Module: Locomotive::Concerns::Site::Metafields
- Extended by:
- ActiveSupport::Concern
- Included in:
- Site
- Defined in:
- app/models/locomotive/concerns/site/metafields.rb
Instance Method Summary collapse
- #any_localized_metafield? ⇒ Boolean
- #cast_metafields(namespace) ⇒ Object
- #find_metafield(name) ⇒ Object
- #has_metafields? ⇒ Boolean
Instance Method Details
#any_localized_metafield? ⇒ Boolean
27 28 29 30 31 |
# File 'app/models/locomotive/concerns/site/metafields.rb', line 27 def return false unless self. self..any? { |g| g['fields'].any? { |f| f['localized'] == true } } end |
#cast_metafields(namespace) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/locomotive/concerns/site/metafields.rb', line 44 def (namespace) return nil if namespace.blank? || ! schema = self..find { |s| s['name'] == namespace } values = self.[namespace] return nil if schema.blank? || values.blank? values.map do |name, value| field = schema['fields'].find { |f| f['name'] == name } next unless field [name, (field, value)] end.compact.to_h end |
#find_metafield(name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/locomotive/concerns/site/metafields.rb', line 33 def (name) return nil if name.blank? || ! fields = self..map { |g| g['fields'] }.flatten fields.find do |f| _name = f['name'].downcase.underscore.gsub(' ', '_') _name == name end end |
#has_metafields? ⇒ Boolean
23 24 25 |
# File 'app/models/locomotive/concerns/site/metafields.rb', line 23 def !self..blank? end |