@@ -4,13 +4,13 @@ module Alchemy
44 class Page < BaseRecord
55 # Module concerning page layouts
66 #
7- module PageLayouts
7+ module Definitions
88 extend ActiveSupport ::Concern
99
1010 module ClassMethods
1111 # Register a custom page layouts repository
1212 #
13- # The default repository is Alchemy::PageLayout
13+ # The default repository is Alchemy::PageDefinition
1414 #
1515 def layouts_repository = ( klass )
1616 @_layouts_repository = klass
@@ -19,8 +19,10 @@ def layouts_repository=(klass)
1919 # Returns page layouts ready for Rails' select form helper.
2020 #
2121 def layouts_for_select ( language_id , layoutpages : false )
22- @map_array = [ ]
23- mapped_layouts_for_select ( selectable_layouts ( language_id , layoutpages : layoutpages ) )
22+ layouts = selectable_layouts ( language_id , layoutpages : layoutpages )
23+ layouts . map do |layout |
24+ [ layout . human_name , layout . name ]
25+ end
2426 end
2527
2628 # Returns all layouts that can be used for creating a new page.
@@ -36,9 +38,9 @@ def selectable_layouts(language_id, layoutpages: false)
3638 @language_id = language_id
3739 layouts_repository . all . select do |layout |
3840 if layoutpages
39- layout [ " layoutpage" ] && layout_available? ( layout )
41+ layout . layoutpage && layout_available? ( layout )
4042 else
41- !layout [ " layoutpage" ] && layout_available? ( layout )
43+ !layout . layoutpage && layout_available? ( layout )
4244 end
4345 end
4446 end
@@ -62,28 +64,19 @@ def human_layout_name(layout)
6264 private
6365
6466 def layouts_repository
65- @_layouts_repository ||= PageLayout
66- end
67-
68- # Maps given layouts for Rails select form helper.
69- #
70- def mapped_layouts_for_select ( layouts )
71- layouts . each do |layout |
72- @map_array << [ human_layout_name ( layout [ "name" ] ) , layout [ "name" ] ]
73- end
74- @map_array
67+ @_layouts_repository ||= PageDefinition
7568 end
7669
7770 # Returns true if the given layout is unique and not already taken or it should be hidden.
7871 #
7972 def layout_available? ( layout )
80- !layout [ " hide" ] && !already_taken? ( layout ) && available_on_site? ( layout )
73+ !layout . hide && !already_taken? ( layout ) && available_on_site? ( layout )
8174 end
8275
8376 # Returns true if this layout is unique and already taken by another page.
8477 #
8578 def already_taken? ( layout )
86- layout [ " unique" ] && page_with_layout_existing? ( layout [ " name" ] )
79+ layout . unique && page_with_layout_existing? ( layout . name )
8780 end
8881
8982 # Returns true if one page already has the given layout
@@ -106,7 +99,7 @@ def available_on_site?(layout)
10699 return false unless Alchemy ::Current . site
107100
108101 Alchemy ::Current . site . definition . blank? ||
109- Alchemy ::Current . site . definition . fetch ( "page_layouts" , [ ] ) . include? ( layout [ " name" ] )
102+ Alchemy ::Current . site . definition . fetch ( "page_layouts" , [ ] ) . include? ( layout . name )
110103 end
111104 end
112105 end
0 commit comments