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.



59
60
61
62
# File 'app/models/alchemy/page_definition.rb', line 59

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.



39
40
41
# File 'app/models/alchemy/page_definition.rb', line 39

def all
  @definitions ||= read_definitions_file.map { new(**_1) }
end

.get(name) ⇒ Object

Returns one page definition by given name.



66
67
68
69
70
# File 'app/models/alchemy/page_definition.rb', line 66

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)


78
79
80
# File 'app/models/alchemy/page_definition.rb', line 78

def layouts_file_path
  Rails.root.join("config", "alchemy", "page_layouts.yml")
end

.mapObject Also known as: collect



43
44
45
# File 'app/models/alchemy/page_definition.rb', line 43

def map(...)
  all.map(...)
end

.reset!Object



72
73
74
# File 'app/models/alchemy/page_definition.rb', line 72

def reset!
  @definitions = nil
end

Instance Method Details

#attributesObject



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

def attributes
  super.with_indifferent_access
end

#human_nameObject



101
102
103
# File 'app/models/alchemy/page_definition.rb', line 101

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