Class: TemplateParser
Instance Attribute Summary collapse
-
#bindings ⇒ Object
Returns the value of attribute bindings.
-
#dom ⇒ Object
Returns the value of attribute dom.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
- #add_template(name, template) ⇒ Object
-
#initialize(template, template_path) ⇒ TemplateParser
constructor
A new instance of TemplateParser.
-
#templates ⇒ Object
Return the templates, but map the html from nokogiri to html.
Constructor Details
#initialize(template, template_path) ⇒ TemplateParser
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/volt/server/template_parser.rb', line 406 def initialize(template, template_path) @templates = {} @template_path = template_path template_fragment = Nokogiri::HTML::DocumentFragment.parse(template) # Add templates for each section # Check for sections sections = [] if template_fragment.children[0].name[0] == ':' template_fragment.children.each do |child| if child.is_a?(Nokogiri::XML::Element) sections << [child, child.name[1..-1]] end end else sections << [template_fragment, 'body'] end sections.each do |section, name| template = Template.new(self, name, section) add_template(name, template) template.start_walk template.pull_closed_block_scopes end end |
Instance Attribute Details
#bindings ⇒ Object
Returns the value of attribute bindings.
404 405 406 |
# File 'lib/volt/server/template_parser.rb', line 404 def bindings @bindings end |
#dom ⇒ Object
Returns the value of attribute dom.
404 405 406 |
# File 'lib/volt/server/template_parser.rb', line 404 def dom @dom end |
#template_path ⇒ Object
Returns the value of attribute template_path.
404 405 406 |
# File 'lib/volt/server/template_parser.rb', line 404 def template_path @template_path end |
Instance Method Details
#add_template(name, template) ⇒ Object
435 436 437 438 |
# File 'lib/volt/server/template_parser.rb', line 435 def add_template(name, template) raise "Already defined at #{@template_path + '/' + name}" if @templates[@template_path + '/' + name] @templates[@template_path + '/' + name] = template end |
#templates ⇒ Object
Return the templates, but map the html from nokogiri to html
441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/volt/server/template_parser.rb', line 441 def templates mapped = {} @templates.each_pair do |name, template| mapped[name] = { 'html' => template.html, 'bindings' => template.current_scope.bindings } end return mapped end |