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
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def add @add end |
#after_update ⇒ Object
Returns the value of attribute after_update
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def after_update @after_update end |
#before_edit ⇒ Object
Returns the value of attribute before_edit
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def before_edit @before_edit end |
#class_name ⇒ Object
Returns the value of attribute class_name
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def class_name @class_name end |
#key ⇒ Object
Returns the value of attribute key
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def key @key end |
#selector ⇒ Object
Returns the value of attribute selector
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def selector @selector end |
#tag ⇒ Object
Returns the value of attribute tag
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def tag @tag end |
#value ⇒ Object
Returns the value of attribute value
5 6 7 |
# File 'lib/rich/cms/content/group.rb', line 5 def value @value end |
Class Method Details
.build(selector, specs) ⇒ Object
7 8 9 |
# File 'lib/rich/cms/content/group.rb', line 7 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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rich/cms/content/group.rb', line 11 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
32 33 34 |
# File 'lib/rich/cms/content/group.rb', line 32 def identifiers @identifiers ||= [self.key].flatten.collect(&:to_s).sort end |
#keys ⇒ Object
28 29 30 |
# File 'lib/rich/cms/content/group.rb', line 28 def keys (identifiers + [self.add || []].flatten.collect(&:to_s)).sort end |
#to_javascript_hash ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rich/cms/content/group.rb', line 36 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 |