Class: WrapIt::Container
Overview
TODO:
single_child realization
TODO:
refactor code for more clearness
Describes elements that can contain other elements
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
list of children elements.
-
#extract_children ⇒ Object
writeonly
children can be extracted from normal template flow and rendered in separate section.
Class Method Summary collapse
-
.child(name, class_name = nil, [args, ...], opts = {}, &block) ⇒ String
Defines helper for child elements creation.
Instance Method Summary collapse
Constructor Details
This class inherits a constructor from WrapIt::Base
Instance Attribute Details
#children ⇒ Object (readonly)
list of children elements
20 21 22 |
# File 'lib/wrap_it/container.rb', line 20 def children @children end |
#extract_children=(value) ⇒ Object (writeonly)
children can be extracted from normal template flow and rendered in separate section.
24 25 26 |
# File 'lib/wrap_it/container.rb', line 24 def extract_children=(value) @extract_children = value end |
Class Method Details
.child(name, class_name = nil, [args, ...], opts = {}, &block) ⇒ String
Defines helper for child elements creation.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wrap_it/container.rb', line 79 def self.child(name, *args, option: nil, **opts, &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) define_method name do |*hargs, extracted: false, **hopts, &hblock| hargs += args # TODO: merge html class correctly. Now it just overrided by opts hopts.merge!(opts) hopts[:helper_name] = name child = prepare_child(child_class, block, *hargs, **hopts, &hblock) add_children(name, child, extracted: extracted) end add_child_option(name, option) end |
Instance Method Details
#extract_children? ⇒ Boolean
28 29 30 |
# File 'lib/wrap_it/container.rb', line 28 def extract_children? @extract_children == true end |