Class: Props::Fragment
- Inherits:
-
Object
- Object
- Props::Fragment
- Defined in:
- lib/props_template/extensions/fragment.rb
Instance Attribute Summary collapse
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
Class Method Summary collapse
Instance Method Summary collapse
- #handle(options, item_context = nil) ⇒ Object
-
#initialize(base, fragments = []) ⇒ Fragment
constructor
A new instance of Fragment.
Constructor Details
#initialize(base, fragments = []) ⇒ Fragment
Returns a new instance of Fragment.
5 6 7 8 |
# File 'lib/props_template/extensions/fragment.rb', line 5 def initialize(base, fragments = []) @base = base @fragments = fragments end |
Instance Attribute Details
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
3 4 5 |
# File 'lib/props_template/extensions/fragment.rb', line 3 def fragments @fragments end |
Class Method Details
.fragment_name_from_options(options, item = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/props_template/extensions/fragment.rb', line 10 def self.(, item = nil) return if ![:partial] _, partial_opts = [*[:partial]] return unless partial_opts fragment = partial_opts[:fragment] if item && ::Proc === fragment fragment = fragment.call(item) end if String === fragment || Symbol === fragment fragment.to_s end end |
Instance Method Details
#handle(options, item_context = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/props_template/extensions/fragment.rb', line 27 def handle(, item_context = nil) fragment_name = self.class.(, item_context) path = @base.traveled_path .map { |item| item.is_a?(Array) ? item[0] : item } .join(".") if fragment_name @fragments.push( {id: fragment_name, path: path} ) end end |