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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/javascripts/admin/cms/menu_items.js +39 -17
  4. data/app/assets/stylesheets/admin/cms/application.css +11 -0
  5. data/app/controllers/admin/menu_items_controller.rb +103 -113
  6. data/app/controllers/admin/menus_controller.rb +52 -53
  7. data/app/controllers/admin/pages_controller.rb +107 -111
  8. data/app/controllers/admin/snippets_controller.rb +16 -16
  9. data/app/controllers/cms/sitemaps_controller.rb +5 -5
  10. data/app/controllers/pages_controller.rb +30 -34
  11. data/app/helpers/cms/application_helper.rb +184 -212
  12. data/app/models/concerns/cms_deprecated_multisite.rb +3 -3
  13. data/app/models/spud_menu.rb +4 -4
  14. data/app/models/spud_menu_item.rb +58 -61
  15. data/app/models/spud_page.rb +63 -67
  16. data/app/models/spud_page_partial.rb +42 -44
  17. data/app/models/spud_page_partial_revision.rb +3 -3
  18. data/app/models/spud_snippet.rb +7 -7
  19. data/app/views/admin/menu_items/index.html.erb +1 -1
  20. data/lib/generators/spud/cms/layout_generator.rb +8 -8
  21. data/lib/spud_cms/configuration.rb +10 -10
  22. data/lib/spud_cms/engine.rb +28 -28
  23. data/lib/spud_cms/liquid_snippet.rb +5 -7
  24. data/lib/spud_cms/page_route.rb +1 -1
  25. data/lib/spud_cms/template_parser.rb +35 -40
  26. data/lib/spud_cms/test_files.rb +6 -6
  27. data/lib/spud_cms/version.rb +3 -3
  28. data/spec/controllers/admin/menu_items_controller_spec.rb +54 -56
  29. data/spec/controllers/admin/menus_controller_spec.rb +31 -37
  30. data/spec/controllers/admin/pages_controller_spec.rb +31 -36
  31. data/spec/controllers/admin/snippets_controller_spec.rb +1 -1
  32. data/spec/controllers/pages_controller_spec.rb +21 -21
  33. data/spec/dummy/config/application.rb +3 -4
  34. data/spec/dummy/config/boot.rb +1 -1
  35. data/spec/dummy/config/environments/production.rb +1 -1
  36. data/spec/dummy/config/environments/test.rb +3 -3
  37. data/spec/dummy/config.ru +1 -1
  38. data/spec/dummy/db/migrate/20141231214447_create_spud_users.tb_core.rb +12 -12
  39. data/spec/dummy/db/migrate/20141231214448_add_time_zone_to_spud_user.tb_core.rb +0 -1
  40. data/spec/dummy/db/migrate/20141231214449_add_scope_to_spud_admin_permissions.tb_core.rb +0 -1
  41. data/spec/dummy/db/migrate/20141231214452_create_spud_permissions.tb_core.rb +3 -3
  42. data/spec/dummy/db/migrate/20141231214453_create_spud_role_permissions.tb_core.rb +2 -2
  43. data/spec/dummy/db/migrate/20141231214455_create_spud_permalinks.tb_permalinks.rb +1 -1
  44. data/spec/dummy/db/migrate/20141231214456_add_site_id_to_spud_permalinks.tb_permalinks.rb +1 -1
  45. data/spec/dummy/db/migrate/20141231214457_modify_site_id_for_spud_permalinks.tb_permalinks.rb +4 -4
  46. data/spec/dummy/db/migrate/20141231214459_create_spud_pages.tb_cms.rb +1 -1
  47. data/spec/dummy/db/migrate/20141231214461_create_spud_menu_items.tb_cms.rb +3 -3
  48. data/spec/dummy/db/migrate/20141231214463_create_spud_page_partials.tb_cms.rb +1 -1
  49. data/spec/dummy/db/migrate/20141231214464_add_visibility_to_spud_pages.tb_cms.rb +2 -2
  50. data/spec/dummy/db/migrate/20141231214466_add_use_custom_url_name_to_spud_pages.tb_cms.rb +1 -1
  51. data/spec/dummy/db/migrate/20141231214468_add_menu_id_to_spud_menu_items.tb_cms.rb +1 -1
  52. data/spec/dummy/db/migrate/20141231214469_add_classes_to_spud_menu_items.tb_cms.rb +0 -1
  53. data/spec/dummy/db/migrate/20141231214470_add_site_id_to_spud_pages.tb_cms.rb +2 -2
  54. data/spec/dummy/db/migrate/20141231214471_add_site_id_to_spud_templates.tb_cms.rb +2 -2
  55. data/spec/dummy/db/migrate/20141231214472_add_site_id_to_spud_menus.tb_cms.rb +2 -2
  56. data/spec/dummy/db/migrate/20141231214473_create_spud_page_partial_revisions.tb_cms.rb +1 -1
  57. data/spec/dummy/db/migrate/20141231214475_modify_site_id_for_spud_pages.tb_cms.rb +8 -8
  58. data/spec/dummy/db/migrate/20141231214478_create_spud_page_liquid_tags.tb_cms.rb +1 -1
  59. data/spec/dummy/db/migrate/20141231214479_create_spud_snippets.tb_cms.rb +1 -2
  60. data/spec/dummy/db/migrate/20141231214480_change_liquid_tags_to_polymorphic.tb_cms.rb +2 -2
  61. data/spec/dummy/db/migrate/20141231214481_drop_spud_page_liquid_tags.tb_cms.rb +6 -8
  62. data/spec/dummy/db/migrate/20150108164814_remove_site_id_from_cms_tables.tb_cms.rb +1 -0
  63. data/spec/dummy/db/migrate/20150911185843_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
  64. data/spec/dummy/db/migrate/20160215180157_create_tb_redirects.tb_redirects.rb +3 -3
  65. data/spec/dummy/db/schema.rb +142 -153
  66. data/spec/dummy/script/rails +2 -2
  67. data/spec/helpers/cms/application_helper_spec.rb +39 -41
  68. data/spec/models/spud_menu_item_spec.rb +13 -13
  69. data/spec/models/spud_page_partial_revision_spec.rb +1 -1
  70. data/spec/models/spud_page_partial_spec.rb +19 -20
  71. data/spec/models/spud_page_spec.rb +90 -91
  72. data/spec/models/spud_snippet_spec.rb +1 -1
  73. data/spec/rails_helper.rb +12 -6
  74. data/spec/spec_helper.rb +42 -44
  75. metadata +64 -38
  76. data/spec/authlogic_helper.rb +0 -2
@@ -1,86 +1,74 @@
1
1
  module Cms::ApplicationHelper
2
- MENU_INDEX = {}
3
-
4
- def sp_snippet(name, snippets=nil)
5
- if name.blank?
6
- return ''
7
- end
8
- if !snippets.blank?
9
- snippet = snippets.select {|s| s.name == name}
10
- else
11
- snippet = SpudSnippet.where(:name => name).first
12
- end
13
- if !snippet.blank?
14
- # cache(snippet) do
15
- # concat snippet.content_processed.html_safe
16
- # end
17
- snippet.content_processed.html_safe
18
- else
19
- return nil
20
- end
21
- end
22
-
23
- def sp_list_pages(options = {})
24
-
25
- pages = SpudPage.viewable.published_pages
26
-
27
- start_page = nil
28
- max_depth = 0
29
- active_class = "menu-active"
30
-
31
- if !options.blank?
32
- if options.has_key?(:exclude)
33
-
34
- pages = pages.where(["name NOT IN (?)",options[:exclude]])
35
- end
36
- if options.has_key?(:start_page_id)
37
- start_page = options[:start_page_id]
38
- end
39
- if options.has_key?(:id)
40
- content = "<ul id='#{options[:id]}' #{"class='#{options[:class]}'" if options.has_key?(:class)}>"
41
- else
42
- content = "<ul #{"class='#{options[:class]}'" if options.has_key?(:class)}>"
43
- end
44
- if options.has_key?(:active_class)
45
- active_class = options[:acive_class]
46
- end
47
- if options.has_key?(:max_depth)
48
- max_depth = options[:max_depth]
49
- end
50
-
51
- else
52
- content = "<ul>"
53
- end
54
-
55
- pages = pages.to_a.group_by(&:spud_page_id)
56
- if pages[start_page].blank?
57
-
58
- return ""
59
- end
60
- pages[start_page].sort_by{|p| p.page_order}.each do |page|
61
- active = false
62
- if !page.url_name.blank?
63
- if current_page?(page_path(:id => page.url_name))
64
- active = true
65
- elsif page.url_name == Spud::Cms.root_page_name && current_page?(root_path)
66
- active = true
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
- if !options.has_key?(:name)
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(:name => options[:name]).first
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.has_key?(:link_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.has_key?(:start_menu_item_id)
104
- if options.has_key?(:id)
105
- content = "<ul id='#{options[:id]}' #{"class='#{options[:class]}'" if options.has_key?(:class)}>"
106
- else
107
- content = "<ul #{"class='#{options[:class]}'" if options.has_key?(:class)}>"
108
- end
109
- max_depth = options[:max_depth] if options.has_key?(:max_depth)
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(:spud_menu_id => menu_id).select("
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,:parent_id).joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)").to_a
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["SpudMenu"].blank?
124
- return ""
125
- end
111
+ return '' if grouped_items['SpudMenu'].blank?
126
112
 
127
- child_items = grouped_items["SpudMenuItem"].blank? ? [] : grouped_items["SpudMenuItem"].group_by(&:parent_id)
113
+ child_items = grouped_items['SpudMenuItem'].blank? ? [] : grouped_items['SpudMenuItem'].group_by(&:parent_id)
128
114
 
129
- parent_items = grouped_items["SpudMenu"]
130
- if start_menu_item != nil
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{|p| p.menu_order}.each do |item|
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(:id => item.url_name))
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(:id => item.url_name)) : item.url, {:class => "#{'menu-active' if active} #{item.classes if !item.classes.blank?}"}.merge(link_options)
146
- content += "<li class='#{"menu-active" if active} #{item.classes if !item.classes.blank?}'>#{link_tag}"
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 += "</li>"
134
+ content += '</li>'
151
135
  end
152
136
 
153
- content += "</ul>"
137
+ content += '</ul>'
154
138
 
155
139
  concat content.html_safe
156
140
  end
157
141
  end
158
142
 
159
- def sp_menu_with_seperator(options={})
143
+ def sp_menu_with_seperator(options = {})
144
+ seperator = '&nbsp;|&nbsp;'.html_safe
145
+ seperator = options[:seperator] if options.key?(:seperator)
160
146
 
161
- seperator = "&nbsp;|&nbsp;".html_safe
162
- if(options.has_key?(:seperator))
163
- seperator = options[:seperator]
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,:parent_id).joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)").to_a
179
-
180
- menu_tags = []
181
- menu_items.sort_by{|p| p.menu_order}.each do |item|
182
- menu_tags += ["<a #{"class='#{item.classes}' " if !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>"]
183
- end
184
-
185
- return menu_tags.join(seperator).html_safe
186
- end
187
-
188
- private
189
- def sp_list_menu_item(items,item_id,depth,max_depth, options = {})
190
- link_options = options.has_key?(:link_options) ? options[:link_options] : {}
191
- spud_menu_items = items[item_id]
192
- if spud_menu_items == nil
193
- return ""
194
- end
195
- content = "<ul>"
196
-
197
- spud_menu_items.sort_by{|p| p.menu_order}.each do |item|
198
- active = false
199
- if !item.url_name.blank?
200
- if current_page?(page_path(:id => item.url_name))
201
- active = true
202
- elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path)
203
- active = true
204
- end
205
- elsif current_page?(item.url)
206
- active = true
207
- end
208
- 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 if !item.classes.blank?}"}.merge(link_options)
209
- content += "<li class='#{"menu-active" if active} #{item.classes if !item.classes.blank?}'>#{link_tag}"
210
- if max_depth == 0 || max_depth > depth
211
- content += sp_list_menu_item(items,item.id,depth+1,max_depth)
212
- end
213
- content += "</li>"
214
- end
215
- content += "</ul>"
216
- return content.html_safe
217
- end
218
-
219
- def sp_list_page(page,collection,depth,max_depth,options = {})
220
- active_class = 'menu-active'
221
- if options.has_key?(:active_class)
222
- active_class = options[:active_class]
223
- end
224
- if collection[page.id].blank?
225
- return ""
226
- end
227
- content = "<ul>"
228
- collection[page.id].sort_by{|p| p.page_order}.each do |page|
229
- active = false
230
- if !page.url_name.blank?
231
- if current_page?(page_path(:id => page.url_name))
232
- active = true
233
- elsif page.url_name == Spud::Cms.root_page_name && current_page?(root_path)
234
- active = true
235
- end
236
- end
237
-
238
- content += "<li class='#{active_class if active}'><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>"
239
- if max_depth == 0 || max_depth > depth
240
- content += sp_list_page(page,collection,depth+1,max_depth,options)
241
- end
242
- content += "</li>"
243
- end
244
- content += "</ul>"
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 = "navigation"
252
- classes = "subnav"
225
+ menu_name = 'navigation'
226
+ classes = 'subnav'
253
227
 
254
- menu_name = options[:name] if options.has_key?(:name);
255
- classes = options[:class] if options.has_key?(:class);
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
- if !menu.blank?
233
+ unless menu.blank?
260
234
  menu_item = menu.spud_menu_items_combined
261
- .joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)")
262
- .where([
263
- "#{SpudPage.table_name}.url_name = :base_path OR #{SpudMenuItem.table_name}.url = :base_path_slash",
264
- {:base_path => base_path, :base_path_slash => "/#{base_path}"}
265
- ]).first
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
- if !menu_item.blank?
241
+ unless menu_item.blank?
268
242
  begin
269
243
  if menu_item.spud_menu_items.count > 0
270
- return_string = sp_list_menu({class: classes, name: menu_name, start_menu_item_id: menu_item.id})
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({class: classes, name: menu_name, start_menu_item_id: menu_item.parent_id})
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
- def layout_options
283
- layouts = Spud::Cms::Engine.template_parser.layouts
284
- layout_options = []
285
- layouts.each_pair do |key,value|
286
- layout_options << [value[:template_name],key]
287
- end
288
- return layout_options
289
- end
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, ->(sid){
5
+ scope :site, ->(_sid) {
6
6
  ActiveSupport::Deprecation.warn 'Model.site scope is deprecated and will be removed in the future'
7
- self.all()
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=(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
@@ -1,9 +1,9 @@
1
1
  class SpudMenu < ActiveRecord::Base
2
2
  include CmsDeprecatedMultisite
3
3
 
4
- validates :name,:presence => true
5
- validates_uniqueness_of :name
4
+ validates :name, presence: true
5
+ validates :name, uniqueness: true
6
6
 
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
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
- 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
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
- validates :name,:presence => true
8
- validates :spud_menu_id,:presence => true
9
- validates :parent_type,:presence => true
10
- validates :parent_id,:presence => true
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
- def get_url
13
- if !self.spud_page.blank?
14
- return self.spud_page.url_name
15
- else
16
- return url
17
- end
18
- end
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
- def options_tree(options,depth,current = nil)
21
- sub_items = self.spud_menu_items
22
- sub_items = sub_items.where(["id != ?",current.id]) if !current.blank? && !current.id.blank?
23
- if(sub_items.blank?)
24
- return options
25
- end
26
- sub_items.each do |item|
27
- options << ["#{'-'*depth} #{item.name}",item.id]
28
- options = item.options_tree(options,depth+1,current)
29
- end
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
- # Returns an array of pages in order of heirarchy
37
- # :fitler Filters out a page by ID, and all of its children
38
- # :value Pick an attribute to be used in the value field, defaults to ID
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
- return list
67
- end
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