Sha256: 5ac4a1e839dda25253c8c36c6f236430aa40d052c896611d05049c020ccf21c3

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 KB

Contents

# StringTemplateRender are used to render a template to a string.  Call .html
# to get the string.  Be sure to call .remove when complete.
#
# StringTemplateRender will intellegently update the string in the same way
# a normal bindings will update the dom.

class StringTemplateRender
  def initialize(page, context, template_path)
    @dependency = Dependency.new

    @template_path = template_path
    @target = AttributeTarget.new(nil, nil, self)
    @template = TemplateRenderer.new(page, @target, context, "main", template_path)
  end

  # Render the template and get the current value
  def html
    @dependency.depend

    html = nil
    Computation.run_without_tracking do
      html = @target.to_html
    end

    return html
  end

  def changed!
    # if @dependency is missing, this template has been removed
    @dependency.changed! if @dependency
  end

  def remove
    @dependency.remove
    @dependency = nil

    Computation.run_without_tracking do
      @template.remove
      @template = nil
    end

    @target = nil
    @template_path = nil
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/page/string_template_renderer.rb
volt-0.8.13 lib/volt/page/string_template_renderer.rb
volt-0.8.11 lib/volt/page/string_template_renderer.rb
volt-0.8.10 lib/volt/page/string_template_renderer.rb
volt-0.8.9 lib/volt/page/string_template_renderer.rb
volt-0.8.8 lib/volt/page/string_template_renderer.rb
volt-0.8.7 lib/volt/page/string_template_renderer.rb
volt-0.8.6 lib/volt/page/string_template_renderer.rb
volt-0.8.5 lib/volt/page/string_template_renderer.rb
volt-0.8.4 lib/volt/page/string_template_renderer.rb
volt-0.8.3 lib/volt/page/string_template_renderer.rb
volt-0.8.2 lib/volt/page/string_template_renderer.rb
volt-0.8.1 lib/volt/page/string_template_renderer.rb
volt-0.8.0 lib/volt/page/string_template_renderer.rb