Sha256: fe78d8fffd4a205d6232779e2a0a511b9a8af918cafc278fe90ad134acaa7573

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'active_support/core_ext'
require 'set'

require 'dragonfly'
require 'mime-types'

module DynamicContent
  autoload :VERSION, 'dynamic_content/version'
  autoload :TagSerializer, 'dynamic_content/tag_serializer'
  autoload :Models, 'dynamic_content/models'
  autoload :Processor, 'dynamic_content/processor'

  class << self
    # Structure file path
    attr_accessor :structure_path

    # Locale
    attr_accessor :locale
  end

  def self.locale
    @locale || :en
  end

  def self.structure_path
    @structure_path || 'db/seeds/dynamic_content.yml'
  end

  def self.structure_file
    if File.exists? Rails.root.join(self.structure_path)
      return YAML.load(File.read(Rails.root.join(self.structure_path)))
    else
      raise NoStructureFileError, "File #{self.structure_path} is not found."
    end
  end

  def self.setup(&block)
    yield self
  end

  def self.process
    Processor.new
  end

  def self.settings
    {
      locale: self.locale,
      structure_path: self.structure_path
    }
  end

end

ActionController::Base.class_eval do
  private
  def load_dynamic_content finder_key = nil
    unless dc_is_admin?
      finder_key ||= controller_name

      @application = DynamicContent::Page.cached_for('application')
      @page = DynamicContent::Page.cached_for(finder_key)
      @dynamic_content = @application.merge(@page)
    end
  end

  def dc_is_admin?
    params[:controller] =~ /admin/ || params[:controller] =~ /redactor/
  end
end

# Require things that don't support autoload
require 'dynamic_content/engine'
require 'dynamic_content/error'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dynamic_content-1.0.0 lib/dynamic_content.rb