Class: Volt::EachScope

Inherits:
ViewScope show all
Defined in:
lib/volt/server/html_parser/each_scope.rb

Instance Attribute Summary

Attributes inherited from ViewScope

#binding_number, #bindings, #html, #path

Instance Method Summary collapse

Methods inherited from ViewScope

#<<, #add_binding, #add_component, #add_content_binding, #add_each, #add_else, #add_if, #add_template, #add_textarea, #last_method_name, #parent_fetcher, #save_binding

Methods included from AttributeScope

#add_id_to_attributes, #add_multiple_attribute, #add_single_attribute, #add_string_template_renderer, #attribute_string, #binding_parts_and_count, #getter_to_setter, #process_attribute, #process_attributes, #process_event_binding

Constructor Details

#initialize(handler, path, content) ⇒ EachScope

Returns a new instance of EachScope.



3
4
5
6
7
8
9
10
# File 'lib/volt/server/html_parser/each_scope.rb', line 3

def initialize(handler, path, content)
  super(handler, path)
  # @content, @variable_name = content.strip.split(/ as /)

  @content, @variable_name = content.split(/.each\s+do\s+\|/)

  @variable_name = @variable_name.gsub(/\|/, '')
end

Instance Method Details

#close_scopeObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/volt/server/html_parser/each_scope.rb', line 12

def close_scope
  binding_number                    = @handler.scope[-2].binding_number
  @handler.scope[-2].binding_number += 1
  @path                             += "/__template/#{binding_number}"

  super

  @handler.html << "<!-- $#{binding_number} --><!-- $/#{binding_number} -->"
  @handler.scope.last.save_binding(binding_number, "lambda { |__p, __t, __c, __id| Volt::EachBinding.new(__p, __t, __c, __id, Proc.new { #{@content} }, #{@variable_name.inspect}, #{@path.inspect}) }")
end