Class: Skyline::Content::MetaData::FieldPage

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, options = {}) ⇒ FieldPage

Returns a new instance of FieldPage.



7
8
9
10
11
12
13
# File 'lib/skyline/content/meta_data/field_page.rb', line 7

def initialize(owner,name,options={})
  @owner = owner
  @name = name
  @options = options
  @fields = {}
  @ungrouped_fields = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/skyline/content/meta_data/field_page.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/skyline/content/meta_data/field_page.rb', line 5

def options
  @options
end

#ownerObject (readonly)

Returns the value of attribute owner.



5
6
7
# File 'lib/skyline/content/meta_data/field_page.rb', line 5

def owner
  @owner
end

Instance Method Details

#description(v = nil) ⇒ Object



15
16
17
18
# File 'lib/skyline/content/meta_data/field_page.rb', line 15

def description(v=nil)
  @options[:description] = v if v
  @options[:description]
end

#each_field(&block) ⇒ Object



25
26
27
28
29
# File 'lib/skyline/content/meta_data/field_page.rb', line 25

def each_field(&block)
  self.ungrouped_fields.each do |field_name|
    yield_field(field_name,&block)
  end
end

#field(*fields, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/skyline/content/meta_data/field_page.rb', line 35

def field(*fields,&block)
  options = fields.last.kind_of?(Hash) ? fields.pop : {}
  fields = fields.first if fields.any? && fields.first.kind_of?(Array)
  
  fields.map do |name|
    @fields[name] = Field.new(options.update(:name => name, :owner => self))
    yield @fields[name] if block_given?
    @ungrouped_fields << name
    @fields[name]
  end
end

#field_group(name, options = {}) {|field_group| ... } ⇒ Object

Yields:



47
48
49
50
51
52
# File 'lib/skyline/content/meta_data/field_page.rb', line 47

def field_group(name,options={})
  field_group = FieldGroup.new(options.update(:owner => self, :name => name))
  yield field_group if block_given?
  @fields[name] = field_group
  @ungrouped_fields << name
end

#field_namesObject



70
71
72
# File 'lib/skyline/content/meta_data/field_page.rb', line 70

def field_names
  @fields.keys
end

#field_order(*order) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/skyline/content/meta_data/field_page.rb', line 58

def field_order(*order)
  if order.empty?
    @ungrouped_fields
  else
  
  end
end

#fieldsObject



54
55
56
# File 'lib/skyline/content/meta_data/field_page.rb', line 54

def fields
  @fields
end

#human_nameObject



74
75
76
# File 'lib/skyline/content/meta_data/field_page.rb', line 74

def human_name
  self.title.present? ? self.title : self.name.to_s.humanize
end

#title(v = nil) ⇒ Object



20
21
22
23
# File 'lib/skyline/content/meta_data/field_page.rb', line 20

def title(v=nil)
  @options[:title] = v if v
  @options[:title]
end

#ungrouped_fieldsObject



66
67
68
# File 'lib/skyline/content/meta_data/field_page.rb', line 66

def ungrouped_fields
  @ungrouped_fields
end

#yield_field(field_name) {|| ... } ⇒ Object

Yields:

  • ()


31
32
33
# File 'lib/skyline/content/meta_data/field_page.rb', line 31

def yield_field(field_name,&block)
  yield self.fields[field_name]
end