Class: Alchemy::ElementDefinition
- Inherits:
-
Object
- Object
- Alchemy::ElementDefinition
- Defined in:
- lib/alchemy/element_definition.rb
Class Method Summary collapse
-
.add(element) ⇒ Object
Add additional page definitions to collection.
-
.all ⇒ Object
Returns the definitions from elements.yml file.
-
.definitions_file_path ⇒ Pathname
The absolute
elements.yml
file path. -
.get(name) ⇒ Object
Returns one element definition by given name.
- .reset! ⇒ Object
Class Method Details
.add(element) ⇒ Object
Add additional page definitions to collection.
Useful for extending the elements from an Alchemy module.
Usage Example
Call +Alchemy::ElementDefinition.add(your_definition)+ in your engine.rb file.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/alchemy/element_definition.rb', line 26 def add(element) all if element.is_a?(Array) @definitions += element elsif element.is_a?(Hash) @definitions << element else raise TypeError end end |
.all ⇒ Object
Returns the definitions from elements.yml file.
Place a elements.yml
file inside your apps config/alchemy
folder to define your own set of elements
11 12 13 |
# File 'lib/alchemy/element_definition.rb', line 11 def all @definitions ||= read_definitions_file.map(&:with_indifferent_access) end |
.definitions_file_path ⇒ Pathname
The absolute elements.yml
file path
51 52 53 |
# File 'lib/alchemy/element_definition.rb', line 51 def definitions_file_path Rails.root.join("config", "alchemy", "elements.yml") end |
.get(name) ⇒ Object
Returns one element definition by given name.
39 40 41 42 43 |
# File 'lib/alchemy/element_definition.rb', line 39 def get(name) return {} if name.blank? all.detect { |a| a["name"] == name } end |
.reset! ⇒ Object
45 46 47 |
# File 'lib/alchemy/element_definition.rb', line 45 def reset! @definitions = nil end |