Class: Volt::ComponentViewScope
- Defined in:
- lib/volt/server/html_parser/component_view_scope.rb
Instance Attribute Summary
Attributes inherited from ViewScope
#binding_number, #bindings, #html, #path
Instance Method Summary collapse
- #close_scope ⇒ Object
-
#initialize(handler, path, tag_name, attributes, unary) ⇒ ComponentViewScope
constructor
The path passed in is the path used to lookup view’s.
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, tag_name, attributes, unary) ⇒ ComponentViewScope
The path passed in is the path used to lookup view’s. The path from the tag is passed in as tag_name
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/volt/server/html_parser/component_view_scope.rb', line 5 def initialize(handler, path, tag_name, attributes, unary) super(handler, path) @binding_in_path = path component_name = tag_name[1..-1].tr('-', '_').tr(':', '/') data_hash = [] attributes.each_pair do |name, value| name = name.tr('-', '_') if name[0..1] == 'e_' # Event binding value = ViewScope.methodize_string(value.strip) data_hash << "#{name.inspect} => Proc.new {|event| #{value} }" else parts, binding_count = binding_parts_and_count(value) # if this attribute has bindings if binding_count > 0 if binding_count > 1 # Multiple bindings elsif parts.size == 1 && binding_count == 1 # A single binding getter = value[2...-2].strip data_hash << "#{name.inspect} => Proc.new { #{getter} }" setter = getter_to_setter(getter) data_hash << "#{(name + '=').inspect} => Proc.new { |val| #{setter} }" # Add an _parent fetcher. Useful for things like volt-fields to get the parent model. parent = parent_fetcher(getter) # TODO: This adds some overhead, perhaps there is a way to compute this dynamically on the # front-end. data_hash << "#{(name + '_parent').inspect} => Proc.new { #{parent} }" # Add a _last_method property. This is useful data_hash << "#{(name + '_last_method').inspect} => #{last_method_name(getter).inspect}" end else # String data_hash << "#{name.inspect} => #{value.inspect}" end end end @arguments = "#{component_name.inspect}, { #{data_hash.join(',')} }" end |
Instance Method Details
#close_scope ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/volt/server/html_parser/component_view_scope.rb', line 56 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::ComponentBinding.new(__p, __t, __c, __id, #{@binding_in_path.inspect}, Proc.new { [#{@arguments}] }, #{@path.inspect}) }") end |