Module: Alchemy::Page::PageLayouts::ClassMethods
- Defined in:
- app/models/alchemy/page/page_layouts.rb
Instance Method Summary collapse
-
#human_layout_name(layout) ⇒ Object
Translates name for given layout.
-
#layouts_for_select(language_id, layoutpages: false) ⇒ Object
Returns page layouts ready for Rails’ select form helper.
-
#layouts_repository=(klass) ⇒ Object
Register a custom page layouts repository.
-
#selectable_layouts(language_id, layoutpages: false) ⇒ Object
Returns all layouts that can be used for creating a new page.
Instance Method Details
#human_layout_name(layout) ⇒ Object
Translates name for given layout
Translation example
en:
alchemy:
page_layout_names:
products_overview: Products Overview
58 59 60 |
# File 'app/models/alchemy/page/page_layouts.rb', line 58 def human_layout_name(layout) Alchemy.t(layout, scope: "page_layout_names", default: layout.to_s.humanize) end |
#layouts_for_select(language_id, layoutpages: false) ⇒ Object
Returns page layouts ready for Rails’ select form helper.
21 22 23 24 |
# File 'app/models/alchemy/page/page_layouts.rb', line 21 def layouts_for_select(language_id, layoutpages: false) @map_array = [] mapped_layouts_for_select(selectable_layouts(language_id, layoutpages: layoutpages)) end |
#layouts_repository=(klass) ⇒ Object
Register a custom page layouts repository
The default repository is Alchemy::PageLayout
15 16 17 |
# File 'app/models/alchemy/page/page_layouts.rb', line 15 def layouts_repository=(klass) @_layouts_repository = klass end |
#selectable_layouts(language_id, layoutpages: false) ⇒ Object
Returns all layouts that can be used for creating a new page.
It removes all layouts from available layouts that are unique and already taken and that are marked as hide.
35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/alchemy/page/page_layouts.rb', line 35 def selectable_layouts(language_id, layoutpages: false) @language_id = language_id layouts_repository.all.select do |layout| if layoutpages layout["layoutpage"] && layout_available?(layout) else !layout["layoutpage"] && layout_available?(layout) end end end |