Class: Alchemy::PageLayout

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

Class Method Summary collapse

Class Method Details

.add(page_layout) ⇒ Object

Add additional page definitions to collection.

Useful for extending the page layouts from an Alchemy module.

Usage Example

Call +Alchemy::PageLayout.add(your_definition)+ in your engine.rb file.

Parameters:

  • You (Array || Hash)

    can pass a single layout definition as Hash, or a collection of page layouts as Array.



25
26
27
28
29
30
31
32
33
34
# File 'lib/alchemy/page_layout.rb', line 25

def add(page_layout)
  all
  if page_layout.is_a?(Array)
    @definitions += page_layout
  elsif page_layout.is_a?(Hash)
    @definitions << page_layout
  else
    raise TypeError
  end
end

.allObject

Returns all page layouts.

They are defined in config/alchemy/page_layout.yml file.



10
11
12
# File 'lib/alchemy/page_layout.rb', line 10

def all
  @definitions ||= read_definitions_file.map(&:with_indifferent_access)
end

.get(name) ⇒ Object

Returns one page definition by given name.



38
39
40
41
42
# File 'lib/alchemy/page_layout.rb', line 38

def get(name)
  return {} if name.blank?

  all.detect { |a| a["name"].casecmp(name).zero? }
end