Class: Alchemy::PageDefinition
- Inherits:
-
Object
- Object
- Alchemy::PageDefinition
- Extended by:
- ActiveModel::Translation
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, Hints
- Defined in:
- app/models/alchemy/page_definition.rb
Class Method Summary collapse
-
.add(definition) ⇒ Object
Add additional page definitions to collection.
-
.all ⇒ Object
Returns all page layouts.
-
.get(name) ⇒ Object
Returns one page definition by given name.
-
.layouts_file_path ⇒ Pathname
The absolute
page_layouts.ymlfile path. - .map ⇒ Object (also: collect)
- .reset! ⇒ Object
Instance Method Summary collapse
Methods included from Hints
Class Method Details
.add(definition) ⇒ Object
Add additional page definitions to collection.
Useful for extending the page layouts from an Alchemy module.
Usage Example
Call +Alchemy::PageDefinition.add(your_definition)+ in your engine.rb file.
62 63 64 65 |
# File 'app/models/alchemy/page_definition.rb', line 62 def add(definition) all @definitions += Array.wrap(definition).map { new(**_1) } end |
.all ⇒ Object
Returns all page layouts.
They are defined in config/alchemy/page_layout.yml file.
42 43 44 |
# File 'app/models/alchemy/page_definition.rb', line 42 def all @definitions ||= read_definitions_file.map { new(**_1) } end |
.get(name) ⇒ Object
Returns one page definition by given name.
69 70 71 72 73 |
# File 'app/models/alchemy/page_definition.rb', line 69 def get(name) return new if name.blank? all.detect { _1.name.casecmp(name).zero? } end |
.layouts_file_path ⇒ Pathname
The absolute page_layouts.yml file path
81 82 83 |
# File 'app/models/alchemy/page_definition.rb', line 81 def layouts_file_path Rails.root.join("config", "alchemy", "page_layouts.yml") end |
.map ⇒ Object Also known as: collect
46 47 48 |
# File 'app/models/alchemy/page_definition.rb', line 46 def map(...) all.map(...) end |
.reset! ⇒ Object
75 76 77 |
# File 'app/models/alchemy/page_definition.rb', line 75 def reset! @definitions = nil end |
Instance Method Details
#attributes ⇒ Object
108 109 110 |
# File 'app/models/alchemy/page_definition.rb', line 108 def attributes super.with_indifferent_access end |
#human_name ⇒ Object
104 105 106 |
# File 'app/models/alchemy/page_definition.rb', line 104 def human_name Alchemy::Page.human_layout_name(name) end |