Class: Volt::ViewParser
- Defined in:
- lib/volt/server/html_parser/view_parser.rb
Instance Attribute Summary collapse
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#data ⇒ Object
Returns a parsed version of the data (useful for backend rendering and testing).
-
#initialize(html, template_path) ⇒ ViewParser
constructor
A new instance of ViewParser.
Constructor Details
#initialize(html, template_path) ⇒ ViewParser
Returns a new instance of ViewParser.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/volt/server/html_parser/view_parser.rb', line 13 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 |
Instance Attribute Details
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
11 12 13 |
# File 'lib/volt/server/html_parser/view_parser.rb', line 11 def templates @templates end |
Instance Method Details
#data ⇒ Object
Returns a parsed version of the data (useful for backend rendering and testing)
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/volt/server/html_parser/view_parser.rb', line 32 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 |