Class: Skyline::Content::MetaData::FieldGroup
- Inherits:
-
Array
- Object
- Array
- Skyline::Content::MetaData::FieldGroup
- Defined in:
- lib/skyline/content/meta_data/field_group.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #columns_hash ⇒ Object
- #each_field(&block) ⇒ Object
- #field(*fields, &block) ⇒ Object
- #field_names ⇒ Object
-
#hidden_in(scope) ⇒ Object
You can’t hide groups.
-
#initialize(options) ⇒ FieldGroup
constructor
A new instance of FieldGroup.
- #inspect ⇒ Object
- #only_each_field_of(selection, &block) ⇒ Object
- #plural_title ⇒ Object
- #singular_title ⇒ Object
Constructor Details
#initialize(options) ⇒ FieldGroup
Returns a new instance of FieldGroup.
6 7 8 9 10 11 12 13 14 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 6 def initialize() super([]) self.name = [:name] self.title = [:title] self.owner = [:owner] self.field([:field]) if [:fields] && [:fields].any? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 4 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
4 5 6 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 4 def owner @owner end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 4 def title @title end |
Instance Method Details
#columns_hash ⇒ Object
67 68 69 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 67 def columns_hash self.owner.columns_hash end |
#each_field(&block) ⇒ Object
47 48 49 50 51 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 47 def each_field(&block) self.each do |field_name| yield_field(field_name, &block) end end |
#field(*fields, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 30 def field(*fields,&block) created_fields = self.owner.field(*fields,&block) self.concat(created_fields.map(&:name)) # Remove newly grouped fields from the ungrouped list as well as the existing order current_order = self.owner.field_order.dup fields.each do |field_name| next unless field_name.kind_of?(Symbol) self.owner.ungrouped_fields.delete(field_name) current_order.delete(field_name) end self.owner.field_order(*current_order) created_fields end |
#field_names ⇒ Object
63 64 65 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 63 def field_names self.to_a end |
#hidden_in(scope) ⇒ Object
You can’t hide groups
72 73 74 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 72 def hidden_in(scope) false end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 26 def inspect "#<FieldGroup fields=#{super}>" end |
#only_each_field_of(selection, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 53 def only_each_field_of(selection,&block) selection.each do |field_name| if self.include?(field_name) yield_field(field_name,&block) else yield nil end end end |
#plural_title ⇒ Object
21 22 23 24 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 21 def plural_title return self.name.to_s.humanize.pluralize if self.title.blank? self.title.kind_of?(Array) && self.title.last || self.title.to_s.pluralize end |
#singular_title ⇒ Object
16 17 18 19 |
# File 'lib/skyline/content/meta_data/field_group.rb', line 16 def singular_title return self.name.to_s.humanize if self.title.blank? self.title.kind_of?(Array) && self.title.first || self.title.to_s end |