Sha256: b15a9c2646bd9407527e07ebfe2b6b300d126299992d62335b8275420322b3e7

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module Volt
  # 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.
  class StringTemplateRenderer
    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

      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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
volt-0.9.3.pre1 lib/volt/page/string_template_renderer.rb
volt-0.9.2 lib/volt/page/string_template_renderer.rb
volt-0.9.1 lib/volt/page/string_template_renderer.rb
volt-0.9.1.pre5 lib/volt/page/string_template_renderer.rb
volt-0.9.1.pre4 lib/volt/page/string_template_renderer.rb
volt-0.9.1.pre3 lib/volt/page/string_template_renderer.rb
volt-0.9.1.pre2 lib/volt/page/string_template_renderer.rb