tb_cms 1.2.3 → 1.3.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/assets/javascripts/admin/cms/menu_items.js +39 -17
- data/app/assets/stylesheets/admin/cms/application.css +11 -0
- data/app/controllers/admin/menu_items_controller.rb +103 -113
- data/app/controllers/admin/menus_controller.rb +52 -53
- data/app/controllers/admin/pages_controller.rb +107 -111
- data/app/controllers/admin/snippets_controller.rb +16 -16
- data/app/controllers/cms/sitemaps_controller.rb +5 -5
- data/app/controllers/pages_controller.rb +30 -34
- data/app/helpers/cms/application_helper.rb +184 -212
- data/app/models/concerns/cms_deprecated_multisite.rb +3 -3
- data/app/models/spud_menu.rb +4 -4
- data/app/models/spud_menu_item.rb +58 -61
- data/app/models/spud_page.rb +63 -67
- data/app/models/spud_page_partial.rb +42 -44
- data/app/models/spud_page_partial_revision.rb +3 -3
- data/app/models/spud_snippet.rb +7 -7
- data/app/views/admin/menu_items/index.html.erb +1 -1
- data/lib/generators/spud/cms/layout_generator.rb +8 -8
- data/lib/spud_cms/configuration.rb +10 -10
- data/lib/spud_cms/engine.rb +28 -28
- data/lib/spud_cms/liquid_snippet.rb +5 -7
- data/lib/spud_cms/page_route.rb +1 -1
- data/lib/spud_cms/template_parser.rb +35 -40
- data/lib/spud_cms/test_files.rb +6 -6
- data/lib/spud_cms/version.rb +3 -3
- data/spec/controllers/admin/menu_items_controller_spec.rb +54 -56
- data/spec/controllers/admin/menus_controller_spec.rb +31 -37
- data/spec/controllers/admin/pages_controller_spec.rb +31 -36
- data/spec/controllers/admin/snippets_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +21 -21
- data/spec/dummy/config/application.rb +3 -4
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +3 -3
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/20141231214447_create_spud_users.tb_core.rb +12 -12
- data/spec/dummy/db/migrate/20141231214448_add_time_zone_to_spud_user.tb_core.rb +0 -1
- data/spec/dummy/db/migrate/20141231214449_add_scope_to_spud_admin_permissions.tb_core.rb +0 -1
- data/spec/dummy/db/migrate/20141231214452_create_spud_permissions.tb_core.rb +3 -3
- data/spec/dummy/db/migrate/20141231214453_create_spud_role_permissions.tb_core.rb +2 -2
- data/spec/dummy/db/migrate/20141231214455_create_spud_permalinks.tb_permalinks.rb +1 -1
- data/spec/dummy/db/migrate/20141231214456_add_site_id_to_spud_permalinks.tb_permalinks.rb +1 -1
- data/spec/dummy/db/migrate/20141231214457_modify_site_id_for_spud_permalinks.tb_permalinks.rb +4 -4
- data/spec/dummy/db/migrate/20141231214459_create_spud_pages.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214461_create_spud_menu_items.tb_cms.rb +3 -3
- data/spec/dummy/db/migrate/20141231214463_create_spud_page_partials.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214464_add_visibility_to_spud_pages.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214466_add_use_custom_url_name_to_spud_pages.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214468_add_menu_id_to_spud_menu_items.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214469_add_classes_to_spud_menu_items.tb_cms.rb +0 -1
- data/spec/dummy/db/migrate/20141231214470_add_site_id_to_spud_pages.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214471_add_site_id_to_spud_templates.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214472_add_site_id_to_spud_menus.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214473_create_spud_page_partial_revisions.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214475_modify_site_id_for_spud_pages.tb_cms.rb +8 -8
- data/spec/dummy/db/migrate/20141231214478_create_spud_page_liquid_tags.tb_cms.rb +1 -1
- data/spec/dummy/db/migrate/20141231214479_create_spud_snippets.tb_cms.rb +1 -2
- data/spec/dummy/db/migrate/20141231214480_change_liquid_tags_to_polymorphic.tb_cms.rb +2 -2
- data/spec/dummy/db/migrate/20141231214481_drop_spud_page_liquid_tags.tb_cms.rb +6 -8
- data/spec/dummy/db/migrate/20150108164814_remove_site_id_from_cms_tables.tb_cms.rb +1 -0
- data/spec/dummy/db/migrate/20150911185843_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
- data/spec/dummy/db/migrate/20160215180157_create_tb_redirects.tb_redirects.rb +3 -3
- data/spec/dummy/db/schema.rb +142 -153
- data/spec/dummy/script/rails +2 -2
- data/spec/helpers/cms/application_helper_spec.rb +39 -41
- data/spec/models/spud_menu_item_spec.rb +13 -13
- data/spec/models/spud_page_partial_revision_spec.rb +1 -1
- data/spec/models/spud_page_partial_spec.rb +19 -20
- data/spec/models/spud_page_spec.rb +90 -91
- data/spec/models/spud_snippet_spec.rb +1 -1
- data/spec/rails_helper.rb +12 -6
- data/spec/spec_helper.rb +42 -44
- metadata +64 -38
- data/spec/authlogic_helper.rb +0 -2
@@ -1,86 +1,74 @@
|
|
1
1
|
module Cms::ApplicationHelper
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
content += "<li class='#{active_class if active}'><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>"
|
70
|
-
if max_depth == 0 || max_depth > 1
|
71
|
-
content += sp_list_page(page,pages,2,max_depth,options)
|
72
|
-
end
|
73
|
-
content += "</li>"
|
74
|
-
end
|
75
|
-
content += "</ul>"
|
76
|
-
|
77
|
-
return content.html_safe
|
78
|
-
end
|
2
|
+
MENU_INDEX = {}.freeze
|
3
|
+
|
4
|
+
def sp_snippet(name, snippets = nil)
|
5
|
+
return '' if name.blank?
|
6
|
+
snippet = if !snippets.blank?
|
7
|
+
snippets.select { |s| s.name == name }
|
8
|
+
else
|
9
|
+
SpudSnippet.where(name: name).first
|
10
|
+
end
|
11
|
+
if !snippet.blank?
|
12
|
+
# cache(snippet) do
|
13
|
+
# concat snippet.content_processed.html_safe
|
14
|
+
# end
|
15
|
+
snippet.content_processed.html_safe
|
16
|
+
else
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def sp_list_pages(options = {})
|
22
|
+
pages = SpudPage.viewable.published_pages
|
23
|
+
|
24
|
+
start_page = nil
|
25
|
+
max_depth = 0
|
26
|
+
active_class = 'menu-active'
|
27
|
+
|
28
|
+
if !options.blank?
|
29
|
+
if options.key?(:exclude)
|
30
|
+
|
31
|
+
pages = pages.where(['name NOT IN (?)', options[:exclude]])
|
32
|
+
end
|
33
|
+
start_page = options[:start_page_id] if options.key?(:start_page_id)
|
34
|
+
content = if options.key?(:id)
|
35
|
+
"<ul id='#{options[:id]}' #{"class='#{options[:class]}'" if options.key?(:class)}>"
|
36
|
+
else
|
37
|
+
"<ul #{"class='#{options[:class]}'" if options.key?(:class)}>"
|
38
|
+
end
|
39
|
+
active_class = options[:acive_class] if options.key?(:active_class)
|
40
|
+
max_depth = options[:max_depth] if options.key?(:max_depth)
|
41
|
+
|
42
|
+
else
|
43
|
+
content = '<ul>'
|
44
|
+
end
|
45
|
+
|
46
|
+
pages = pages.to_a.group_by(&:spud_page_id)
|
47
|
+
return '' if pages[start_page].blank?
|
48
|
+
pages[start_page].sort_by(&:page_order).each do |page|
|
49
|
+
active = false
|
50
|
+
unless page.url_name.blank?
|
51
|
+
if current_page?(page_path(id: page.url_name))
|
52
|
+
active = true
|
53
|
+
elsif page.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
54
|
+
active = true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
content += "<li class='#{active_class if active}'><a href='#{page_path(id: page.url_name)}'>#{page.name}</a>"
|
58
|
+
if max_depth == 0 || max_depth > 1
|
59
|
+
content += sp_list_page(page, pages, 2, max_depth, options)
|
60
|
+
end
|
61
|
+
content += '</li>'
|
62
|
+
end
|
63
|
+
content += '</ul>'
|
64
|
+
|
65
|
+
return content.html_safe
|
66
|
+
end
|
79
67
|
|
80
68
|
def sp_list_menu(options = {})
|
81
69
|
options[:path] = request.original_fullpath
|
82
70
|
|
83
|
-
|
71
|
+
unless options.key?(:name)
|
84
72
|
logger.debug 'sp_list_menu require a :name option'
|
85
73
|
return ''
|
86
74
|
end
|
@@ -89,26 +77,26 @@ module Cms::ApplicationHelper
|
|
89
77
|
menu_id = nil
|
90
78
|
link_options = {}
|
91
79
|
start_menu_item = nil
|
92
|
-
menu = SpudMenu.where(:
|
80
|
+
menu = SpudMenu.where(name: options[:name]).first
|
93
81
|
|
94
82
|
if menu.blank?
|
95
83
|
return ''
|
96
84
|
else
|
97
|
-
menu_id = menu.id
|
85
|
+
menu_id = menu.id
|
98
86
|
end
|
99
87
|
|
100
88
|
cache(['sp_list_menu', menu, options]) do
|
101
|
-
link_options = options[:link_options] if options.
|
89
|
+
link_options = options[:link_options] if options.key?(:link_options)
|
102
90
|
|
103
|
-
start_menu_item = options[:start_menu_item_id] if options.
|
104
|
-
if options.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
max_depth = options[:max_depth] if options.
|
91
|
+
start_menu_item = options[:start_menu_item_id] if options.key?(:start_menu_item_id)
|
92
|
+
content = if options.key?(:id)
|
93
|
+
"<ul id='#{options[:id]}' #{"class='#{options[:class]}'" if options.key?(:class)}>"
|
94
|
+
else
|
95
|
+
"<ul #{"class='#{options[:class]}'" if options.key?(:class)}>"
|
96
|
+
end
|
97
|
+
max_depth = options[:max_depth] if options.key?(:max_depth)
|
110
98
|
|
111
|
-
menu_items = SpudMenuItem.where(:
|
99
|
+
menu_items = SpudMenuItem.where(spud_menu_id: menu_id).select("
|
112
100
|
#{SpudMenuItem.table_name}.id as id,
|
113
101
|
#{SpudMenuItem.table_name}.url as url,
|
114
102
|
#{SpudMenuItem.table_name}.classes as classes,
|
@@ -116,25 +104,21 @@ module Cms::ApplicationHelper
|
|
116
104
|
#{SpudMenuItem.table_name}.menu_order as menu_order,
|
117
105
|
#{SpudMenuItem.table_name}.parent_id as parent_id,
|
118
106
|
#{SpudMenuItem.table_name}.name as name,
|
119
|
-
#{SpudPage.table_name}.url_name as url_name").order(:parent_type
|
107
|
+
#{SpudPage.table_name}.url_name as url_name").order(:parent_type, :parent_id).joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)").to_a
|
120
108
|
|
121
109
|
grouped_items = menu_items.group_by(&:parent_type)
|
122
110
|
|
123
|
-
if grouped_items[
|
124
|
-
return ""
|
125
|
-
end
|
111
|
+
return '' if grouped_items['SpudMenu'].blank?
|
126
112
|
|
127
|
-
child_items = grouped_items[
|
113
|
+
child_items = grouped_items['SpudMenuItem'].blank? ? [] : grouped_items['SpudMenuItem'].group_by(&:parent_id)
|
128
114
|
|
129
|
-
parent_items = grouped_items[
|
130
|
-
|
131
|
-
parent_items = child_items[start_menu_item]
|
132
|
-
end
|
115
|
+
parent_items = grouped_items['SpudMenu']
|
116
|
+
parent_items = child_items[start_menu_item] unless start_menu_item.nil?
|
133
117
|
|
134
|
-
parent_items.sort_by
|
118
|
+
parent_items.sort_by(&:menu_order).each do |item|
|
135
119
|
active = false
|
136
120
|
if !item.url_name.blank?
|
137
|
-
if current_page?(page_path(:
|
121
|
+
if current_page?(page_path(id: item.url_name))
|
138
122
|
active = true
|
139
123
|
elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
140
124
|
active = true
|
@@ -142,32 +126,27 @@ module Cms::ApplicationHelper
|
|
142
126
|
elsif current_page?(item.url)
|
143
127
|
active = true
|
144
128
|
end
|
145
|
-
link_tag = link_to item.name, !item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(:
|
146
|
-
content += "<li class='#{
|
129
|
+
link_tag = link_to item.name, !item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(id: item.url_name)) : item.url, { class: "#{'menu-active' if active} #{item.classes unless item.classes.blank?}" }.merge(link_options)
|
130
|
+
content += "<li class='#{'menu-active' if active} #{item.classes unless item.classes.blank?}'>#{link_tag}"
|
147
131
|
if max_depth == 0 || max_depth > 1
|
148
|
-
content += sp_list_menu_item(child_items,item.id,2,max_depth,options)
|
132
|
+
content += sp_list_menu_item(child_items, item.id, 2, max_depth, options)
|
149
133
|
end
|
150
|
-
content +=
|
134
|
+
content += '</li>'
|
151
135
|
end
|
152
136
|
|
153
|
-
content +=
|
137
|
+
content += '</ul>'
|
154
138
|
|
155
139
|
concat content.html_safe
|
156
140
|
end
|
157
141
|
end
|
158
142
|
|
159
|
-
|
143
|
+
def sp_menu_with_seperator(options = {})
|
144
|
+
seperator = ' | '.html_safe
|
145
|
+
seperator = options[:seperator] if options.key?(:seperator)
|
160
146
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
menu = SpudMenu.find_by(:name => options[:name])
|
167
|
-
if(menu.blank?)
|
168
|
-
return ""
|
169
|
-
end
|
170
|
-
menu_items = menu.spud_menu_items_combined.select("
|
147
|
+
menu = SpudMenu.find_by(name: options[:name])
|
148
|
+
return '' if menu.blank?
|
149
|
+
menu_items = menu.spud_menu_items_combined.select("
|
171
150
|
#{SpudMenuItem.table_name}.id as id,
|
172
151
|
#{SpudMenuItem.table_name}.url as url,
|
173
152
|
#{SpudMenuItem.table_name}.classes as classes,
|
@@ -175,119 +154,112 @@ module Cms::ApplicationHelper
|
|
175
154
|
#{SpudMenuItem.table_name}.menu_order as menu_order,
|
176
155
|
#{SpudMenuItem.table_name}.parent_id as parent_id,
|
177
156
|
#{SpudMenuItem.table_name}.name as name,
|
178
|
-
#{SpudPage.table_name}.url_name as url_name").order(:parent_type
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
private
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
return content.html_safe
|
246
|
-
end
|
247
|
-
|
248
|
-
def sp_list_menu_subnav(options={})
|
249
|
-
return_string = ""
|
157
|
+
#{SpudPage.table_name}.url_name as url_name").order(:parent_type, :parent_id).joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)").to_a
|
158
|
+
|
159
|
+
menu_tags = []
|
160
|
+
menu_items.sort_by(&:menu_order).each do |item|
|
161
|
+
menu_tags += ["<a #{"class='#{item.classes}' " unless item.classes.blank?}href='#{!item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(id: item.url_name)) : item.url}'>#{item.name}</a>"]
|
162
|
+
end
|
163
|
+
|
164
|
+
return menu_tags.join(seperator).html_safe
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def sp_list_menu_item(items, item_id, depth, max_depth, options = {})
|
170
|
+
link_options = options.key?(:link_options) ? options[:link_options] : {}
|
171
|
+
spud_menu_items = items[item_id]
|
172
|
+
return '' if spud_menu_items.nil?
|
173
|
+
content = '<ul>'
|
174
|
+
|
175
|
+
spud_menu_items.sort_by(&:menu_order).each do |item|
|
176
|
+
active = false
|
177
|
+
if !item.url_name.blank?
|
178
|
+
if current_page?(page_path(id: item.url_name))
|
179
|
+
active = true
|
180
|
+
elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
181
|
+
active = true
|
182
|
+
end
|
183
|
+
elsif current_page?(item.url)
|
184
|
+
active = true
|
185
|
+
end
|
186
|
+
link_tag = link_to item.name, !item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(id: item.url_name)) : item.url, { class: "#{'menu-active' if active} #{item.classes unless item.classes.blank?}" }.merge(link_options)
|
187
|
+
content += "<li class='#{'menu-active' if active} #{item.classes unless item.classes.blank?}'>#{link_tag}"
|
188
|
+
if max_depth == 0 || max_depth > depth
|
189
|
+
content += sp_list_menu_item(items, item.id, depth + 1, max_depth)
|
190
|
+
end
|
191
|
+
content += '</li>'
|
192
|
+
end
|
193
|
+
content += '</ul>'
|
194
|
+
return content.html_safe
|
195
|
+
end
|
196
|
+
|
197
|
+
def sp_list_page(page, collection, depth, max_depth, options = {})
|
198
|
+
active_class = 'menu-active'
|
199
|
+
active_class = options[:active_class] if options.key?(:active_class)
|
200
|
+
return '' if collection[page.id].blank?
|
201
|
+
content = '<ul>'
|
202
|
+
collection[page.id].sort_by(&:page_order).each do |page|
|
203
|
+
active = false
|
204
|
+
unless page.url_name.blank?
|
205
|
+
if current_page?(page_path(id: page.url_name))
|
206
|
+
active = true
|
207
|
+
elsif page.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
208
|
+
active = true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
content += "<li class='#{active_class if active}'><a href='#{page_path(id: page.url_name)}'>#{page.name}</a>"
|
213
|
+
if max_depth == 0 || max_depth > depth
|
214
|
+
content += sp_list_page(page, collection, depth + 1, max_depth, options)
|
215
|
+
end
|
216
|
+
content += '</li>'
|
217
|
+
end
|
218
|
+
content += '</ul>'
|
219
|
+
return content.html_safe
|
220
|
+
end
|
221
|
+
|
222
|
+
def sp_list_menu_subnav(options = {})
|
223
|
+
return_string = ''
|
250
224
|
base_path = request.path[1..-1]
|
251
|
-
menu_name =
|
252
|
-
classes =
|
225
|
+
menu_name = 'navigation'
|
226
|
+
classes = 'subnav'
|
253
227
|
|
254
|
-
menu_name = options[:name] if options.
|
255
|
-
classes = options[:class] if options.
|
228
|
+
menu_name = options[:name] if options.key?(:name)
|
229
|
+
classes = options[:class] if options.key?(:class)
|
256
230
|
|
257
231
|
menu = SpudMenu.where(name: menu_name).first
|
258
232
|
|
259
|
-
|
233
|
+
unless menu.blank?
|
260
234
|
menu_item = menu.spud_menu_items_combined
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
235
|
+
.joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)")
|
236
|
+
.where([
|
237
|
+
"#{SpudPage.table_name}.url_name = :base_path OR #{SpudMenuItem.table_name}.url = :base_path_slash",
|
238
|
+
{ base_path: base_path, base_path_slash: "/#{base_path}" }
|
239
|
+
]).first
|
266
240
|
|
267
|
-
|
241
|
+
unless menu_item.blank?
|
268
242
|
begin
|
269
243
|
if menu_item.spud_menu_items.count > 0
|
270
|
-
return_string = sp_list_menu(
|
244
|
+
return_string = sp_list_menu(class: classes, name: menu_name, start_menu_item_id: menu_item.id)
|
271
245
|
else
|
272
|
-
return_string = sp_list_menu(
|
246
|
+
return_string = sp_list_menu(class: classes, name: menu_name, start_menu_item_id: menu_item.parent_id)
|
273
247
|
end
|
274
248
|
rescue
|
275
|
-
return_string =
|
249
|
+
return_string = ''
|
276
250
|
end
|
277
251
|
end
|
278
252
|
end
|
279
253
|
return return_string
|
280
254
|
end
|
281
255
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
256
|
+
def layout_options
|
257
|
+
layouts = Spud::Cms::Engine.template_parser.layouts
|
258
|
+
layout_options = []
|
259
|
+
layouts.each_pair do |key, value|
|
260
|
+
layout_options << [value[:template_name], key]
|
261
|
+
end
|
262
|
+
return layout_options
|
263
|
+
end
|
292
264
|
|
293
265
|
end
|
@@ -2,9 +2,9 @@ module CmsDeprecatedMultisite
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
scope :site, ->(
|
5
|
+
scope :site, ->(_sid) {
|
6
6
|
ActiveSupport::Deprecation.warn 'Model.site scope is deprecated and will be removed in the future'
|
7
|
-
|
7
|
+
all()
|
8
8
|
}
|
9
9
|
end
|
10
10
|
|
@@ -13,7 +13,7 @@ module CmsDeprecatedMultisite
|
|
13
13
|
return 0
|
14
14
|
end
|
15
15
|
|
16
|
-
def site_id=(
|
16
|
+
def site_id=(_id)
|
17
17
|
ActiveSupport::Deprecation.warn '#site_id is deprecated and will be removed in the future'
|
18
18
|
return nil
|
19
19
|
end
|
data/app/models/spud_menu.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class SpudMenu < ActiveRecord::Base
|
2
2
|
include CmsDeprecatedMultisite
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
validates :name, presence: true
|
5
|
+
validates :name, uniqueness: true
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
has_many :spud_menu_items, as: :parent, dependent: :destroy
|
8
|
+
has_many :spud_menu_items_combined, class_name: 'SpudMenuItem', foreign_key: :spud_menu_id, dependent: :destroy
|
9
9
|
end
|
@@ -1,69 +1,66 @@
|
|
1
1
|
class SpudMenuItem < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
belongs_to :parent, polymorphic: true
|
3
|
+
belongs_to :spud_menu, touch: true
|
4
|
+
belongs_to :spud_page
|
5
|
+
has_many :spud_menu_items, as: :parent, dependent: :destroy
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
validates :name, presence: true
|
8
|
+
validates :spud_menu_id, presence: true
|
9
|
+
validates :parent_type, presence: true
|
10
|
+
validates :parent_id, presence: true
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def get_url
|
13
|
+
if !spud_page.blank?
|
14
|
+
return spud_page.url_name
|
15
|
+
else
|
16
|
+
return url
|
17
|
+
end
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return options
|
31
|
-
end
|
32
|
-
def self.grouped(menu)
|
33
|
-
return menu.spud_menu_items_combined.group_by(&:parent_type)
|
34
|
-
end
|
20
|
+
def options_tree(options, depth, current = nil)
|
21
|
+
sub_items = spud_menu_items
|
22
|
+
sub_items = sub_items.where(['id != ?', current.id]) if !current.blank? && !current.id.blank?
|
23
|
+
return options if sub_items.blank?
|
24
|
+
sub_items.each do |item|
|
25
|
+
options << ["#{'-' * depth} #{item.name}", item.id]
|
26
|
+
options = item.options_tree(options, depth + 1, current)
|
27
|
+
end
|
28
|
+
return options
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def self.options_tree_for_item(menu,config={})
|
40
|
-
collection = config[:collection] || self.grouped(menu)
|
41
|
-
level = config[:level] || 0
|
42
|
-
parent_id = config[:parent_id] || nil
|
43
|
-
parent_type = config[:parent_type] || 'SpudMenu'
|
44
|
-
filter = config[:filter] || nil
|
45
|
-
value = config[:value] || :id
|
46
|
-
list = []
|
47
|
-
if parent_type == 'SpudMenu' && collection[parent_type]
|
48
|
-
item_collection = collection['SpudMenuItem'].group_by(&:parent_id) if collection['SpudMenuItem']
|
49
|
-
collection[parent_type].each do |c|
|
50
|
-
if filter.blank? || c.id != filter.id
|
51
|
-
list << [level.times.collect{ '- ' }.join('') + c.name, c[value]]
|
52
|
-
list += self.options_tree_for_item(menu,{:collection => item_collection, :parent_id => c.id, :level => level+1, :filter => filter,:parent_type => "SpudMenuItem"})
|
53
|
-
end
|
54
|
-
end
|
55
|
-
else
|
56
|
-
if collection[parent_id]
|
57
|
-
collection[parent_id].each do |c|
|
58
|
-
if filter.blank? || c.id != filter.id
|
59
|
-
list << [level.times.collect{ '- ' }.join('') + c.name, c[value]]
|
60
|
-
list += self.options_tree_for_item(menu,{:collection => collection, :parent_id => c.id, :level => level+1, :filter => filter,:parent_type => "SpudMenuItem"})
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
31
|
+
def self.grouped(menu)
|
32
|
+
return menu.spud_menu_items_combined.group_by(&:parent_type)
|
33
|
+
end
|
65
34
|
|
66
|
-
|
67
|
-
|
35
|
+
# Returns an array of pages in order of heirarchy
|
36
|
+
# :fitler Filters out a page by ID, and all of its children
|
37
|
+
# :value Pick an attribute to be used in the value field, defaults to ID
|
38
|
+
def self.options_tree_for_item(menu, config = {})
|
39
|
+
collection = config[:collection] || grouped(menu)
|
40
|
+
level = config[:level] || 0
|
41
|
+
parent_id = config[:parent_id] || nil
|
42
|
+
parent_type = config[:parent_type] || 'SpudMenu'
|
43
|
+
filter = config[:filter] || nil
|
44
|
+
value = config[:value] || :id
|
45
|
+
list = []
|
46
|
+
if parent_type == 'SpudMenu' && collection[parent_type]
|
47
|
+
item_collection = collection['SpudMenuItem'].group_by(&:parent_id) if collection['SpudMenuItem']
|
48
|
+
collection[parent_type].each do |c|
|
49
|
+
if filter.blank? || c.id != filter.id
|
50
|
+
list << [Array.new(level) { '- ' }.join('') + c.name, c[value]]
|
51
|
+
list += options_tree_for_item(menu, collection: item_collection, parent_id: c.id, level: level + 1, filter: filter, parent_type: 'SpudMenuItem')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
collection[parent_id]&.each do |c|
|
56
|
+
if filter.blank? || c.id != filter.id
|
57
|
+
list << [Array.new(level) { '- ' }.join('') + c.name, c[value]]
|
58
|
+
list += options_tree_for_item(menu, collection: collection, parent_id: c.id, level: level + 1, filter: filter, parent_type: 'SpudMenuItem')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
return list
|
64
|
+
end
|
68
65
|
|
69
66
|
end
|