Class: Rich::Cms::Content::Group
- Inherits:
-
Struct
- Object
- Struct
- Rich::Cms::Content::Group
- Defined in:
- lib/rich/cms/content/group.rb
Instance Attribute Summary collapse
-
#add ⇒ Object
Returns the value of attribute add.
-
#after_update ⇒ Object
Returns the value of attribute after_update.
-
#before_edit ⇒ Object
Returns the value of attribute before_edit.
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#key ⇒ Object
Returns the value of attribute key.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(ref, as_content_item = true) ⇒ Object
- #identifiers ⇒ Object
- #keys ⇒ Object
- #to_javascript_hash ⇒ Object
Instance Attribute Details
#add ⇒ Object
Returns the value of attribute add
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def add @add end |
#after_update ⇒ Object
Returns the value of attribute after_update
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def after_update @after_update end |
#before_edit ⇒ Object
Returns the value of attribute before_edit
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def before_edit @before_edit end |
#class_name ⇒ Object
Returns the value of attribute class_name
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def class_name @class_name end |
#key ⇒ Object
Returns the value of attribute key
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def key @key end |
#selector ⇒ Object
Returns the value of attribute selector
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def selector @selector end |
#tag ⇒ Object
Returns the value of attribute tag
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def tag @tag end |
#value ⇒ Object
Returns the value of attribute value
6 7 8 |
# File 'lib/rich/cms/content/group.rb', line 6 def value @value end |
Class Method Details
.build(selector, specs) ⇒ Object
8 9 10 |
# File 'lib/rich/cms/content/group.rb', line 8 def self.build(selector, specs) self.new *{:selector => selector, :key => :key, :value => :value}.merge(specs).stringify_keys.values_at(*self.members) end |
Instance Method Details
#fetch(ref, as_content_item = true) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rich/cms/content/group.rb', line 12 def fetch(ref, as_content_item = true) reference = if ref.is_a?(Hash) ref elsif identifiers.size == 1 {identifiers.first => ref} end reference.stringify_keys! if reference.is_a?(Hash) unless valid_reference?(reference) raise ArgumentError, "Invalid reference #{reference.inspect} (#{reference.values_at(*identifiers).inspect}) passed for #{identifiers.inspect}" end object = self.class_name.constantize.send :"find_or_initialize_by_#{identifiers.join "_and_"}", *reference.values_at(*identifiers) as_content_item ? Cms::Content::Item.new(self, object) : object end |
#identifiers ⇒ Object
33 34 35 |
# File 'lib/rich/cms/content/group.rb', line 33 def identifiers @identifiers ||= [self.key].flatten.collect(&:to_s).sort end |
#keys ⇒ Object
29 30 31 |
# File 'lib/rich/cms/content/group.rb', line 29 def keys (identifiers + [self.add || []].flatten.collect(&:to_s)).sort end |
#to_javascript_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rich/cms/content/group.rb', line 37 def to_javascript_hash "#{self.selector.inspect}: {#{ members.collect do |k| if v = self[k] case k when "key" "keys: [#{ [v].flatten.collect do |key| "data-#{key}".inspect end.join ", " }]" when "value" "#{k}: #{"data-#{v}".inspect}" when "before_edit", "after_update" "#{k.camelize :lower}: #{v}" end end end.compact.join(", ") }}" end |