tb_cms 0.9.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +110 -0
  4. data/Rakefile +28 -0
  5. data/app/assets/images/spud/admin/menus_thumb.png +0 -0
  6. data/app/assets/images/spud/admin/menus_thumb@2x.png +0 -0
  7. data/app/assets/images/spud/admin/pages_thumb.png +0 -0
  8. data/app/assets/images/spud/admin/snippets_thumb.png +0 -0
  9. data/app/assets/images/spud/admin/snippets_thumb@2x.png +0 -0
  10. data/app/assets/javascripts/spud/admin/cms/application.js +25 -0
  11. data/app/assets/javascripts/spud/admin/cms/menu_items.js +35 -0
  12. data/app/assets/javascripts/spud/admin/cms/pages.js +29 -0
  13. data/app/assets/javascripts/spud/admin/snippets.js +2 -0
  14. data/app/assets/stylesheets/spud/admin/cms/application.css +28 -0
  15. data/app/assets/stylesheets/spud/admin/cms.css +4 -0
  16. data/app/assets/stylesheets/spud/admin/snippets.css +4 -0
  17. data/app/controllers/pages_controller.rb +90 -0
  18. data/app/controllers/spud/admin/cms_controller.rb +3 -0
  19. data/app/controllers/spud/admin/menu_items_controller.rb +115 -0
  20. data/app/controllers/spud/admin/menus_controller.rb +55 -0
  21. data/app/controllers/spud/admin/pages_controller.rb +182 -0
  22. data/app/controllers/spud/admin/snippets_controller.rb +61 -0
  23. data/app/controllers/spud/cms/sitemaps_controller.rb +13 -0
  24. data/app/helpers/spud/cms/application_helper.rb +283 -0
  25. data/app/models/spud_menu.rb +9 -0
  26. data/app/models/spud_menu_item.rb +72 -0
  27. data/app/models/spud_page.rb +131 -0
  28. data/app/models/spud_page_liquid_tag.rb +4 -0
  29. data/app/models/spud_page_partial.rb +67 -0
  30. data/app/models/spud_page_partial_revision.rb +5 -0
  31. data/app/models/spud_snippet.rb +42 -0
  32. data/app/observers/page_sweeper.rb +48 -0
  33. data/app/observers/snippet_sweeper.rb +41 -0
  34. data/app/views/pages/not_found.html.erb +2 -0
  35. data/app/views/pages/show.html.erb +24 -0
  36. data/app/views/spud/admin/menu_items/_form.html.erb +51 -0
  37. data/app/views/spud/admin/menu_items/_menu_item_row.html.erb +22 -0
  38. data/app/views/spud/admin/menu_items/edit.html.erb +10 -0
  39. data/app/views/spud/admin/menu_items/index.html.erb +17 -0
  40. data/app/views/spud/admin/menu_items/new.html.erb +12 -0
  41. data/app/views/spud/admin/menus/_form.html.erb +11 -0
  42. data/app/views/spud/admin/menus/edit.html.erb +13 -0
  43. data/app/views/spud/admin/menus/index.html.erb +24 -0
  44. data/app/views/spud/admin/menus/new.html.erb +7 -0
  45. data/app/views/spud/admin/pages/_form.html.erb +95 -0
  46. data/app/views/spud/admin/pages/_page_partials_form.html.erb +18 -0
  47. data/app/views/spud/admin/pages/_page_row.html.erb +18 -0
  48. data/app/views/spud/admin/pages/edit.html.erb +32 -0
  49. data/app/views/spud/admin/pages/index.html.erb +13 -0
  50. data/app/views/spud/admin/pages/new.html.erb +34 -0
  51. data/app/views/spud/admin/pages/show.html.erb +20 -0
  52. data/app/views/spud/admin/snippets/_form.html.erb +8 -0
  53. data/app/views/spud/admin/snippets/edit.html.erb +7 -0
  54. data/app/views/spud/admin/snippets/index.html.erb +24 -0
  55. data/app/views/spud/admin/snippets/new.html.erb +7 -0
  56. data/app/views/spud/admin/templates/_form.html.erb +43 -0
  57. data/app/views/spud/admin/templates/edit.html.erb +9 -0
  58. data/app/views/spud/admin/templates/index.html.erb +17 -0
  59. data/app/views/spud/admin/templates/new.html.erb +11 -0
  60. data/app/views/spud/cms/sitemaps/show.xml.builder +16 -0
  61. data/config/boot.rb +6 -0
  62. data/config/routes.rb +29 -0
  63. data/db/migrate/20120101192412_create_spud_pages.rb +19 -0
  64. data/db/migrate/20120101193138_create_spud_menus.rb +10 -0
  65. data/db/migrate/20120101193255_create_spud_menu_items.rb +17 -0
  66. data/db/migrate/20120101194124_create_spud_templates.rb +11 -0
  67. data/db/migrate/20120103034659_create_spud_page_partials.rb +13 -0
  68. data/db/migrate/20120104194032_add_visibility_to_spud_pages.rb +6 -0
  69. data/db/migrate/20120107181337_add_menu_name_to_spud_menu_items.rb +5 -0
  70. data/db/migrate/20120111134754_add_use_custom_url_name_to_spud_pages.rb +5 -0
  71. data/db/migrate/20120118141852_add_notes_to_spud_pages.rb +5 -0
  72. data/db/migrate/20120126232428_add_menu_id_to_spud_menu_items.rb +7 -0
  73. data/db/migrate/20120128163601_add_classes_to_spud_menu_items.rb +6 -0
  74. data/db/migrate/20120329132314_add_site_id_to_spud_pages.rb +6 -0
  75. data/db/migrate/20120329132322_add_site_id_to_spud_templates.rb +6 -0
  76. data/db/migrate/20120329132330_add_site_id_to_spud_menus.rb +6 -0
  77. data/db/migrate/20120510195151_create_spud_page_partial_revisions.rb +13 -0
  78. data/db/migrate/20120911190030_add_symbol_name_to_spud_page_partials.rb +5 -0
  79. data/db/migrate/20120912121313_modify_site_id_for_spud_pages.rb +15 -0
  80. data/db/migrate/20121016233715_add_content_processed_to_spud_page_partials.rb +5 -0
  81. data/db/migrate/20121112151110_add_layout_to_spud_pages.rb +8 -0
  82. data/db/migrate/20121112212113_create_spud_page_liquid_tags.rb +11 -0
  83. data/db/migrate/20121119025608_create_spud_snippets.rb +17 -0
  84. data/db/migrate/20121119030136_change_liquid_tags_to_polymorphic.rb +17 -0
  85. data/lib/generators/spud/cms/template_generator.rb +17 -0
  86. data/lib/generators/spud/cms/templates/template.html.erb +28 -0
  87. data/lib/spud_cms/configuration.rb +27 -0
  88. data/lib/spud_cms/engine.rb +69 -0
  89. data/lib/spud_cms/liquid_snippet.rb +29 -0
  90. data/lib/spud_cms/page_route.rb +5 -0
  91. data/lib/spud_cms/template_parser.rb +126 -0
  92. data/lib/spud_cms/test_files.rb +25 -0
  93. data/lib/spud_cms/version.rb +5 -0
  94. data/lib/spud_cms.rb +10 -0
  95. data/lib/tasks/spud_cms_tasks.rake +4 -0
  96. data/spec/controllers/pages_controller_spec.rb +108 -0
  97. data/spec/controllers/spud/admin/cms_controller_spec.rb +11 -0
  98. data/spec/controllers/spud/admin/menu_items_controller_spec.rb +148 -0
  99. data/spec/controllers/spud/admin/menus_controller_spec.rb +121 -0
  100. data/spec/controllers/spud/admin/pages_controller_spec.rb +111 -0
  101. data/spec/controllers/spud/admin/snippets_controller_spec.rb +5 -0
  102. data/spec/controllers/spud/cms/sitemaps_controller_spec.rb +48 -0
  103. data/spec/dummy/README.rdoc +261 -0
  104. data/spec/dummy/Rakefile +7 -0
  105. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  106. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  107. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  108. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  109. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  110. data/spec/dummy/app/views/layouts/content_left.html.erb +0 -0
  111. data/spec/dummy/config/application.rb +59 -0
  112. data/spec/dummy/config/boot.rb +10 -0
  113. data/spec/dummy/config/database.yml +15 -0
  114. data/spec/dummy/config/environment.rb +5 -0
  115. data/spec/dummy/config/environments/development.rb +37 -0
  116. data/spec/dummy/config/environments/production.rb +67 -0
  117. data/spec/dummy/config/environments/test.rb +37 -0
  118. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  119. data/spec/dummy/config/initializers/inflections.rb +15 -0
  120. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  121. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  122. data/spec/dummy/config/initializers/session_store.rb +8 -0
  123. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  124. data/spec/dummy/config/locales/en.yml +5 -0
  125. data/spec/dummy/config/routes.rb +3 -0
  126. data/spec/dummy/config.ru +4 -0
  127. data/spec/dummy/db/migrate/20120307002859_create_spud_admin_permissions.spud_core.rb +12 -0
  128. data/spec/dummy/db/migrate/20120307002860_create_spud_users.spud_core.rb +30 -0
  129. data/spec/dummy/db/migrate/20120307003559_create_spud_permalinks.spud_permalinks.rb +12 -0
  130. data/spec/dummy/db/migrate/20120610123555_add_time_zone_to_spud_user.spud_core.rb +7 -0
  131. data/spec/dummy/db/migrate/20120610123556_add_scope_to_spud_admin_permissions.spud_core.rb +7 -0
  132. data/spec/dummy/db/migrate/20120610123557_create_spud_user_settings.spud_core.rb +12 -0
  133. data/spec/dummy/db/migrate/20120610123615_add_site_id_to_spud_permalinks.spud_permalinks.rb +7 -0
  134. data/spec/dummy/db/schema.rb +171 -0
  135. data/spec/dummy/log/test.log +1874 -0
  136. data/spec/dummy/public/404.html +26 -0
  137. data/spec/dummy/public/422.html +26 -0
  138. data/spec/dummy/public/500.html +25 -0
  139. data/spec/dummy/public/favicon.ico +0 -0
  140. data/spec/dummy/script/rails +6 -0
  141. data/spec/helpers/spud/cms/application_helper_spec.rb +160 -0
  142. data/spec/models/spud_menu_item_spec.rb +31 -0
  143. data/spec/models/spud_page_liquid_tag_spec.rb +5 -0
  144. data/spec/models/spud_page_partial_revision_spec.rb +5 -0
  145. data/spec/models/spud_page_partial_spec.rb +44 -0
  146. data/spec/models/spud_page_spec.rb +163 -0
  147. data/spec/models/spud_snippet_spec.rb +5 -0
  148. data/spec/spec_helper.rb +40 -0
  149. data/spec/support/authlogic_helper.rb +2 -0
  150. metadata +427 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWExNDA4YjAxMmM4MTcwMmFiMmQ0YzFmMjcwNWExNGVkMjM4ZmY5NQ==
5
+ data.tar.gz: !binary |-
6
+ ZjM4NGNmNDYwODE1Y2NkYTg4YzlhNWY5MTFmMjY0NGIzODYzNmE3Zg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDZlZjYwYjdhMWU4NzRiNDkxODk0Zjk1NTFjNWE1ZWI1ODQ4Y2RkZWE2YjI0
10
+ NzlhN2QzNzc3MjY4NzQwZGU5ZDMwYjFhNDJmYTE3NGQzNDZlNzU0MDhkNGQ0
11
+ MjBhYTIyMzAxYWQ4YmUzMWZhYzUyM2IwNjhlZDhhZDYwY2RhNTA=
12
+ data.tar.gz: !binary |-
13
+ Njk0MzdjZjJkNzU5NWU1YTFmZDkwM2IxZjE1YmM5ZTJlZjY1NTJiY2U4MTNk
14
+ ZGVkNWZmNzEwYzhiNzE0OGMxMzdiMTAxOTJhNWIyY2VjMDAzMjExOGIyZmU4
15
+ OGU2NTY1MDA2NzNkZWQzNDg0Y2IwNjIxNWIzYTE1ZWViZGQ0MzA=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,110 @@
1
+ Spud CMS
2
+ ========
3
+
4
+ Spud CMS is a CMS Engine designed to be robust, easy to use, and light weight.
5
+
6
+
7
+ Installation/Usage
8
+ ------------------
9
+
10
+ 1. In your Gemfile add the following
11
+
12
+ gem 'spud_cms'
13
+
14
+ 2. Run bundle install
15
+ 3. Copy in database migrations to your new rails project
16
+
17
+ bundle exec rake railties:install:migrations
18
+ rake db:migrate
19
+ 4. Change ApplicationController to inherit from Spud::ApplicationController instead of ActionController::Base
20
+
21
+ class ApplicationController < Spud::ApplicationController
22
+
23
+ 5. run a rails server instance and point your browser to /spud/admin
24
+
25
+ Routing to the CMS Engine
26
+ --------------------------
27
+ Routing your home page to the CMS engine is fairly straight forward.
28
+ in your applications application.rb file add a configure block as such
29
+
30
+
31
+ Spud::Cms.configure do |config|
32
+ config.menus_enabled = true
33
+ config.root_page_name = "home"
34
+ end
35
+
36
+
37
+
38
+ Where "home" is the page name you wish to use.
39
+
40
+ Pages will default render to the 'application' layout of your application. You can change this by using templates to specify base layouts.
41
+
42
+ Defining Templates / Layouts
43
+ ----------------------------
44
+ Spud CMS has recently changed its template structure. The admin templates area is no longer with us. In Spud CMS templates are defined similar to how an asset pipeline manifest is defined. At the top of your layout files a series of comments can be used to define the name of the template, and the content_for blocks that are editable by the user.
45
+
46
+ Example:
47
+
48
+ <%
49
+ #template_name: 2 Column Page
50
+ #html: Left
51
+ #html: Right
52
+ %>
53
+
54
+ Optionally a description can be passed as well as a `site_name: default` for multisite mode.
55
+
56
+
57
+ Using Liquid Template Engine
58
+ ----------------------------
59
+ Spud CMS utilizes the liquid template syntax engine created by Shopify. This allows you to easily inject variables into your pages in the page editor. Example:
60
+
61
+ <h2>{{page.name}}</h2>
62
+
63
+ Using Menus
64
+ -----------
65
+ A lot of cms engines allow you to render your navigation links in a ul block by using your page tree structure. In a lot of cases this is insufficient as some sites have urls that redirect to pages outside of your cms. This is where menus come in. They can be built in the spud admin control panel.
66
+ In your application layout file or any erb template you can render a ul block like so
67
+
68
+ <%=sp_list_menu({:id => "navigation",:name => "Main"})%>
69
+
70
+ This will output a <ul id="navigation"></ul> block for the menu you created in admin named "Main"
71
+
72
+ Adding Your Own Engines
73
+ -----------------------
74
+
75
+ Creating a rails engine that ties into spud admin is fairly straight forward
76
+ In your new engine add spud_admin as a dependency and create an initializer inside your engine class as such:
77
+
78
+ initializer :admin do
79
+ Spud::Core.configure do |config|
80
+ config.admin_applications += [{:name => "Pages",:thumbnail => "spud/admin/pages_thumb.png",:url => "/spud/admin/pages",:order => 0}]
81
+
82
+ end
83
+ end
84
+
85
+ You can use the layouts provided with spud admin by using 'spud/admin/application' or 'spud/admin/detail' layouts
86
+
87
+ When creating controllers for the admin panel create them in the Spud::Admin Namespace and have them extend Spud::Admin::ApplicationController for automatic user authentication restrictions.
88
+
89
+ Testing
90
+ -----------------
91
+
92
+ Spud uses RSpec for testing. Get the tests running with a few short commands:
93
+
94
+ 1. Create and migrate the databases:
95
+
96
+ rake db:create
97
+ rake db:migrate
98
+
99
+ 2. Load the schema in to the test database:
100
+
101
+ rake app:db:test:prepare
102
+
103
+ 3. Run the tests with RSpec
104
+
105
+ rspec spec
106
+
107
+ After the tests have completed the current code coverage stats is available by opening ```/coverage/index.html``` in a browser.
108
+
109
+
110
+
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SpudCms'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake'
@@ -0,0 +1,25 @@
1
+ //= require_self
2
+ //= require spud/admin/cms/pages
3
+ //= require spud/admin/cms/menu_items
4
+
5
+ spud.admin.cms = {};
6
+
7
+ $(document).ready(function() {
8
+ spud.admin.cms.pages.initFormTabs();
9
+
10
+ $("#spud_page_layout").bind('change', function() {
11
+ var $this = $(this);
12
+ $.get($this.attr("data-source"), { template: $this.val() }, function(data) {
13
+
14
+ spud.admin.editor.unload();
15
+
16
+ $("#page_partials_form").replaceWith(data);
17
+ spud.admin.cms.pages.initFormTabs();
18
+
19
+ spud.admin.editor.init();
20
+
21
+ }, 'text').error(function(jqXHR) {
22
+ alert("Error: " + jqXHR.responseText);
23
+ });
24
+ });
25
+ });
@@ -0,0 +1,35 @@
1
+ spud.admin.cms.menu_items = {};
2
+
3
+ (function() {
4
+ var menu_items = spud.admin.cms.menu_items;
5
+
6
+ menu_items.init = function() {
7
+ return;
8
+ $('.sortable').sortable({
9
+ connectWith:".connectedSortable",
10
+ start: function(event,ui) {
11
+ $('#root_menu_list').addClass('menu_edit');
12
+ },
13
+ axis:"y",
14
+ tolerance:'pointer',
15
+ cursor: "move",
16
+ items:'li',
17
+ stop: function(event,ui) {
18
+ $('#root_menu_list').removeClass('menu_edit');
19
+ },
20
+ over: function(event,ui) {
21
+
22
+ var source = ui.item[0];
23
+
24
+ var destination = $(event.target);
25
+ $('ul.left_guide').removeClass('left_guide');
26
+
27
+ if(destination.hasClass('subitem'))
28
+ {
29
+ destination.addClass('left_guide');
30
+ }
31
+ }
32
+ }).disableSelection();
33
+ };
34
+
35
+ })();
@@ -0,0 +1,29 @@
1
+ spud.admin.cms.pages = {};
2
+
3
+ (function(){
4
+ var pages = spud.admin.cms.pages;
5
+
6
+
7
+ pages.initFormTabs = function(){
8
+ var tabNames = [];
9
+
10
+ $('.formtabs .formtab').each(function(tabind) {
11
+ if(tabind === 0) {
12
+ $(this).addClass('active');
13
+ }
14
+ this.id = 'tab-' + tabind;
15
+ tabNames.push($('.tab_name',this).first().val());
16
+ });
17
+
18
+ var tabButtons = $('.formtabs .formtab_buttons').first();
19
+ for(var x=0;x<tabNames.length;x++)
20
+ {
21
+ var tabButton = $('<li><a href="#tab-' + x + '" data-toggle="tab">' + tabNames[x] + '</a></li>');
22
+ if(x === 0) {
23
+ tabButton.addClass('active');
24
+ }
25
+ tabButtons.append(tabButton);
26
+ }
27
+
28
+ };
29
+ })();
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,28 @@
1
+ /*
2
+ //= require codemirror
3
+ //= require codemirror/themes/night
4
+ */
5
+ .menu_list {
6
+ list-style-type:none;
7
+ }
8
+ .page_row {
9
+ background:white;
10
+ }
11
+ .menu_edit .subitem {
12
+
13
+ min-height:10px;
14
+ /*padding-bottom:12px;*/
15
+ }
16
+
17
+ .subitem .page_row {
18
+
19
+ border-left:2px solid #999;
20
+ }
21
+ .left_guide.subitem .page_row {
22
+ border:none;
23
+ }
24
+
25
+ .ui-sortable-placeholder {
26
+ background:#FAE7D9 !important;
27
+ visibility:visible !important;
28
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,90 @@
1
+ class PagesController < ApplicationController
2
+ caches_action :show, :if => Proc.new { |c| Spud::Cms.cache_mode == :action }
3
+
4
+ respond_to :html
5
+
6
+ before_filter :set_default_content_type
7
+
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
+ def show
15
+ # prevents 500 errors if a url like "/home.jpg" is hit
16
+ if request.format != :html
17
+ render_404
18
+ return
19
+ end
20
+
21
+ url_name = !params[:id].blank? ? params[:id] : Spud::Cms.root_page_name
22
+
23
+ # MultiSite Code Block
24
+ if params[:id].blank? && Spud::Core.multisite_mode_enabled
25
+ site_config = Spud::Core.site_config_for_host(request.host_with_port)
26
+ if !site_config.blank?
27
+ cms_config = Spud::Cms.site_config_for_short_name(site_config[:short_name])
28
+ url_name = cms_config[:root_page_name] if !cms_config.blank? && !cms_config[:root_page_name].blank?
29
+ end
30
+ end
31
+
32
+ @page = SpudPage.published_pages.where(:url_name => url_name).includes([:spud_page_partials])
33
+
34
+ # MultiSite Code Block
35
+ if Spud::Core.multisite_mode_enabled
36
+ site_config = Spud::Core.site_config_for_host(request.host_with_port)
37
+ @page = @page.site(!site_config.blank? ? site_config[:site_id] : nil)
38
+ end
39
+
40
+ @page = @page.first
41
+ if @page.blank?
42
+ @permalink = SpudPermalink.where(:url_name => url_name)
43
+
44
+ # MultiSite Code Block
45
+ if Spud::Core.multisite_mode_enabled
46
+ @permalink = @permalink.site(!site_config.blank? ? site_config[:site_id] : nil)
47
+ end
48
+ @permalink = @permalink.first
49
+
50
+ if !@permalink.blank? && @permalink.attachment_type == 'SpudPage'
51
+ 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
+ end
53
+
54
+
55
+ render_404
56
+ return
57
+ end
58
+
59
+ if @page.is_private?
60
+ return if defined?(require_user) && require_user == false
61
+ end
62
+
63
+ layout = Spud::Cms.default_page_layout
64
+
65
+ # MultiSite Code Block
66
+ if Spud::Core.multisite_mode_enabled && !site_config.blank?
67
+ cms_config = Spud::Cms.site_config_for_short_name(site_config[:short_name])
68
+ layout = cms_config[:default_page_layout] if !cms_config.blank? && !cms_config[:default_page_layout].blank?
69
+ end
70
+
71
+ layout = @page.layout || layout
72
+
73
+
74
+ render :layout => layout
75
+
76
+ end
77
+
78
+ private
79
+
80
+ def render_404
81
+ Spud::Cms.template_404 ? render(Spud::Cms.template_404,:status => 404, :formats => [:html]) : render(:text=>nil,:status => 404)
82
+ end
83
+
84
+ def set_default_content_type
85
+ if params[:format].blank?
86
+ request.format = :html
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,3 @@
1
+ class Spud::Admin::CmsController < Spud::Admin::ApplicationController
2
+
3
+ end
@@ -0,0 +1,115 @@
1
+ class Spud::Admin::MenuItemsController < Spud::Admin::CmsController
2
+ add_breadcrumb "Menus", :spud_admin_menus_path
3
+ belongs_to_spud_app :menus, :page_title => "Menu Items"
4
+ layout 'spud/admin/detail'
5
+ before_filter :load_menu
6
+ before_filter :load_menu_item, :only => [:edit,:update,:show,:destroy,:reorder]
7
+
8
+
9
+ def index
10
+ @menu_items = @menu.spud_menu_items.order(:menu_order).includes(:spud_menu_items)
11
+ respond_with @menu_items
12
+ end
13
+
14
+ def new
15
+ add_breadcrumb "New", :new_spud_admin_page_path
16
+
17
+ @menu_item = @menu.spud_menu_items.new
18
+ respond_with @menu_item
19
+ end
20
+
21
+ def create
22
+
23
+ add_breadcrumb "New", :new_spud_admin_page_path
24
+ @menu_item = SpudMenuItem.new(params[:spud_menu_item])
25
+ @menu_item.spud_menu_id = @menu.id
26
+ if params[:spud_menu_item][:parent_id].blank?
27
+ @menu_item.parent_id = @menu.id
28
+ @menu_item.parent_type = "SpudMenu"
29
+ else
30
+ @menu_item.parent_type = "SpudMenuItem"
31
+ end
32
+ if @menu_item.name.blank? && !@menu_item.spud_page.blank?
33
+ @menu_item.name = @menu_item.spud_page.name
34
+ end
35
+ if @menu_item.menu_order.blank?
36
+ highest_sibling = @menu_item.parent.spud_menu_items.order("menu_order desc").first
37
+ if !highest_sibling.blank?
38
+ @menu_item.menu_order = highest_sibling.menu_order + 1
39
+ end
40
+ end
41
+ flash[:notice] = "Menu Created successfully!" if @menu_item.save
42
+
43
+
44
+
45
+ respond_with @menu_item,:location => spud_admin_menu_menu_items_url
46
+ end
47
+
48
+ def edit
49
+ add_breadcrumb "Edit #{@menu_item.name}", :edit_spud_admin_menu_menu_item_path
50
+ if @menu_item.parent_type == "SpudMenu"
51
+ @menu_item.parent_id = nil
52
+ end
53
+ respond_with @menu_item
54
+ end
55
+
56
+ def update
57
+
58
+ add_breadcrumb "Edit #{@menu_item.name}", :edit_spud_admin_menu_menu_item_path
59
+ if params[:spud_menu_item][:parent_id].blank?
60
+ params[:spud_menu_item][:parent_type] = "SpudMenu"
61
+ params[:spud_menu_item][:parent_id] = @menu.id
62
+ else
63
+ params[:spud_menu_item][:parent_type] = "SpudMenuItem"
64
+ end
65
+ @menu_item.attributes = params[:spud_menu_item]
66
+ @menu_item.spud_menu_id = @menu.id
67
+ flash[:notice] = "Menu saved successfully!" if @menu_item.save
68
+
69
+ respond_with @menu_item,:location => spud_admin_menu_menu_items_url
70
+ end
71
+
72
+ def destroy
73
+
74
+ flash[:notice] = "Menu Item removed!" if @menu_item.destroy
75
+
76
+ respond_with @menu_item,:location => spud_admin_menu_menu_items_url
77
+ end
78
+
79
+ def reorder
80
+ #id param
81
+ #source position
82
+ #destination position
83
+ #parent
84
+ # @menu_items = @menu.spud_menu_items.order(:menu_order).includes(:spud_menu_items).paginate :page => params[:page]
85
+
86
+
87
+ end
88
+ private
89
+ def load_menu
90
+
91
+ @menu = SpudMenu.where(:id => params[:menu_id]).first
92
+
93
+ if @menu.blank?
94
+ flash[:error] = "Menu not found!"
95
+ redirect_to spud_admin_menus_url() and return false
96
+ elsif Spud::Core.multisite_mode_enabled && @menu.site_id != session[:admin_site]
97
+ flash[:warning] = "Site Context Changed. The menu you were viewing is not associated with the current site. Redirected back to menu selections."
98
+ redirect_to spud_admin_menus_url() and return false
99
+ end
100
+ add_breadcrumb "#{@menu.name}", :spud_admin_menu_menu_items_path
101
+ end
102
+
103
+ def load_menu_item
104
+ @menu_item = SpudMenuItem.where(:id =>params[:id]).first
105
+ if @menu_item.blank?
106
+ flash[:error] = "Menu Item not found!"
107
+ redirect_to spud_admin_menu_menu_items_url() and return false
108
+ end
109
+ end
110
+
111
+
112
+
113
+
114
+
115
+ end
@@ -0,0 +1,55 @@
1
+ class Spud::Admin::MenusController < Spud::Admin::CmsController
2
+ layout 'spud/admin/detail'
3
+ belongs_to_spud_app :menus
4
+ add_breadcrumb "Menus", :spud_admin_menus_path
5
+ before_filter :load_menu,:only => [:edit,:update,:show,:destroy]
6
+
7
+ def index
8
+ @menus = SpudMenu.site(session[:admin_site]).order(:name).paginate :page => params[:page]
9
+ respond_with @menus
10
+ end
11
+
12
+
13
+ def new
14
+ add_breadcrumb "New", :new_spud_admin_menu_path
15
+ @menu = SpudMenu.new
16
+ respond_with @menu
17
+ end
18
+
19
+ def create
20
+ add_breadcrumb "New", :new_spud_admin_menu_path
21
+ @menu = SpudMenu.new(params[:spud_menu])
22
+ @menu.site_id = session[:admin_site]
23
+ flash[:notice] = "New menu created" if @menu.save
24
+ respond_with @menu,:location => @menu.id != nil ? spud_admin_menu_menu_items_url(:menu_id => @menu.id) : spud_admin_menus_url
25
+ end
26
+
27
+ def edit
28
+ add_breadcrumb "Edit #{@menu.name}", :edit_spud_admin_menu_path
29
+ respond_with @menu
30
+ end
31
+
32
+ def update
33
+ add_breadcrumb "Edit #{@menu.name}", :edit_spud_admin_menu_path
34
+
35
+ flash[:notice] = "Menu saved successfully" if @menu.update_attributes(params[:spud_menu])
36
+ respond_with @menu,:location => spud_admin_menu_menu_items_url(:menu_id => @menu.id)
37
+ end
38
+
39
+ def destroy
40
+ flash[:notice] = "Menu removed!" if @menu.destroy
41
+ respond_with @menu,:location => spud_admin_menus_url
42
+ end
43
+
44
+ private
45
+ def load_menu
46
+ @menu = SpudMenu.where(:id => params[:id]).first
47
+ if @menu.blank?
48
+ flash[:error] = "Menu not found!"
49
+ redirect_to spud_admin_menus_url() and return false
50
+ elsif Spud::Core.multisite_mode_enabled && @menu.site_id != session[:admin_site]
51
+ flash[:warning] = "Site Context Changed. The menu you were viewing is not associated with the current site. Redirected back to menu selections."
52
+ redirect_to spud_admin_menus_url() and return false
53
+ end
54
+ end
55
+ end