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_asset_url, #add_binding, #add_component, #add_content_binding, #add_each, #add_else, #add_if, #add_template, #add_textarea, #add_yield, #last_method_name, #parent_fetcher, #save_binding

Methods included from AttributeScope

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

Constructor Details

#initialize(handler, path, content, with_index) ⇒ EachScope

Returns a new instance of EachScope.



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

def initialize(handler, path, content, with_index)
  super(handler, path)

  if with_index
    @content, @variable_name = content.split(/.each_with_index\s+do\s+\|/)
    @variable_name, @index_name = @variable_name.gsub(/\|/, '').split(/\s*,\s*/)
  else
    @content, @variable_name = content.split(/.each\s+do\s+\|/)
    @variable_name = @variable_name.gsub(/\|/, '')
  end
end

Instance Method Details

#close_scopeObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/volt/server/html_parser/each_scope.rb', line 15

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.try(:strip).inspect}, #{@index_name.try(:strip).inspect}, #{@path.inspect}) }")
end