Class: Skyline::Content::MetaData::FieldGroup

Inherits:
Array
  • Object
show all
Defined in:
lib/skyline/content/meta_data/field_group.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  super([])
  
  self.name = options[:name]
  self.title = options[:title]
  self.owner = options[:owner]
  
  self.field(options[:field]) if options[:fields] && options[:fields].any?    
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/skyline/content/meta_data/field_group.rb', line 4

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



4
5
6
# File 'lib/skyline/content/meta_data/field_group.rb', line 4

def owner
  @owner
end

#titleObject

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_hashObject



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_namesObject



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

#inspectObject



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_titleObject



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_titleObject



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