Module: WrapIt::Sections
Overview
Sections is a smart way to make complex components with inheritance.
Sections is just array of named HTML markup pieces. You can place any section before or after another at class level and change their content at instance level.
Each component have three stages. First is initialization, then sections capturing and rendering. You can change any sections content until rendering stage begins. Finally, renderer joins all sections in order, that they have at render time.
Base provides following sections: main section is :content.
All text from block captured there. :render_arguments and :render_block
also provided, so arguments and block passed to render method captured
here.
Access to sections at instance level performed throw hash-like getter and setter ([] and []=) of self.
With this functionality you can easy organize you inheritance, so any descendant can change sections order or any section content without changes to unrelated sections.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.place(src, at, dst = nil) ⇒ void
extended
from ClassMethods
Places specific section in specified place.
-
.placement ⇒ Array<Symbol>
extended
from ClassMethods
Retrieves section names in current order.
-
#section([name, ...]) ⇒ void
extended
from ClassMethods
Defines new section or sections.
-
.sections ⇒ Array<Symbol>
extended
from ClassMethods
Retrieves all sections, including ancestors.
Instance Method Summary collapse
-
#[](name) ⇒ String
Retrieves specified section content.
-
#[]=(name, value) ⇒ String
Sets specified section content.
Class Method Details
#place(src, to) ⇒ void #place(src, at, dst) ⇒ void Originally defined in module ClassMethods
This method returns an undefined value.
Places specific section in specified place
.placement ⇒ Array<Symbol> Originally defined in module ClassMethods
Retrieves section names in current order
#section([name, ...]) ⇒ void Originally defined in module ClassMethods
This method returns an undefined value.
Defines new section or sections. Places its to end of section list
.sections ⇒ Array<Symbol> Originally defined in module ClassMethods
Retrieves all sections, including ancestors
Instance Method Details
#[](name) ⇒ String
Retrieves specified section content
71 72 73 74 75 76 |
# File 'lib/wrap_it/sections.rb', line 71 def [](name) @section_names ||= self.class.sections return nil unless @section_names.include?(name) @sections ||= {} @sections[name] ||= empty_html end |
#[]=(name, value) ⇒ String
Sets specified section content
84 85 86 87 88 89 |
# File 'lib/wrap_it/sections.rb', line 84 def []=(name, value) @section_names ||= self.class.sections return unless @section_names.include?(name) @sections ||= {} @sections[name] = value end |