Module: WrapIt::Sections::ClassMethods
- Defined in:
- lib/wrap_it/sections.rb
Overview
Class methods to include
Instance Method Summary collapse
Instance Method Details
#place(src, at, dst = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wrap_it/sections.rb', line 62 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 ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/wrap_it/sections.rb', line 52 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(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wrap_it/sections.rb', line 40 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 ⇒ Object
36 37 38 |
# File 'lib/wrap_it/sections.rb', line 36 def sections collect_derived(:@sections) end |