Class: Alchemy::ElementDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy/element_definition.rb

Class Method Summary collapse

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.

Parameters:

  • You (Array || Hash)

    can pass a single element definition as Hash, or a collection of elements as Array.


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

.allObject

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

.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