Class: WrapIt::Container
Overview
Describes elements that can contain other elements
TODO: single_child
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#extract_children ⇒ Object
writeonly
Sets the attribute extract_children.
Attributes inherited from Base
Class Method Summary collapse
-
.child(name, *args, &block) ⇒ String
Defines child elements helper for creation of child items.
- .extract_from_options(*args) ⇒ Object
Instance Method Summary collapse
Methods inherited from Base
#initialize, #omit_content?, #render, #unwrap, #wrap
Methods included from Renderer
Methods included from Enums
Methods included from DerivedAttributes
Methods included from Switches
Methods included from HTMLData
included, #remove_html_data, #set_html_data
Methods included from HTMLClass
#add_html_class, #html_class, #html_class=, #html_class?, #html_class_prefix, included, #no_html_class?, #remove_html_class, sanitize
Methods included from Sections
Methods included from Callbacks
Constructor Details
This class inherits a constructor from WrapIt::Base
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
18 19 20 |
# File 'lib/wrap_it/container.rb', line 18 def children @children end |
#extract_children=(value) ⇒ Object (writeonly)
Sets the attribute extract_children
19 20 21 |
# File 'lib/wrap_it/container.rb', line 19 def extract_children=(value) @extract_children = value end |
Class Method Details
.child(name, *args, &block) ⇒ String
Defines child elements helper for creation of child items.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wrap_it/container.rb', line 41 def self.child(name, *args, &block) name.is_a?(String) && name.to_sym name.is_a?(Symbol) || fail(ArgumentError, 'Wrong child name') child_class = if args.first.is_a?(String) || args.first.is_a?(Class) args.shift else 'WrapIt::Base' end child_class = child_class.name if child_class.is_a?(Class) @helpers ||= [] @helpers << name define_method name do |*helper_args, &helper_block| # We should clone arguments becouse if we have loop in template, # `extract_options!` below works only for first iterration default_args = args.clone = helper_args. [:helper_name] = name .merge!(default_args.) helper_args += default_args + [] add_children(name, child_class, block, *helper_args, &helper_block) end end |
.extract_from_options(*args) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/wrap_it/container.rb', line 65 def self.(*args) return || [] if args.size == 0 hash = args. args.size.odd? && fail(ArgumentError, 'odd arguments number') args.each_with_index { |arg, i| i.even? && hash[arg] = args[i + 1] } @helpers ||= [] hash.symbolize_keys! = Hash[ hash.select do |k, v| (v.is_a?(String) || v.is_a?(Symbol)) && @helpers.include?(k) end.map { |k, v| [k, v.to_sym] } ] end |
Instance Method Details
#extract_children? ⇒ Boolean
22 23 24 |
# File 'lib/wrap_it/container.rb', line 22 def extract_children? @extract_children == true end |