Module: WrapIt::Sections::ClassMethods
- Included in:
- Base, WrapIt::Sections
- Defined in:
- lib/wrap_it/sections.rb
Overview
WrapIt::Sections class methods
Instance Method Summary collapse
-
#place(src, at, dst = nil) ⇒ void
Places specific section in specified place.
-
#placement ⇒ Array<Symbol>
Retrieves section names in current order.
-
#section([name, ...]) ⇒ void
Defines new section or sections.
-
#sections ⇒ Array<Symbol>
Retrieves all sections, including ancestors.
Instance Method Details
#place(src, to) ⇒ void #place(src, at, dst) ⇒ void
This method returns an undefined value.
Places specific section in specified place
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/wrap_it/sections.rb', line 150 def place(src, at, dst = nil) if dst == nil && at.is_a?(Hash) && at.keys.size == 1 dst = at.values[0] at = at.keys[0] end return unless placement.include?(src) && (dst == :begin || dst == :end || placement.include?(dst)) && (at == :before || at == :after) item = placement.delete_at(placement.index(src)) case dst when :begin then placement.unshift(item) when :end then placement.push(item) else x = at == :before ? 0 : 1 placement.insert(placement.index(dst) + x, item) end end |
#placement ⇒ Array<Symbol>
Retrieves section names in current order
126 127 128 129 130 131 132 133 134 |
# File 'lib/wrap_it/sections.rb', line 126 def placement @placement ||= if self == Base sections.clone else parent = ancestors[1..-1].find { |a| a.respond_to?(:placement) } parent.nil? ? sections.clone : parent.placement.clone end end |
#section([name, ...]) ⇒ void
This method returns an undefined value.
Defines new section or sections. Places its to end of section list
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/wrap_it/sections.rb', line 110 def section(*args) @sections ||= [] args.flatten.each do |name| name.is_a?(String) && name = name.to_sym next unless name.is_a?(Symbol) next if (sections + [:begin, :end]).include?(name) @sections << name placement << name unless placement.include?(name) place name, before: :end end end |
#sections ⇒ Array<Symbol>
Retrieves all sections, including ancestors
99 100 101 |
# File 'lib/wrap_it/sections.rb', line 99 def sections collect_derived(:@sections) end |