Module: ManageableContent::Controllers::Dsl::ClassMethods

Defined in:
lib/manageable_content/controllers/dsl.rb

Instance Method Summary collapse

Instance Method Details

#manageable_content_custom_key(&block) ⇒ Object

Defines a custom page key that should be looked at for valid pages for the current controller. This can be useful when dealing with custom pages. Expects a block that should return a page key. E.g.:

manageable_content_page_key do |params|
  params[:page]
end

Raises:

  • (ArgumentError)


85
86
87
88
# File 'lib/manageable_content/controllers/dsl.rb', line 85

def manageable_content_custom_key(&block)
  raise ArgumentError, "Block required" unless block_given?
  self.manageable_content_custom_key_evaluator = block
end

#manageable_content_for(*keys) ⇒ Object

Configures the manageable contents for a Controller. For example, if the Controller will have a ‘body’ and a ‘side’ contents, the following should be set:

manageable_content_for :body, :side

This will also inherit manageable contents from superclasses. For example, if all your Controllers will have a ‘title’ content, you can add the following to ApplicationController, and all Controllers which inherit from it will have it too:

manageable_content_for :title

You can also set a content type for the given keys. By default they are :text content types. Available types are :text for long contents and :string for short contents.

manageable_content_for :title, :type => :string


68
69
70
71
72
73
74
75
# File 'lib/manageable_content/controllers/dsl.rb', line 68

def manageable_content_for(*keys)
  options = keys.last.is_a?(Hash) ? keys.pop : {}
  type    = options[:type] || :text

  if keys.present?
    self.manageable_content_keys = (self.manageable_content_keys.merge(keys_for_type(type, keys)))
  end
end

#manageable_layout_content_for(*keys) ⇒ Object

Configures the manageable contents that will be shared between all Controllers that use a given layout. For example, if all Controllers using the application layout will share a ‘footer_message’ and a ‘footer_copyright’ contents, the following should be set:

manageable_layout_content_for :footer_message, :footer_copyright

By default, this will set contents for a layout named the same as the Controller in which the manageable_layout_content_for method was called. For example, if it was called in the ApplicationController, it will set the layout vars for the ‘application’ layout. If you need to use multiple layouts with ApplicationController, you can specify for which layout are the contents being set with this:

manageable_layout_content_for :footer_message, :footer_copyright, :layout => 'application'

You can also set a content type for the given keys. By default they are :text content types. Available types are :text for long contents and :string for short contents.

manageable_layout_content_for :footer_copyright, :type => :string


40
41
42
43
44
45
46
47
48
49
# File 'lib/manageable_content/controllers/dsl.rb', line 40

def manageable_layout_content_for(*keys)
  options = keys.last.is_a?(Hash) ? keys.pop : {}
  layout  = options[:layout] || self.controller_path
  type    = options[:type]   || :text

  if keys.present?
    Dsl.manageable_layout_content_keys[layout] =
      ((Dsl.manageable_layout_content_keys[layout] || {}).merge(keys_for_type(type, keys)))
  end
end