Module: CMS::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/cms/configuration.rb

Instance Method Summary collapse

Instance Method Details

#attributes(attributes, type) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/cms/configuration.rb', line 35

def attributes attributes, type
  attributes.map do |args|
    options = args.extract_options!
    name = args.shift
    format = args.pop || options.delete('format')
    attribute = CMS::Attribute.new(name, format, options)
    attribute.reference_to.references << type if attribute.reference?
    attribute
  end
end

#dataObject



4
5
6
7
8
9
10
# File 'lib/cms/configuration.rb', line 4

def data
  @data ||= if yaml_string_data.present?
    YAML.load(yaml_string_data).reverse_merge(default_empty_data)
  else
    default_empty_data
  end
end

#pagesObject



46
47
48
49
50
# File 'lib/cms/configuration.rb', line 46

def pages
  data['pages'].map do |route, page_config|
    CMS::Page.new route.dup, HashWithIndifferentAccess.new(page_config)
  end
end

#scoped_types(options) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/cms/configuration.rb', line 12

def scoped_types options
  if options[:only]
    [types.find{|t| options[:only] == t.name}]
  else
    types.reject{|t| options[:except].include?(t.name)}
  end
end

#typesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cms/configuration.rb', line 20

def types
  if defined?(@types) then return @types end

  # raise data['content_types'].inspect
  @types = data['content_types'].map do |name, config|
    CMS::Type.new(name, config.delete('attributes'), config)
  end

  @types.each do |type|
    type.attributes = attributes(type.attributes, type)
  end

  @types
end