Sha256: f708b81c9078f286668c79c4b2c1f81c44831f0dc0938b0ce7e0aad6c885b40e

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

module CMS::Configuration
  extend self

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

  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

  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

  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

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

  private

  def default_empty_data
    {
      'content_types' => [],
      'pages' => []
    }
  end

  def _load_yaml_string_data
    File.read(Rails.root.join 'config/cms.yml')
  rescue Errno::ENOENT
    nil
  end

  def _memoize_yaml_string_data
    return @_memoize_yaml_string_data if defined?(@_memoize_yaml_string_data)
    @_memoize_yaml_string_data = _load_yaml_string_data
  end

  alias yaml_string_data _memoize_yaml_string_data
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
honey-cms-0.4.8 lib/cms/configuration.rb
honey-cms-0.4.7 lib/cms/configuration.rb
honey-cms-0.4.6 lib/cms/configuration.rb
honey-cms-0.4.5 lib/cms/configuration.rb
honey-cms-0.4.2 lib/cms/configuration.rb
honey-cms-0.4.1 lib/cms/configuration.rb
honey-cms-0.4.0 lib/cms/configuration.rb
honey-cms-0.3.13 lib/cms/configuration.rb
honey-cms-0.3.12 lib/cms/configuration.rb
honey-cms-0.3.11 lib/cms/configuration.rb
honey-cms-0.3.10 lib/cms/configuration.rb
honey-cms-0.3.9 lib/cms/configuration.rb