Class: Heartml::TemplateRenderer

Inherits:
ServerComponent show all
Defined in:
lib/heartml/template_renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerComponent

inherited, source_location

Constructor Details

#initialize(body:, context:) ⇒ TemplateRenderer

rubocop:disable Lint/MissingSuper



22
23
24
25
26
# File 'lib/heartml/template_renderer.rb', line 22

def initialize(body:, context:) # rubocop:disable Lint/MissingSuper
  @doc_html = body.is_a?(String) ? body : body.to_html
  @body = body.is_a?(String) ? Nokolexbor::DocumentFragment.parse(body) : body
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key) ⇒ Object

TODO: delegate instead?



38
39
40
# File 'lib/heartml/template_renderer.rb', line 38

def method_missing(key, *, **)
  context.send(key, *, **)
end

Class Method Details

.heart_moduleObject



18
19
20
# File 'lib/heartml/template_renderer.rb', line 18

def self.heart_module
  "eval"
end

Instance Method Details

#callObject



28
29
30
31
# File 'lib/heartml/template_renderer.rb', line 28

def call
  Fragment.new(@body, self).process
  @body
end

#respond_to_missing?(key) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/heartml/template_renderer.rb', line 33

def respond_to_missing?(key)
  context.respond_to?(key)
end