class Alchemy::PageLayout
Public Class Methods
add(page_layout)
click to toggle source
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.
@param [Array || Hash]
You can pass a single layout definition as Hash, or a collection of page layouts as Array.
# 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
all()
click to toggle source
Returns all page layouts.
They are defined in config/alchemy/page_layout.yml
file.
# File lib/alchemy/page_layout.rb, line 10 def all @definitions ||= read_definitions_file.map(&:with_indifferent_access) end
get(name)
click to toggle source
Returns one page definition by given name.
# File lib/alchemy/page_layout.rb, line 38 def get(name) return {} if name.blank? all.detect { |a| a["name"].casecmp(name).zero? } end
layouts_file_path()
click to toggle source
The absolute page_layouts.yml
file path @return [Pathname]
# File lib/alchemy/page_layout.rb, line 50 def layouts_file_path Rails.root.join("config", "alchemy", "page_layouts.yml") end
reset!()
click to toggle source
# File lib/alchemy/page_layout.rb, line 44 def reset! @definitions = nil end
Private Class Methods
read_definitions_file()
click to toggle source
Reads the layout definitions from config/alchemy/page_layouts.yml
.
# File lib/alchemy/page_layout.rb, line 58 def read_definitions_file if File.exist?(layouts_file_path) Array.wrap( YAML.safe_load( ERB.new(File.read(layouts_file_path)).result, permitted_classes: YAML_PERMITTED_CLASSES, aliases: true ) || [] ) else raise LoadError, "Could not find page_layouts.yml file! Please run `rails generate alchemy:install`" end end