Class: ManageableContent::Manager
- Inherits:
-
Object
- Object
- ManageableContent::Manager
- Defined in:
- lib/manageable_content/manager.rb
Class Method Summary collapse
-
.eligible_contents(key) ⇒ Object
Retrieves a list of eligible keys for a given Page key.
-
.eligible_controllers ⇒ Object
Retrieves a list of Controllers eligible for having manageable content.
-
.generate! ⇒ Object
Generates a Page and PageContent for each Controller with manageable content keys, and the layout Page for manageable layout content keys.
-
.page(key, locale = I18n.locale) ⇒ Object
Retrieves a Page relation for the given key and locale.
-
.pages ⇒ Object
Retrieves a Page relation with a filter for eligible Pages.
Class Method Details
.eligible_contents(key) ⇒ Object
Retrieves a list of eligible keys for a given Page key. This can be useful to check if a PageContent is still relevant based on the current configurations.
This will return a list of page keys with it’s corresponding content type (:string or :text).
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/manageable_content/manager.rb', line 61 def self.eligible_contents(key) layout_content_keys = Controllers::Dsl.manageable_layout_content_keys[key] || {} content_keys = begin "#{key.camelize}Controller".constantize.manageable_content_keys rescue NameError [] end layout_content_keys.merge(content_keys) end |
.eligible_controllers ⇒ Object
Retrieves a list of Controllers eligible for having manageable content. A Controller is eligible if it has set contents with :manageable_content_for. This method is cached if Rails.configuration.cache_classes is true.
7 8 9 10 11 12 13 |
# File 'lib/manageable_content/manager.rb', line 7 def self.eligible_controllers if Rails.configuration.cache_classes @@eligible_controllers ||= find_eligible_controllers else find_eligible_controllers end end |
.generate! ⇒ Object
Generates a Page and PageContent for each Controller with manageable content keys, and the layout Page for manageable layout content keys.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/manageable_content/manager.rb', line 17 def self.generate! controllers = eligible_controllers Engine.config.locales.each do |locale| # layout page Controllers::Dsl.manageable_layout_content_keys.each_key do |layout| generate_page! layout, locale, Controllers::Dsl.manageable_layout_content_keys[layout] end # controllers pages controllers.each do |controller_class| generate_page! controller_class.controller_path, locale, controller_class.manageable_content_keys end end controllers end |
.page(key, locale = I18n.locale) ⇒ Object
Retrieves a Page relation for the given key and locale. By default I18n.locale is used as the locale option.
52 53 54 |
# File 'lib/manageable_content/manager.rb', line 52 def self.page(key, locale = I18n.locale) Page.with_contents.where(:key => key, :locale => locale) end |
.pages ⇒ Object
Retrieves a Page relation with a filter for eligible Pages. A Page is eligible if the corresponding controller is still eligible (from the eligible_controllers method).
This method should be used to access a list of valid Pages instead of directly accessing the Page model.
45 46 47 48 |
# File 'lib/manageable_content/manager.rb', line 45 def self.pages Page.where(:key => eligible_controllers.map {|controller_class| controller_class.controller_path }) end |