Sha256: 5229a0cd760df273f2f7c685ecfd23aa343d88e8e1f7d2f49f4babfdd40694dc

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

require 'volt/server/html_parser/sandlebars_parser'
require 'volt/server/html_parser/view_scope'
require 'volt/server/html_parser/if_view_scope'
require 'volt/server/html_parser/component_view_scope'
require 'volt/server/html_parser/view_handler'
require 'volt/server/html_parser/each_scope'
require 'volt/server/html_parser/textarea_scope'

module Volt
  class ViewParser
    attr_reader :templates

    def initialize(html, template_path)
      @template_path = template_path

      handler = ViewHandler.new(template_path)

      SandlebarsParser.new(html, handler)

      # Close out the last scope
      last_scope = handler.scope.last

      fail "Unclosed tag in:\n#{html}" unless last_scope

      last_scope.close_scope

      @templates = handler.templates
    end

    # Returns a parsed version of the data (useful for backend rendering
    # and testing)
    def data
      templates = @templates.deep_clone

      templates.each_pair do |name, value|
        if value['bindings']
          value['bindings'].each_pair do |number, binding|
            value['bindings'][number] = binding.map { |code| eval(code) }
          end
        end
      end

      templates
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
volt-0.9.5.pre1 lib/volt/server/html_parser/view_parser.rb
volt-0.9.4 lib/volt/server/html_parser/view_parser.rb
volt-0.9.4.pre5 lib/volt/server/html_parser/view_parser.rb
volt-0.9.4.pre3 lib/volt/server/html_parser/view_parser.rb
volt-0.9.4.pre2 lib/volt/server/html_parser/view_parser.rb
volt-0.9.4.pre1 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3.pre6 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3.pre5 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3.pre4 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3.pre3 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3.pre2 lib/volt/server/html_parser/view_parser.rb
volt-0.9.3.pre1 lib/volt/server/html_parser/view_parser.rb
volt-0.9.2 lib/volt/server/html_parser/view_parser.rb