Sha256: f68fb633636ff5cfcbde46e1b9f130aba85578d16d6bdcd50e951796f1994fcd

Contents?: true

Size: 1.17 KB

Versions: 6

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

      raise "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

6 entries across 6 versions & 1 rubygems

Version Path
volt-0.9.1 lib/volt/server/html_parser/view_parser.rb
volt-0.9.1.pre5 lib/volt/server/html_parser/view_parser.rb
volt-0.9.1.pre4 lib/volt/server/html_parser/view_parser.rb
volt-0.9.1.pre3 lib/volt/server/html_parser/view_parser.rb
volt-0.9.1.pre2 lib/volt/server/html_parser/view_parser.rb
volt-0.9.1.pre1 lib/volt/server/html_parser/view_parser.rb