comfortable_mexican_sofa 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.rdoc +2 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +55 -0
  5. data/Rakefile +88 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/cms_admin/attachments_controller.rb +55 -0
  8. data/app/controllers/cms_admin/base_controller.rb +25 -0
  9. data/app/controllers/cms_admin/categories_controller.rb +69 -0
  10. data/app/controllers/cms_admin/layouts_controller.rb +71 -0
  11. data/app/controllers/cms_admin/pages_controller.rb +79 -0
  12. data/app/controllers/cms_admin/sections_controller.rb +17 -0
  13. data/app/controllers/cms_admin/snippets_controller.rb +58 -0
  14. data/app/controllers/cms_common/render_page.rb +47 -0
  15. data/app/controllers/cms_content_controller.rb +30 -0
  16. data/app/helpers/cms_helper.rb +12 -0
  17. data/app/models/cms_attachment.rb +17 -0
  18. data/app/models/cms_attachment_categorization.rb +5 -0
  19. data/app/models/cms_block.rb +15 -0
  20. data/app/models/cms_category.rb +36 -0
  21. data/app/models/cms_layout.rb +102 -0
  22. data/app/models/cms_page.rb +125 -0
  23. data/app/models/cms_page_categorization.rb +6 -0
  24. data/app/models/cms_snippet.rb +15 -0
  25. data/app/views/cms_admin/attachments/_details.html.haml +27 -0
  26. data/app/views/cms_admin/attachments/_form.html.haml +24 -0
  27. data/app/views/cms_admin/attachments/edit.html.haml +10 -0
  28. data/app/views/cms_admin/attachments/index.html.haml +36 -0
  29. data/app/views/cms_admin/attachments/new.html.haml +8 -0
  30. data/app/views/cms_admin/categories/_category.html.haml +21 -0
  31. data/app/views/cms_admin/categories/_category_subform.html.haml +12 -0
  32. data/app/views/cms_admin/categories/_form.html.haml +18 -0
  33. data/app/views/cms_admin/categories/_new.html.haml +7 -0
  34. data/app/views/cms_admin/categories/_toggle_link.html.haml +9 -0
  35. data/app/views/cms_admin/categories/_tree_branch.html.haml +36 -0
  36. data/app/views/cms_admin/categories/children.js.rjs +10 -0
  37. data/app/views/cms_admin/categories/create.js.rjs +9 -0
  38. data/app/views/cms_admin/categories/edit.html.haml +10 -0
  39. data/app/views/cms_admin/categories/index.html.haml +7 -0
  40. data/app/views/cms_admin/categories/new.html.haml +8 -0
  41. data/app/views/cms_admin/categories/show.html.haml +17 -0
  42. data/app/views/cms_admin/layouts/_details.html.haml +6 -0
  43. data/app/views/cms_admin/layouts/_form.html.haml +19 -0
  44. data/app/views/cms_admin/layouts/_toggle_link.html.haml +9 -0
  45. data/app/views/cms_admin/layouts/_tree_branch.html.haml +39 -0
  46. data/app/views/cms_admin/layouts/children.js.rjs +10 -0
  47. data/app/views/cms_admin/layouts/edit.html.haml +10 -0
  48. data/app/views/cms_admin/layouts/index.html.haml +7 -0
  49. data/app/views/cms_admin/layouts/new.html.haml +8 -0
  50. data/app/views/cms_admin/pages/_details.html.haml +25 -0
  51. data/app/views/cms_admin/pages/_form.html.haml +45 -0
  52. data/app/views/cms_admin/pages/_form_blocks.html.haml +48 -0
  53. data/app/views/cms_admin/pages/_toggle_link.html.haml +10 -0
  54. data/app/views/cms_admin/pages/_tree_branch.html.haml +41 -0
  55. data/app/views/cms_admin/pages/children.js.rjs +10 -0
  56. data/app/views/cms_admin/pages/edit.html.haml +11 -0
  57. data/app/views/cms_admin/pages/form_blocks.js.rjs +1 -0
  58. data/app/views/cms_admin/pages/index.html.haml +6 -0
  59. data/app/views/cms_admin/pages/new.html.haml +9 -0
  60. data/app/views/cms_admin/sections/show.html.haml +23 -0
  61. data/app/views/cms_admin/snippets/_form.html.haml +10 -0
  62. data/app/views/cms_admin/snippets/edit.html.haml +10 -0
  63. data/app/views/cms_admin/snippets/index.html.haml +26 -0
  64. data/app/views/cms_admin/snippets/new.html.haml +8 -0
  65. data/app/views/cms_content/show.xml.rxml +27 -0
  66. data/app/views/cms_content/sitemap.xml.rxml +16 -0
  67. data/app/views/layouts/cms_admin.html.haml +44 -0
  68. data/comfortable_mexican_sofa.gemspec +254 -0
  69. data/config/cms_routes.rb +25 -0
  70. data/generators/cms/cms_generator.rb +55 -0
  71. data/generators/cms/templates/README +32 -0
  72. data/generators/cms/templates/images/arrow_bottom.gif +0 -0
  73. data/generators/cms/templates/images/arrow_right.gif +0 -0
  74. data/generators/cms/templates/images/icon_attachment.gif +0 -0
  75. data/generators/cms/templates/images/icon_category.gif +0 -0
  76. data/generators/cms/templates/images/icon_draft.gif +0 -0
  77. data/generators/cms/templates/images/icon_layout.gif +0 -0
  78. data/generators/cms/templates/images/icon_move.gif +0 -0
  79. data/generators/cms/templates/images/icon_regular.gif +0 -0
  80. data/generators/cms/templates/images/icon_snippet.gif +0 -0
  81. data/generators/cms/templates/images/logo.png +0 -0
  82. data/generators/cms/templates/initializers/cms.rb +14 -0
  83. data/generators/cms/templates/initializers/paperclip.rb +14 -0
  84. data/generators/cms/templates/javascripts/codemirror_init.js +16 -0
  85. data/generators/cms/templates/javascripts/mce_init.js +17 -0
  86. data/generators/cms/templates/javascripts/utilities.js +27 -0
  87. data/generators/cms/templates/migrations/create_cms.rb +113 -0
  88. data/generators/cms/templates/stylesheets/cms_master.sass +414 -0
  89. data/init.rb +1 -0
  90. data/lib/comfortable_mexican_sofa.rb +46 -0
  91. data/lib/comfortable_mexican_sofa/acts_as_categorized.rb +87 -0
  92. data/lib/comfortable_mexican_sofa/acts_as_published.rb +60 -0
  93. data/lib/comfortable_mexican_sofa/cms_acts_as_tree.rb +108 -0
  94. data/lib/comfortable_mexican_sofa/cms_rails_extensions.rb +12 -0
  95. data/lib/comfortable_mexican_sofa/cms_tag.rb +109 -0
  96. data/lib/comfortable_mexican_sofa/cms_tags/attachment.rb +3 -0
  97. data/lib/comfortable_mexican_sofa/cms_tags/block.rb +117 -0
  98. data/lib/comfortable_mexican_sofa/cms_tags/helper.rb +3 -0
  99. data/lib/comfortable_mexican_sofa/cms_tags/page_block.rb +119 -0
  100. data/lib/comfortable_mexican_sofa/cms_tags/partial.rb +19 -0
  101. data/lib/comfortable_mexican_sofa/cms_tags/snippet.rb +19 -0
  102. data/rails/init.rb +1 -0
  103. data/test/fixtures/cms_attachment_categorizations.yml +7 -0
  104. data/test/fixtures/cms_attachments.yml +6 -0
  105. data/test/fixtures/cms_blocks.yml +38 -0
  106. data/test/fixtures/cms_categories.yml +19 -0
  107. data/test/fixtures/cms_layouts.yml +41 -0
  108. data/test/fixtures/cms_page_categorizations.yml +15 -0
  109. data/test/fixtures/cms_pages.yml +38 -0
  110. data/test/fixtures/cms_snippets.yml +7 -0
  111. data/test/fixtures/files/upload_file.txt +1 -0
  112. data/test/functional/cms_admin/attachments_controller_test.rb +63 -0
  113. data/test/functional/cms_admin/categories_controller_test.rb +86 -0
  114. data/test/functional/cms_admin/layouts_controller_test.rb +77 -0
  115. data/test/functional/cms_admin/pages_controller_test.rb +153 -0
  116. data/test/functional/cms_admin/sections_controller_test.rb +9 -0
  117. data/test/functional/cms_admin/snippets_controller_test.rb +63 -0
  118. data/test/functional/cms_content_controller_test.rb +52 -0
  119. data/test/models/cms_attachment_test.rb +16 -0
  120. data/test/models/cms_block_test.rb +11 -0
  121. data/test/models/cms_categorization_test.rb +39 -0
  122. data/test/models/cms_category_test.rb +71 -0
  123. data/test/models/cms_layout_test.rb +44 -0
  124. data/test/models/cms_page_test.rb +55 -0
  125. data/test/models/cms_snippet_test.rb +16 -0
  126. data/test/models/cms_tag_test.rb +70 -0
  127. data/test/rails_root/README +243 -0
  128. data/test/rails_root/Rakefile +10 -0
  129. data/test/rails_root/app/controllers/application_controller.rb +10 -0
  130. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  131. data/test/rails_root/app/views/cms/under-development.html.haml +1 -0
  132. data/test/rails_root/app/views/complex_page/_example.html.erb +1 -0
  133. data/test/rails_root/config/boot.rb +110 -0
  134. data/test/rails_root/config/database.yml +22 -0
  135. data/test/rails_root/config/environment.rb +48 -0
  136. data/test/rails_root/config/environments/development.rb +17 -0
  137. data/test/rails_root/config/environments/production.rb +28 -0
  138. data/test/rails_root/config/environments/test.rb +28 -0
  139. data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  140. data/test/rails_root/config/initializers/inflections.rb +10 -0
  141. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  142. data/test/rails_root/config/initializers/new_rails_defaults.rb +19 -0
  143. data/test/rails_root/config/initializers/session_store.rb +15 -0
  144. data/test/rails_root/config/locales/en.yml +5 -0
  145. data/test/rails_root/config/routes.rb +43 -0
  146. data/test/rails_root/doc/README_FOR_APP +2 -0
  147. data/test/rails_root/public/404.html +30 -0
  148. data/test/rails_root/public/422.html +30 -0
  149. data/test/rails_root/public/500.html +30 -0
  150. data/test/rails_root/public/favicon.ico +0 -0
  151. data/test/rails_root/public/images/rails.png +0 -0
  152. data/test/rails_root/public/index.html +275 -0
  153. data/test/rails_root/public/javascripts/application.js +2 -0
  154. data/test/rails_root/public/javascripts/controls.js +963 -0
  155. data/test/rails_root/public/javascripts/dragdrop.js +973 -0
  156. data/test/rails_root/public/javascripts/effects.js +1128 -0
  157. data/test/rails_root/public/javascripts/prototype.js +4320 -0
  158. data/test/rails_root/public/robots.txt +5 -0
  159. data/test/rails_root/public/stylesheets/sass/cms_master.sass +414 -0
  160. data/test/rails_root/script/about +4 -0
  161. data/test/rails_root/script/console +3 -0
  162. data/test/rails_root/script/dbconsole +3 -0
  163. data/test/rails_root/script/destroy +3 -0
  164. data/test/rails_root/script/generate +3 -0
  165. data/test/rails_root/script/performance/benchmarker +3 -0
  166. data/test/rails_root/script/performance/profiler +3 -0
  167. data/test/rails_root/script/plugin +3 -0
  168. data/test/rails_root/script/runner +3 -0
  169. data/test/rails_root/script/server +3 -0
  170. data/test/test_helper.rb +17 -0
  171. metadata +303 -0
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ pkg
3
+ rdoc
4
+ test/rails_root/db
5
+ test/rails_root/log
6
+ test/rails_root/vendor
7
+ test/rails_root/config/initializers/paperclip.rb
8
+ test/rails_root/public/javascripts/cms_mce_init.js
9
+ test/rails_root/public/javascripts/cms_codemirror_init.js
10
+ test/rails_root/public/javascripts/cms_utilities.js
@@ -0,0 +1,2 @@
1
+ == 0.0.15
2
+ * First release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Oleg Khabarov and The Working Group
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.
@@ -0,0 +1,55 @@
1
+ = Comfortable Mexican Sofa
2
+
3
+ ComfortableMexicanSofa is a CMS engine that provides CMS functionality to any Rails app.
4
+ It is not intended for users that would put <% ActiveRecord::Base.connection.execute('DROP DATABASE;') %> as content of a page.
5
+
6
+ == Install
7
+
8
+ From local gem:
9
+ rake manifest && rake install
10
+
11
+ In your Rails project:
12
+ # config/envionment.rb
13
+ config.gem 'comfortable_mexican_sofa'
14
+
15
+ Run the follwing in your console to generate migrations and update your database:
16
+ script/generate cms
17
+ rake db:migrate
18
+
19
+ Navigate to the following address to access CMS admin page:
20
+ http://your_application/cms-admin
21
+
22
+ == Sample CMS Configuration
23
+
24
+ ComfortableMexicanSofa.config do |config|
25
+ config.http_auth_username = 'username'
26
+ config.http_auth_password = 'secret_password'
27
+ end
28
+
29
+ == Setting Up Layouts and Writing CMS Content
30
+
31
+ Here's some available type of tags that allow construction and insertion of page content:
32
+
33
+ cms_page_block - block that gets rendered in the actual content of the page
34
+ cms_block - block that is not automatically rendered
35
+ cms_snippet - it's a snippet
36
+ cms_helper - it's a helper method of some sort
37
+ cms_partial - sometimes all we need is a partial
38
+
39
+ Here are the different formats for page blocks and what they will generate in the CMS page editing form:
40
+
41
+ string - a single-line text input
42
+ text - a textarea
43
+ rich_text - if TinyMCE is installed in the app, this will generate a TinyMCE enhanced textarea
44
+ code - if CodeMirror is installed in the app, this will generate a CodeMirror editor with syntax highlighting for HTML, JavaScript and CSS
45
+
46
+ == Installing CodeMirror Support
47
+
48
+ Download CodeMirror from: http://marijn.haverbeke.nl/codemirror
49
+
50
+ To get CodeMirror support properly working, you need to place the CodeMirror files in specific folders in your app. The JavaScript initializer expects the CodeMirror .js files to be at /publib/javascripts/codemirrror/ and the CSS files at /public/stylesheets/codemirror/.
51
+
52
+ To properly generate the .sass files, use the following command:
53
+
54
+ css2sass -a file.css > file.sass
55
+
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = 'comfortable_mexican_sofa'
9
+ gem.summary = 'ComfortableMexicanSofa is a Rails Engine CMS gem'
10
+ gem.description = ''
11
+ gem.email = "oleg@theworkinggroup.ca"
12
+ gem.homepage = "http://theworkinggroup.ca"
13
+ gem.authors = ["Oleg Khabarov, The Working Group Inc"]
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ gem.rubyforge_project = 'cms-sofa'
16
+ gem.add_dependency('haml')
17
+ gem.add_dependency('will_paginate')
18
+ gem.add_dependency('paperclip')
19
+ gem.add_dependency('calendar_date_select')
20
+ gem.add_dependency('active_link_to')
21
+ end
22
+
23
+ Jeweler::RubyforgeTasks.new do |rubyforge|
24
+ rubyforge.doc_task = "rdoc"
25
+ end
26
+
27
+ Jeweler::GemcutterTasks.new
28
+ rescue LoadError
29
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
30
+ end
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ namespace :generator do
40
+ desc "Cleans up test application"
41
+ task :cleanup do
42
+ files = [
43
+ 'test/rails_root/vendor/plugins/comfortable_mexican_sofa',
44
+ 'test/rails_root/db',
45
+ 'test/rails_root/public/javascripts/cms',
46
+ 'test/rails_root/public/images/cms',
47
+ 'test/rails_root/tmp/',
48
+ 'test/rails_root/public/blank_iframe.html',
49
+ 'test/rails_root/public/images/calendar_date_select',
50
+ 'test/rails_root/public/javascripts/calendar_date_select/',
51
+ 'test/rails_root/public/stylesheets/calendar_date_select/',
52
+ 'test/rails_root/public/stylesheets/cms_master.css',
53
+ 'test/rails_root/config/initializers/cms.rb',
54
+ 'test/rails_root/public/system/files/'
55
+ ]
56
+ files.each do |file|
57
+ FileUtils.rm_rf(file)
58
+ end
59
+ end
60
+
61
+ desc "Run the generator on the tests"
62
+ task :prepare do
63
+ plugin_root = File.expand_path(File.dirname(__FILE__))
64
+ system("ln -s #{plugin_root} test/rails_root/vendor/plugins/comfortable_mexican_sofa")
65
+ system "cd test/rails_root && ./script/generate cms && rake db:migrate db:test:prepare"
66
+ end
67
+ end
68
+
69
+ desc "Run the test suite"
70
+ task :default => ['generator:cleanup', 'generator:prepare', :test]
71
+ task :test => :check_dependencies
72
+ task :gemspec => ['generator:cleanup']
73
+
74
+ require 'rake/rdoctask'
75
+ Rake::RDocTask.new do |rdoc|
76
+ if File.exist?('VERSION')
77
+ version = File.read('VERSION')
78
+ else
79
+ version = ""
80
+ end
81
+
82
+ rdoc.rdoc_dir = 'rdoc'
83
+ rdoc.title = "active_link_to #{version}"
84
+ rdoc.rdoc_files.include('README*')
85
+ rdoc.rdoc_files.include('lib/**/*.rb')
86
+ end
87
+
88
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.18
@@ -0,0 +1,55 @@
1
+ class CmsAdmin::AttachmentsController < CmsAdmin::BaseController
2
+
3
+ before_filter :load_attachment, :only => [:edit, :update, :destroy]
4
+
5
+ def index
6
+ @category_id = params[:filter][:category_id] rescue nil
7
+ unless @category_id.blank?
8
+ @cms_attachments = CmsAttachment.in_category(@category_id).paginate(:page => params[:page])
9
+ else
10
+ @cms_attachments = CmsAttachment.paginate(:page => params[:page])
11
+ end
12
+ end
13
+
14
+ def new
15
+ @cms_attachment = CmsAttachment.new
16
+ end
17
+
18
+ def edit
19
+ end
20
+
21
+ def create
22
+ @cms_attachment = CmsAttachment.new(params[:cms_attachment])
23
+ @cms_attachment.save!
24
+
25
+ flash[:notice] = 'Attachment created'
26
+ redirect_to :action => :edit, :id => @cms_attachment
27
+
28
+ rescue ActiveRecord::RecordInvalid
29
+ render :action => :new
30
+ end
31
+
32
+ def update
33
+ @cms_attachment.update_attributes!(params[:cms_attachment])
34
+
35
+ flash[:notice] = 'Attachment updated'
36
+ redirect_to :action => :edit, :id => @cms_attachment
37
+
38
+ rescue ActiveRecord::RecordInvalid
39
+ render :action => :edit
40
+ end
41
+
42
+ def destroy
43
+ @cms_attachment.destroy
44
+
45
+ flash[:notice] = 'Attachment removed'
46
+ redirect_to :action => :index
47
+ end
48
+
49
+ protected
50
+
51
+ def load_attachment
52
+ @cms_attachment = CmsAttachment.find_by_id(params[:id])
53
+ end
54
+
55
+ end
@@ -0,0 +1,25 @@
1
+ class CmsAdmin::BaseController < ApplicationController
2
+
3
+ before_filter :authenticate
4
+
5
+ layout 'cms_admin'
6
+
7
+ def manage_session_array(name, action, value)
8
+ session[name] = case action
9
+ when :add
10
+ (session[name] || []) + [value]
11
+ when :remove
12
+ (session[name] || []) - [value]
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def authenticate
19
+ authenticate_or_request_with_http_basic do |username, password|
20
+ username == ComfortableMexicanSofa::Config.http_auth_username &&
21
+ password == ComfortableMexicanSofa::Config.http_auth_password
22
+ end if ComfortableMexicanSofa::Config.http_auth_enabled
23
+ end
24
+
25
+ end
@@ -0,0 +1,69 @@
1
+ class CmsAdmin::CategoriesController < CmsAdmin::BaseController
2
+ before_filter :load_category, :except => [:create, :new, :index]
3
+
4
+ def index
5
+ @cms_categories = CmsCategory.roots
6
+ end
7
+
8
+ def children
9
+ manage_session_array(:cms_category_tree, (params[:state] == 'open' ? :remove : :add), params[:id])
10
+ end
11
+
12
+ def new
13
+ @cms_category = CmsCategory.new(params.slice(:parent_id))
14
+ end
15
+
16
+ def create
17
+ @cms_category = CmsCategory.new(params[:cms_category])
18
+ @cms_category.save!
19
+
20
+ flash[:notice] = 'Category created'
21
+ respond_to do |format|
22
+ format.html { redirect_to :action => :edit, :id => @cms_category}
23
+ format.js
24
+ end
25
+
26
+ rescue ActiveRecord::RecordInvalid
27
+ respond_to do |format|
28
+ format.html { render :action => 'new' }
29
+ format.js
30
+ end
31
+ end
32
+
33
+ def edit
34
+ # ...
35
+ end
36
+
37
+ def update
38
+ @cms_category.update_attributes!(params[:cms_category])
39
+ flash[:notice] = 'Category updated'
40
+ respond_to do |format|
41
+ format.html { redirect_to :action => :edit, :id => @cms_category }
42
+ format.js
43
+ end
44
+
45
+ rescue ActiveRecord::RecordInvalid
46
+ respond_to do |format|
47
+ format.html { render :action => 'edit' }
48
+ format.js
49
+ end
50
+ end
51
+
52
+ def show
53
+ end
54
+
55
+ def destroy
56
+ @cms_category.destroy
57
+ flash[:notice] = 'Category deleted'
58
+ redirect_to cms_admin_categories_path
59
+ end
60
+
61
+ protected
62
+
63
+ def load_category
64
+ @cms_category = CmsCategory.find(params[:id])
65
+ rescue ActiveRecord::RecordNotFound
66
+ render :text => 'Item not found', :status => 404
67
+ end
68
+
69
+ end
@@ -0,0 +1,71 @@
1
+ class CmsAdmin::LayoutsController < CmsAdmin::BaseController
2
+
3
+ before_filter :load_layout, :only => [:children, :edit, :update, :destroy, :reorder]
4
+
5
+ def index
6
+ @layouts = CmsLayout.roots
7
+ end
8
+
9
+ def children
10
+ manage_session_array(:cms_layout_tree, (params[:state] == 'open' ? :remove : :add), params[:id])
11
+ end
12
+
13
+ def new
14
+ @layout = CmsLayout.new(params.slice(:parent_id))
15
+ end
16
+
17
+ def edit
18
+ # ...
19
+ end
20
+
21
+ def create
22
+ @layout = CmsLayout.new(params[:layout])
23
+ @layout.save!
24
+
25
+ flash[:notice] = 'Layout created'
26
+ manage_session_array(:cms_layout_tree, :add, @layout.parent_id.to_s)
27
+ redirect_to :action => :edit, :id => @layout
28
+
29
+ rescue ActiveRecord::RecordInvalid
30
+ render :action => :new
31
+ end
32
+
33
+ def update
34
+ @layout.update_attributes!(params[:layout])
35
+
36
+ flash[:notice] = 'Layout updated'
37
+ redirect_to :action => :edit, :id => @layout
38
+
39
+ rescue ActiveRecord::RecordInvalid
40
+ render :action => :edit
41
+ end
42
+
43
+ def destroy
44
+ @layout.destroy
45
+
46
+ flash[:notice] = 'Layout removed'
47
+ redirect_to :action => :index
48
+ end
49
+
50
+ def reorder
51
+ if @layout
52
+ layout_id = @layout.id
53
+ find_scope = @layout.children
54
+ else
55
+ layout_id = 0
56
+ find_scope = CmsLayout
57
+ end
58
+
59
+ params["layout_#{layout_id}_branch"].each_with_index do |id, position|
60
+ find_scope.find(id).update_attribute(:position, position)
61
+ end
62
+ render :nothing => true
63
+ end
64
+
65
+ protected
66
+
67
+ def load_layout
68
+ @layout = CmsLayout.find_by_id(params[:id])
69
+ end
70
+
71
+ end
@@ -0,0 +1,79 @@
1
+ class CmsAdmin::PagesController < CmsAdmin::BaseController
2
+
3
+ include CmsCommon::RenderPage
4
+
5
+ before_filter :load_page, :only => [:children, :edit, :update, :destroy, :reorder]
6
+
7
+ def index
8
+ params[:root] ? @cms_pages = CmsPage.find(params[:root]).children : @cms_pages = CmsPage.roots
9
+ end
10
+
11
+ def children
12
+ manage_session_array(:cms_page_tree, (params[:state] == 'open' ? :remove : :add), params[:id])
13
+ end
14
+
15
+ def new
16
+ @cms_page = CmsPage.new(params.slice(:parent_id))
17
+ @cms_page.published_at = Time.now.utc
18
+ @cms_page.cms_layout = @cms_page.parent.cms_layout if @cms_page.parent
19
+ end
20
+
21
+ def edit
22
+ # ...
23
+ end
24
+
25
+ def create
26
+ @cms_page = CmsPage.new(params[:cms_page])
27
+
28
+ return render_page if !params[:preview].blank? && @cms_page.valid?
29
+
30
+ @cms_page.save!
31
+
32
+ flash[:notice] = 'Page created'
33
+ manage_session_array(:cms_page_tree, :add, @cms_page.parent_id.to_s)
34
+ redirect_to :action => :edit, :id => @cms_page
35
+
36
+ rescue ActiveRecord::RecordInvalid
37
+ render :action => :new
38
+ end
39
+
40
+ def update
41
+ @cms_page.attributes = params[:cms_page]
42
+
43
+ return render_page if !params[:preview].blank? && @cms_page.valid?
44
+
45
+ @cms_page.save!
46
+
47
+ flash[:notice] = 'Page updated'
48
+ redirect_to :action => :edit, :id => @cms_page
49
+
50
+ rescue ActiveRecord::RecordInvalid
51
+ render :action => :edit
52
+ end
53
+
54
+ def destroy
55
+ @cms_page.destroy
56
+
57
+ flash[:notice] = 'Page removed'
58
+ redirect_to :action => :index
59
+ end
60
+
61
+ def form_blocks
62
+ @cms_page = CmsPage.find_by_id(params[:id])
63
+ @layout = CmsLayout.find(params[:layout_id])
64
+ end
65
+
66
+ def reorder
67
+ params["page_#{@cms_page.id}_branch"].each_with_index do |id, position|
68
+ @cms_page.children.find(id).update_attribute(:position, position)
69
+ end
70
+ render :nothing => true
71
+ end
72
+
73
+ protected
74
+
75
+ def load_page
76
+ @cms_page = CmsPage.find_by_id(params[:id])
77
+ end
78
+
79
+ end