Class: Volt::StringTemplateRenderer
- Defined in:
- lib/volt/page/string_template_renderer.rb
Overview
StringTemplateRenderer are used to render a template to a string. Call .html to get the string. Be sure to call .remove when complete.
StringTemplateRenderer will intellegently update the string in the same way a normal bindings will update the dom.
Instance Method Summary collapse
- #changed! ⇒ Object
-
#html ⇒ Object
Render the template and get the current value.
-
#initialize(volt_app, context, template_path) ⇒ StringTemplateRenderer
constructor
A new instance of StringTemplateRenderer.
- #remove ⇒ Object
Constructor Details
#initialize(volt_app, context, template_path) ⇒ StringTemplateRenderer
Returns a new instance of StringTemplateRenderer.
8 9 10 11 12 13 14 |
# File 'lib/volt/page/string_template_renderer.rb', line 8 def initialize(volt_app, context, template_path) @dependency = Dependency.new @template_path = template_path @target = AttributeTarget.new(nil, nil, self) @template = TemplateRenderer.new(volt_app, @target, context, 'main', template_path) end |
Instance Method Details
#changed! ⇒ Object
28 29 30 31 |
# File 'lib/volt/page/string_template_renderer.rb', line 28 def changed! # if @dependency is missing, this template has been removed @dependency.changed! if @dependency end |
#html ⇒ Object
Render the template and get the current value
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/volt/page/string_template_renderer.rb', line 17 def html @dependency.depend html = nil Computation.run_without_tracking do html = @target.to_html end html end |
#remove ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/volt/page/string_template_renderer.rb', line 33 def remove @dependency.remove @dependency = nil Computation.run_without_tracking do @template.remove @template = nil end @target = nil @template_path = nil end |