Class: Alchemy::PageDefinition

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Translation
Includes:
ActiveModel::Attributes, ActiveModel::Model, Hints
Defined in:
app/models/alchemy/page_definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hints

#has_hint?, #hint

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.

Parameters:

  • You (Array || Hash)

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



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

.allObject

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_pathPathname

The absolute page_layouts.yml file path

Returns:

  • (Pathname)


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

.mapObject 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

#attributesObject



108
109
110
# File 'app/models/alchemy/page_definition.rb', line 108

def attributes
  super.with_indifferent_access
end

#human_nameObject



104
105
106
# File 'app/models/alchemy/page_definition.rb', line 104

def human_name
  Alchemy::Page.human_layout_name(name)
end