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.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #handle(options) ⇒ Object
-
#initialize(base, fragments = {}) ⇒ Fragment
constructor
A new instance of Fragment.
Constructor Details
#initialize(base, fragments = {}) ⇒ Fragment
Returns a new instance of Fragment.
8 9 10 11 12 |
# File 'lib/props_template/extensions/fragment.rb', line 8 def initialize(base, fragments={}) @base = base @fragments = fragments @digest = Digest::SHA2.new(256) end |
Instance Attribute Details
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
5 6 7 |
# File 'lib/props_template/extensions/fragment.rb', line 5 def fragments @fragments end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/props_template/extensions/fragment.rb', line 6 def name @name end |
Instance Method Details
#handle(options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/props_template/extensions/fragment.rb', line 14 def handle() return if ![:partial] partial_name, partial_opts = [:partial] fragment = partial_opts[:fragment] if String === fragment || Symbol === fragment fragment_name = fragment.to_s path = @base.traveled_path.join('.') @name = fragment_name @fragments[fragment_name] ||= [] @fragments[fragment_name].push(path) end if fragment == true locals = partial_opts[:locals] identity = {} locals .clone .tap{|h| h.delete(:json)} .each do |key, value| if value.respond_to?(:to_global_id) identity[key] = value.to_global_id.to_s else identity[key] = value end end path = @base.traveled_path.join('.') fragment_name = @digest.hexdigest("#{partial_name}#{identity.to_json}") @name = fragment_name @fragments[fragment_name] ||= [] @fragments[fragment_name].push(path) end end |