tb_cms 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.markdown +1 -1
- data/app/controllers/admin/menu_items_controller.rb +5 -5
- data/app/controllers/admin/menus_controller.rb +8 -2
- data/app/controllers/admin/pages_controller.rb +7 -21
- data/app/controllers/admin/snippets_controller.rb +7 -4
- data/app/controllers/cms/sitemaps_controller.rb +0 -2
- data/app/controllers/pages_controller.rb +1 -10
- data/app/helpers/cms/application_helper.rb +90 -98
- data/app/models/spud_menu.rb +2 -3
- data/app/models/spud_menu_item.rb +1 -4
- data/app/models/spud_page.rb +6 -8
- data/app/models/spud_page_partial.rb +6 -21
- data/app/models/spud_page_partial_revision.rb +1 -1
- data/app/models/spud_snippet.rb +3 -19
- data/app/views/admin/menu_items/_menu_item_row.html.erb +2 -2
- data/app/views/admin/menus/index.html.erb +6 -9
- data/app/views/admin/pages/_page_row.html.erb +16 -16
- data/app/views/admin/pages/edit.html.erb +1 -1
- data/app/views/admin/snippets/index.html.erb +1 -1
- data/app/views/pages/show.html.erb +27 -22
- data/config/routes.rb +1 -4
- data/db/migrate/20121119030136_change_liquid_tags_to_polymorphic.rb +4 -2
- data/db/migrate/20140110142037_drop_spud_page_liquid_tags.rb +31 -0
- data/lib/spud_cms/engine.rb +1 -9
- data/lib/spud_cms/page_route.rb +2 -4
- data/lib/spud_cms/version.rb +1 -1
- data/spec/controllers/admin/menu_items_controller_spec.rb +0 -2
- data/spec/controllers/cms/sitemaps_controller_spec.rb +11 -17
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/environments/test.rb +9 -2
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/db/migrate/{20120307002859_create_spud_admin_permissions.spud_core.rb → 20140110051449_create_spud_admin_permissions.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/{20120307002860_create_spud_users.spud_core.rb → 20140110051450_create_spud_users.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/{20120610123555_add_time_zone_to_spud_user.spud_core.rb → 20140110051451_add_time_zone_to_spud_user.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/20140110051452_add_scope_to_spud_admin_permissions.tb_core.rb +7 -0
- data/spec/dummy/db/migrate/{20120610123557_create_spud_user_settings.spud_core.rb → 20140110051453_create_spud_user_settings.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/20140110051454_create_spud_roles.tb_core.rb +11 -0
- data/spec/dummy/db/migrate/20140110051455_create_spud_permissions.tb_core.rb +11 -0
- data/spec/dummy/db/migrate/20140110051456_create_spud_role_permissions.tb_core.rb +12 -0
- data/spec/dummy/db/migrate/20140110051457_drop_spud_admin_permissions.tb_core.rb +16 -0
- data/spec/dummy/db/migrate/20140110051458_create_spud_liquid_tags.tb_core.rb +13 -0
- data/spec/dummy/db/migrate/20140110051459_create_spud_permalinks.tb_permalinks.rb +12 -0
- data/spec/dummy/db/migrate/20140110051460_add_site_id_to_spud_permalinks.tb_permalinks.rb +7 -0
- data/spec/dummy/db/migrate/20140110051461_modify_site_id_for_spud_permalinks.tb_permalinks.rb +12 -0
- data/spec/dummy/db/migrate/20140110051462_create_spud_pages.tb_cms.rb +20 -0
- data/spec/dummy/db/migrate/20140110051463_create_spud_menus.tb_cms.rb +11 -0
- data/spec/dummy/db/migrate/20140110051464_create_spud_menu_items.tb_cms.rb +18 -0
- data/spec/dummy/db/migrate/20140110051465_create_spud_templates.tb_cms.rb +12 -0
- data/spec/dummy/db/migrate/20140110051466_create_spud_page_partials.tb_cms.rb +14 -0
- data/spec/dummy/db/migrate/20140110051467_add_visibility_to_spud_pages.tb_cms.rb +7 -0
- data/spec/dummy/db/migrate/20140110051468_add_menu_name_to_spud_menu_items.tb_cms.rb +6 -0
- data/spec/dummy/db/migrate/20140110051469_add_use_custom_url_name_to_spud_pages.tb_cms.rb +6 -0
- data/spec/dummy/db/migrate/20140110051470_add_notes_to_spud_pages.tb_cms.rb +6 -0
- data/spec/dummy/db/migrate/20140110051471_add_menu_id_to_spud_menu_items.tb_cms.rb +8 -0
- data/spec/dummy/db/migrate/20140110051472_add_classes_to_spud_menu_items.tb_cms.rb +7 -0
- data/spec/dummy/db/migrate/20140110051473_add_site_id_to_spud_pages.tb_cms.rb +7 -0
- data/spec/dummy/db/migrate/20140110051474_add_site_id_to_spud_templates.tb_cms.rb +7 -0
- data/spec/dummy/db/migrate/20140110051475_add_site_id_to_spud_menus.tb_cms.rb +7 -0
- data/spec/dummy/db/migrate/20140110051476_create_spud_page_partial_revisions.tb_cms.rb +14 -0
- data/spec/dummy/db/migrate/20140110051477_add_symbol_name_to_spud_page_partials.tb_cms.rb +6 -0
- data/spec/dummy/db/migrate/20140110051478_modify_site_id_for_spud_pages.tb_cms.rb +16 -0
- data/spec/dummy/db/migrate/20140110051479_add_content_processed_to_spud_page_partials.tb_cms.rb +6 -0
- data/spec/dummy/db/migrate/20140110051480_add_layout_to_spud_pages.tb_cms.rb +9 -0
- data/spec/dummy/db/migrate/20140110051481_create_spud_page_liquid_tags.tb_cms.rb +12 -0
- data/spec/dummy/db/migrate/20140110051482_create_spud_snippets.tb_cms.rb +18 -0
- data/spec/dummy/db/migrate/20140110051483_change_liquid_tags_to_polymorphic.tb_cms.rb +20 -0
- data/spec/dummy/db/migrate/20140110051484_drop_spud_page_liquid_tags.tb_cms.rb +30 -0
- data/spec/dummy/db/schema.rb +96 -79
- data/spec/helpers/cms/application_helper_spec.rb +11 -9
- data/spec/models/spud_page_partial_spec.rb +3 -3
- data/spec/models/spud_page_spec.rb +3 -4
- metadata +115 -77
- data/app/models/spud_page_liquid_tag.rb +0 -4
- data/app/observers/page_sweeper.rb +0 -48
- data/app/observers/snippet_sweeper.rb +0 -41
- data/spec/dummy/db/migrate/20120307003559_create_spud_permalinks.spud_permalinks.rb +0 -12
- data/spec/dummy/db/migrate/20120610123556_add_scope_to_spud_admin_permissions.spud_core.rb +0 -7
- data/spec/dummy/db/migrate/20120610123615_add_site_id_to_spud_permalinks.spud_permalinks.rb +0 -7
- data/spec/dummy/log/test.log +0 -11310
- data/spec/models/spud_page_liquid_tag_spec.rb +0 -5
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
M2RkYWIzMTlmNGFjMzhjMTRlZTZjNDUxZjcxOTY0OWFlN2U1ZjkzNzhlNGUx
|
10
|
-
M2E0MDczZjZhNzlhNjE0ZjFiMjJiNWIxZGE4MGE1ODU4NDEzMDAwNzk2Nzc4
|
11
|
-
N2ZiN2FkZTUyNjY1Y2RkMGYxOGE0OWViNGVlNjFjMDJlYzQxYzc=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmRlMzdiMDRkNTUzNDBkYmE3ZmNmZjFkMjY1YTg3MGQyZGZiNzg0NTRhZjc0
|
14
|
-
OTM0YTk3YzBlYmMyYzgyNTAzYTkzYzE3MmU0MTkzMDFiNmFmNjI0MDk3N2Nl
|
15
|
-
ZTdlNzhmNTlmZjc1NTk2YmNjZjU4YWM5ZTJiNDUwODBhNTllYTQ=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6efebf0dfac267a54330cb74831bc7a283d46e8
|
4
|
+
data.tar.gz: b3ec8956a99c0c9804af05225f96bf58fdb241a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29c6bf42bdb2c0d4bb05fecfc9c5c4d5572c5a8c257ec980b1389e32472a6f00c54bf9a28a292cdbb1eaa51c834acd2685e3dc5e46465961b1a6faaa4ee986bd
|
7
|
+
data.tar.gz: c901815412d8c43e83ad3a37205808d3367a3ff2f8c37c075b93b9d80893fa672179b5b035446fb0ca46f25367df485a2be784416e83567223cf6fd761c31058
|
data/README.markdown
CHANGED
@@ -20,7 +20,7 @@ class Admin::MenuItemsController < Admin::ApplicationController
|
|
20
20
|
def create
|
21
21
|
|
22
22
|
add_breadcrumb "New", :new_admin_page_path
|
23
|
-
@menu_item = SpudMenuItem.new(
|
23
|
+
@menu_item = SpudMenuItem.new(menu_item_params)
|
24
24
|
@menu_item.spud_menu_id = @menu.id
|
25
25
|
if params[:spud_menu_item][:parent_id].blank?
|
26
26
|
@menu_item.parent_id = @menu.id
|
@@ -61,7 +61,7 @@ class Admin::MenuItemsController < Admin::ApplicationController
|
|
61
61
|
else
|
62
62
|
params[:spud_menu_item][:parent_type] = "SpudMenuItem"
|
63
63
|
end
|
64
|
-
@menu_item.attributes =
|
64
|
+
@menu_item.attributes = menu_item_params()
|
65
65
|
@menu_item.spud_menu_id = @menu.id
|
66
66
|
flash[:notice] = "Menu saved successfully!" if @menu_item.save
|
67
67
|
|
@@ -107,8 +107,8 @@ private
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
def menu_item_params
|
111
|
+
params.require(:spud_menu_item).permit(:name, :parent_type, :parent_id, :item_type, :spud_page_id, :menu_order, :url, :classes)
|
112
|
+
end
|
113
113
|
|
114
114
|
end
|
@@ -17,7 +17,7 @@ class Admin::MenusController < Admin::ApplicationController
|
|
17
17
|
|
18
18
|
def create
|
19
19
|
add_breadcrumb "New", :new_admin_menu_path
|
20
|
-
@menu = SpudMenu.new(
|
20
|
+
@menu = SpudMenu.new(menu_params)
|
21
21
|
@menu.site_id = session[:admin_site]
|
22
22
|
flash[:notice] = "New menu created" if @menu.save
|
23
23
|
respond_with @menu,:location => @menu.id != nil ? admin_menu_menu_items_url(:menu_id => @menu.id) : admin_menus_url
|
@@ -31,7 +31,7 @@ class Admin::MenusController < Admin::ApplicationController
|
|
31
31
|
def update
|
32
32
|
add_breadcrumb "Edit #{@menu.name}", :edit_admin_menu_path
|
33
33
|
|
34
|
-
flash[:notice] = "Menu saved successfully" if @menu.update_attributes(
|
34
|
+
flash[:notice] = "Menu saved successfully" if @menu.update_attributes(menu_params)
|
35
35
|
respond_with @menu,:location => admin_menu_menu_items_url(:menu_id => @menu.id)
|
36
36
|
end
|
37
37
|
|
@@ -41,6 +41,7 @@ class Admin::MenusController < Admin::ApplicationController
|
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
|
+
|
44
45
|
def load_menu
|
45
46
|
@menu = SpudMenu.where(:id => params[:id]).first
|
46
47
|
if @menu.blank?
|
@@ -51,4 +52,9 @@ private
|
|
51
52
|
redirect_to admin_menus_url() and return false
|
52
53
|
end
|
53
54
|
end
|
55
|
+
|
56
|
+
def menu_params
|
57
|
+
params.require(:spud_menu).permit(:name)
|
58
|
+
end
|
59
|
+
|
54
60
|
end
|
@@ -37,8 +37,7 @@ class Admin::PagesController < Admin::ApplicationController
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def create
|
40
|
-
|
41
|
-
@page = SpudPage.new(params[:spud_page])
|
40
|
+
@page = SpudPage.new(page_params)
|
42
41
|
@page.site_id = session[:admin_site]
|
43
42
|
if params[:preview] && params[:preview].to_i == 1
|
44
43
|
preview
|
@@ -69,8 +68,7 @@ class Admin::PagesController < Admin::ApplicationController
|
|
69
68
|
end
|
70
69
|
|
71
70
|
def update
|
72
|
-
|
73
|
-
@page.attributes = params[:spud_page]
|
71
|
+
@page.attributes = page_params
|
74
72
|
if params[:preview] && params[:preview].to_i == 1
|
75
73
|
preview
|
76
74
|
return
|
@@ -142,22 +140,8 @@ class Admin::PagesController < Admin::ApplicationController
|
|
142
140
|
end
|
143
141
|
|
144
142
|
def clear
|
145
|
-
|
146
|
-
|
147
|
-
if Spud::Cms.cache_mode == :full_page
|
148
|
-
if record.url_name == Spud::Cms.root_page_name
|
149
|
-
expire_page root_path
|
150
|
-
else
|
151
|
-
expire_page page_path(:id => record.url_name)
|
152
|
-
end
|
153
|
-
elsif Spud::Cms.cache_mode == :action
|
154
|
-
if record.url_name == Spud::Cms.root_page_name
|
155
|
-
expire_action root_path
|
156
|
-
else
|
157
|
-
expire_action page_path(:id => record.url_name)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
143
|
+
# noop
|
144
|
+
logger.debug("TODO: Clear Caches")
|
161
145
|
redirect_to admin_pages_url
|
162
146
|
end
|
163
147
|
|
@@ -176,6 +160,8 @@ private
|
|
176
160
|
return true
|
177
161
|
end
|
178
162
|
|
179
|
-
|
163
|
+
def page_params
|
164
|
+
params.require(:spud_page).permit(:name, :url_name, :created_by, :updated_by, :layout, :visibility, :spud_page_id, :publish_at, :format, :meta_description, :meta_keywords, :page_order, :spud_page_partials_attributes, :use_custom_url_name, :published, :notes, :spud_page_partials_attributes => [:id,:name, :content, :format])
|
165
|
+
end
|
180
166
|
|
181
167
|
end
|
@@ -4,8 +4,6 @@ class Admin::SnippetsController < Admin::ApplicationController
|
|
4
4
|
|
5
5
|
before_filter :load_snippet, :only => [:show, :edit, :update, :destroy]
|
6
6
|
|
7
|
-
cache_sweeper :snippet_sweeper, :only => [:update,:destroy,:create]
|
8
|
-
|
9
7
|
def index
|
10
8
|
@snippets = SpudSnippet.site(session[:admin_site]).order(:name).paginate :page => params[:page]
|
11
9
|
respond_with @snippets
|
@@ -19,7 +17,7 @@ class Admin::SnippetsController < Admin::ApplicationController
|
|
19
17
|
|
20
18
|
def create
|
21
19
|
add_breadcrumb "New", :new_admin_snippet_url
|
22
|
-
@snippet = SpudSnippet.new(
|
20
|
+
@snippet = SpudSnippet.new(snippet_params)
|
23
21
|
@snippet.site_id = session[:admin_site]
|
24
22
|
|
25
23
|
@snippet.save
|
@@ -35,7 +33,7 @@ class Admin::SnippetsController < Admin::ApplicationController
|
|
35
33
|
|
36
34
|
def update
|
37
35
|
add_breadcrumb "Edit", :edit_admin_snippet_url
|
38
|
-
flash[:notice] = "Snippet saved successfully!" if @snippet.update_attributes(
|
36
|
+
flash[:notice] = "Snippet saved successfully!" if @snippet.update_attributes(snippet_params)
|
39
37
|
respond_with @snippet, :location => admin_snippets_url
|
40
38
|
end
|
41
39
|
|
@@ -56,4 +54,9 @@ private
|
|
56
54
|
redirect_to admin_snippets_url and return false
|
57
55
|
end
|
58
56
|
end
|
57
|
+
|
58
|
+
def snippet_params
|
59
|
+
params.require(:spud_snippet).permit(:content, :content_processed, :format, :name)
|
60
|
+
end
|
61
|
+
|
59
62
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
class Cms::SitemapsController < Spud::ApplicationController
|
2
2
|
respond_to :xml
|
3
|
-
caches_page :show,:expires_in => 1.day
|
4
3
|
def show
|
5
4
|
@pages = SpudPage.published_pages.public.order(:spud_page_id)
|
6
5
|
if Spud::Core.multisite_mode_enabled
|
7
6
|
site_config = Spud::Core.site_config_for_host(request.host_with_port)
|
8
7
|
@pages = @pages.site(!site_config.blank? ? site_config[:site_id] : 0)
|
9
8
|
end
|
10
|
-
@pages = @pages.all
|
11
9
|
respond_with @pages
|
12
10
|
end
|
13
11
|
end
|
@@ -1,16 +1,8 @@
|
|
1
1
|
class PagesController < ApplicationController
|
2
|
-
caches_action :show, :if => Proc.new { |c| Spud::Cms.cache_mode == :action }
|
3
2
|
|
4
3
|
respond_to :html
|
5
|
-
|
6
4
|
before_filter :set_default_content_type
|
7
5
|
|
8
|
-
after_filter({:only => [:show]}) do |c|
|
9
|
-
if Spud::Cms.cache_mode == :full_page && @page && @page.is_private? == false
|
10
|
-
c.cache_page(nil, nil, false)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
6
|
def show
|
15
7
|
# prevents 500 errors if a url like "/home.jpg" is hit
|
16
8
|
if request.format != :html
|
@@ -29,7 +21,7 @@ class PagesController < ApplicationController
|
|
29
21
|
end
|
30
22
|
end
|
31
23
|
|
32
|
-
@page = SpudPage.published_pages.where(:url_name => url_name)
|
24
|
+
@page = SpudPage.published_pages.where(:url_name => url_name)
|
33
25
|
|
34
26
|
# MultiSite Code Block
|
35
27
|
if Spud::Core.multisite_mode_enabled
|
@@ -51,7 +43,6 @@ class PagesController < ApplicationController
|
|
51
43
|
redirect_to @permalink.attachment.url_name == Spud::Cms.root_page_name ? root_url() : page_url(:id => @permalink.attachment.url_name) , :status => :moved_permanently and return
|
52
44
|
end
|
53
45
|
|
54
|
-
|
55
46
|
render_404
|
56
47
|
return
|
57
48
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module Cms::ApplicationHelper
|
2
2
|
MENU_INDEX = {}
|
3
3
|
|
4
|
-
def sp_snippet(name,snippets=nil)
|
4
|
+
def sp_snippet(name, snippets=nil)
|
5
5
|
if name.blank?
|
6
6
|
return ''
|
7
7
|
end
|
8
|
-
|
9
8
|
if !snippets.blank?
|
10
9
|
snippet = snippets.select {|s| s.name == name}
|
11
10
|
else
|
12
11
|
snippet = SpudSnippet.where(:name => name).first
|
13
12
|
end
|
14
|
-
|
15
13
|
if !snippet.blank?
|
16
|
-
|
14
|
+
# cache(snippet) do
|
15
|
+
# concat snippet.content_processed.html_safe
|
16
|
+
# end
|
17
|
+
snippet.content_processed.html_safe
|
17
18
|
else
|
18
19
|
return nil
|
19
20
|
end
|
20
|
-
|
21
21
|
end
|
22
22
|
|
23
23
|
def sp_list_pages(options = {})
|
@@ -31,6 +31,7 @@ module Cms::ApplicationHelper
|
|
31
31
|
start_page = nil
|
32
32
|
max_depth = 0
|
33
33
|
active_class = "menu-active"
|
34
|
+
|
34
35
|
if !options.blank?
|
35
36
|
if options.has_key?(:exclude)
|
36
37
|
|
@@ -55,7 +56,7 @@ module Cms::ApplicationHelper
|
|
55
56
|
content = "<ul>"
|
56
57
|
end
|
57
58
|
|
58
|
-
pages = pages.
|
59
|
+
pages = pages.to_a.group_by(&:spud_page_id)
|
59
60
|
if pages[start_page].blank?
|
60
61
|
|
61
62
|
return ""
|
@@ -80,97 +81,88 @@ module Cms::ApplicationHelper
|
|
80
81
|
return content.html_safe
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
content += sp_list_menu_item(child_items,item.id,2,max_depth,options)
|
166
|
-
end
|
167
|
-
content += "</li>"
|
168
|
-
end
|
169
|
-
|
170
|
-
content += "</ul>"
|
171
|
-
|
172
|
-
return content.html_safe
|
173
|
-
end
|
84
|
+
def sp_list_menu(options = {})
|
85
|
+
|
86
|
+
if !options.has_key?(:name)
|
87
|
+
logger.debug 'sp_list_menu require a :name option'
|
88
|
+
return ''
|
89
|
+
end
|
90
|
+
|
91
|
+
max_depth = 0
|
92
|
+
menu_id = nil
|
93
|
+
link_options = {}
|
94
|
+
start_menu_item = nil
|
95
|
+
|
96
|
+
if Spud::Core.multisite_mode_enabled
|
97
|
+
menu = SpudMenu.where(:name => options[:name], :site_id => current_site_id).first
|
98
|
+
else
|
99
|
+
menu = SpudMenu.where(:name => options[:name]).first
|
100
|
+
end
|
101
|
+
|
102
|
+
if menu.blank?
|
103
|
+
return ''
|
104
|
+
else
|
105
|
+
menu_id = menu.id
|
106
|
+
end
|
107
|
+
|
108
|
+
cache(['sp_list_menu', menu, options]) do
|
109
|
+
link_options = options[:link_options] if options.has_key?(:link_options)
|
110
|
+
|
111
|
+
start_menu_item = options[:start_menu_item_id] if options.has_key?(:start_menu_item_id)
|
112
|
+
if options.has_key?(:id)
|
113
|
+
content = "<ul id='#{options[:id]}' #{"class='#{options[:class]}'" if options.has_key?(:class)}>"
|
114
|
+
else
|
115
|
+
content = "<ul #{"class='#{options[:class]}'" if options.has_key?(:class)}>"
|
116
|
+
end
|
117
|
+
max_depth = options[:max_depth] if options.has_key?(:max_depth)
|
118
|
+
|
119
|
+
menu_items = SpudMenuItem.where(:spud_menu_id => menu_id).select("
|
120
|
+
#{SpudMenuItem.table_name}.id as id,
|
121
|
+
#{SpudMenuItem.table_name}.url as url,
|
122
|
+
#{SpudMenuItem.table_name}.classes as classes,
|
123
|
+
#{SpudMenuItem.table_name}.parent_type as parent_type,
|
124
|
+
#{SpudMenuItem.table_name}.menu_order as menu_order,
|
125
|
+
#{SpudMenuItem.table_name}.parent_id as parent_id,
|
126
|
+
#{SpudMenuItem.table_name}.name as name,
|
127
|
+
#{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
|
128
|
+
|
129
|
+
grouped_items = menu_items.group_by(&:parent_type)
|
130
|
+
|
131
|
+
if grouped_items["SpudMenu"].blank?
|
132
|
+
return ""
|
133
|
+
end
|
134
|
+
|
135
|
+
child_items = grouped_items["SpudMenuItem"].blank? ? [] : grouped_items["SpudMenuItem"].group_by(&:parent_id)
|
136
|
+
|
137
|
+
parent_items = grouped_items["SpudMenu"]
|
138
|
+
if start_menu_item != nil
|
139
|
+
parent_items = child_items[start_menu_item]
|
140
|
+
end
|
141
|
+
|
142
|
+
parent_items.sort_by{|p| p.menu_order}.each do |item|
|
143
|
+
active = false
|
144
|
+
if !item.url_name.blank?
|
145
|
+
if current_page?(page_path(:id => item.url_name))
|
146
|
+
active = true
|
147
|
+
elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path)
|
148
|
+
active = true
|
149
|
+
end
|
150
|
+
elsif current_page?(item.url)
|
151
|
+
active = true
|
152
|
+
end
|
153
|
+
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)
|
154
|
+
content += "<li class='#{"menu-active" if active} #{item.classes if !item.classes.blank?}'>#{link_tag}"
|
155
|
+
if max_depth == 0 || max_depth > 1
|
156
|
+
content += sp_list_menu_item(child_items,item.id,2,max_depth,options)
|
157
|
+
end
|
158
|
+
content += "</li>"
|
159
|
+
end
|
160
|
+
|
161
|
+
content += "</ul>"
|
162
|
+
|
163
|
+
concat content.html_safe
|
164
|
+
end
|
165
|
+
end
|
174
166
|
|
175
167
|
def sp_menu_with_seperator(options={})
|
176
168
|
|
@@ -196,7 +188,7 @@ module Cms::ApplicationHelper
|
|
196
188
|
#{SpudMenuItem.table_name}.menu_order as menu_order,
|
197
189
|
#{SpudMenuItem.table_name}.parent_id as parent_id,
|
198
190
|
#{SpudMenuItem.table_name}.name as name,
|
199
|
-
#{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)").
|
191
|
+
#{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
|
200
192
|
|
201
193
|
menu_tags = []
|
202
194
|
menu_items.sort_by{|p| p.menu_order}.each do |item|
|