Module: Alchemy::Site::Layout

Extended by:
ActiveSupport::Concern
Included in:
Alchemy::Site
Defined in:
app/models/alchemy/site/layout.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SITE_DEFINITIONS_FILE =
Rails.root.join("config/alchemy/site_layouts.yml")

Instance Method Summary collapse

Instance Method Details

#definitionObject

Returns sites layout definition



30
31
32
# File 'app/models/alchemy/site/layout.rb', line 30

def definition
  self.class.definitions.detect { |l| l["name"] == partial_name } || {}
end

#page_layout_definitionsObject

Returns sites page layout definitions

If no site layout file is defined all page layouts are returned



52
53
54
55
56
57
58
59
60
# File 'app/models/alchemy/site/layout.rb', line 52

def page_layout_definitions
  if definition["page_layouts"].presence
    Alchemy::PageLayout.all.select do |layout|
      layout["name"].in?(definition["page_layouts"])
    end
  else
    Alchemy::PageLayout.all
  end
end

#page_layout_names(layoutpages: false) ⇒ Array<String>

Returns sites page layout names

If no site layout file is defined all page layouts are returned

Parameters:

  • layoutpages (Boolean) (defaults to: false)

    Return layout pages only (default false)

Returns:

  • (Array<String>)

    Array of page layout names



42
43
44
45
46
# File 'app/models/alchemy/site/layout.rb', line 42

def page_layout_names(layoutpages: false)
  page_layout_definitions.select do |layout|
    !!layout["layoutpage"] && layoutpages || !layout["layoutpage"] && !layoutpages
  end.collect { |layout| layout["name"] }
end

#partial_nameObject

Returns the name for the layout partial



64
65
66
# File 'app/models/alchemy/site/layout.rb', line 64

def partial_name
  name.parameterize.underscore
end