adding publishing functionality for pages
Oleg
committed Dec 16, 2010
commit eca89c35f90eeaddc946c4c81edb1f9c9c6f2f70
Showing 13
changed files with
131 additions
and 68 deletions
Gemfile
+1
-1
| @@ | @@ -1,6 +1,6 @@ |
| source 'http://rubygems.org' | |
| - | gem 'rails', '>=3.0.1' |
| + | gem 'rails', '>=3.0.3' |
| gem 'sqlite3-ruby', :require => 'sqlite3' | |
| gem 'active_link_to', '>=0.0.6' | |
| gem 'paperclip', '>=2.3.5' | |
Gemfile.lock
+47
-51
| @@ | @@ -2,52 +2,50 @@ GEM |
| remote: http://rubygems.org/ | |
| specs: | |
| abstract (1.0.0) | |
| - | actionmailer (3.0.1) |
| - | actionpack (= 3.0.1) |
| - | mail (~> 2.2.5) |
| - | actionpack (3.0.1) |
| - | activemodel (= 3.0.1) |
| - | activesupport (= 3.0.1) |
| + | actionmailer (3.0.3) |
| + | actionpack (= 3.0.3) |
| + | mail (~> 2.2.9) |
| + | actionpack (3.0.3) |
| + | activemodel (= 3.0.3) |
| + | activesupport (= 3.0.3) |
| builder (~> 2.1.2) | |
| erubis (~> 2.6.6) | |
| - | i18n (~> 0.4.1) |
| + | i18n (~> 0.4) |
| rack (~> 1.2.1) | |
| - | rack-mount (~> 0.6.12) |
| - | rack-test (~> 0.5.4) |
| + | rack-mount (~> 0.6.13) |
| + | rack-test (~> 0.5.6) |
| tzinfo (~> 0.3.23) | |
| active_link_to (0.0.6) | |
| - | activemodel (3.0.1) |
| - | activesupport (= 3.0.1) |
| + | activemodel (3.0.3) |
| + | activesupport (= 3.0.3) |
| builder (~> 2.1.2) | |
| - | i18n (~> 0.4.1) |
| - | activerecord (3.0.1) |
| - | activemodel (= 3.0.1) |
| - | activesupport (= 3.0.1) |
| - | arel (~> 1.0.0) |
| + | i18n (~> 0.4) |
| + | activerecord (3.0.3) |
| + | activemodel (= 3.0.3) |
| + | activesupport (= 3.0.3) |
| + | arel (~> 2.0.2) |
| tzinfo (~> 0.3.23) | |
| - | activeresource (3.0.1) |
| - | activemodel (= 3.0.1) |
| - | activesupport (= 3.0.1) |
| - | activesupport (3.0.1) |
| - | arel (1.0.1) |
| - | activesupport (~> 3.0.0) |
| + | activeresource (3.0.3) |
| + | activemodel (= 3.0.3) |
| + | activesupport (= 3.0.3) |
| + | activesupport (3.0.3) |
| + | arel (2.0.6) |
| builder (2.1.2) | |
| erubis (2.6.6) | |
| abstract (>= 1.0.0) | |
| - | gemcutter (0.6.1) |
| git (1.2.5) | |
| - | i18n (0.4.1) |
| - | jeweler (1.4.0) |
| - | gemcutter (>= 0.1.0) |
| + | i18n (0.5.0) |
| + | jeweler (1.5.1) |
| + | bundler (~> 1.0.0) |
| git (>= 1.2.5) | |
| - | rubyforge (>= 2.0.0) |
| - | json_pure (1.4.6) |
| - | mail (2.2.7) |
| + | rake |
| + | mail (2.2.12) |
| activesupport (>= 2.3.6) | |
| - | mime-types |
| - | treetop (>= 1.4.5) |
| + | i18n (>= 0.4.0) |
| + | mime-types (~> 1.16) |
| + | treetop (~> 1.4.8) |
| mime-types (1.16) | |
| - | paperclip (2.3.5) |
| + | paperclip (2.3.8) |
| activerecord | |
| activesupport | |
| polyglot (0.3.1) | |
| @@ | @@ -56,25 +54,23 @@ GEM |
| rack (>= 1.0.0) | |
| rack-test (0.5.6) | |
| rack (>= 1.0) | |
| - | rails (3.0.1) |
| - | actionmailer (= 3.0.1) |
| - | actionpack (= 3.0.1) |
| - | activerecord (= 3.0.1) |
| - | activeresource (= 3.0.1) |
| - | activesupport (= 3.0.1) |
| - | bundler (~> 1.0.0) |
| - | railties (= 3.0.1) |
| - | railties (3.0.1) |
| - | actionpack (= 3.0.1) |
| - | activesupport (= 3.0.1) |
| - | rake (>= 0.8.4) |
| - | thor (~> 0.14.0) |
| + | rails (3.0.3) |
| + | actionmailer (= 3.0.3) |
| + | actionpack (= 3.0.3) |
| + | activerecord (= 3.0.3) |
| + | activeresource (= 3.0.3) |
| + | activesupport (= 3.0.3) |
| + | bundler (~> 1.0) |
| + | railties (= 3.0.3) |
| + | railties (3.0.3) |
| + | actionpack (= 3.0.3) |
| + | activesupport (= 3.0.3) |
| + | rake (>= 0.8.7) |
| + | thor (~> 0.14.4) |
| rake (0.8.7) | |
| - | rubyforge (2.0.4) |
| - | json_pure (>= 1.1.7) |
| - | sqlite3-ruby (1.3.1) |
| - | thor (0.14.3) |
| - | treetop (1.4.8) |
| + | sqlite3-ruby (1.3.2) |
| + | thor (0.14.6) |
| + | treetop (1.4.9) |
| polyglot (>= 0.3.1) | |
| tzinfo (0.3.23) | |
| @@ | @@ -86,5 +82,5 @@ DEPENDENCIES |
| jeweler (>= 1.4.0) | |
| mime-types | |
| paperclip (>= 2.3.5) | |
| - | rails (>= 3.0.1) |
| + | rails (>= 3.0.3) |
| sqlite3-ruby | |
Rakefile
+1
-2
| @@ | @@ -16,7 +16,7 @@ begin |
| gem.email = 'oleg@theworkinggroup.ca' | |
| gem.homepage = 'http://github.com/twg/comfortable-mexican-sofa' | |
| gem.authors = ['Oleg Khabarov', 'The Working Group Inc'] | |
| - | gem.add_dependency('rails', '>=3.0.1') |
| + | gem.add_dependency('rails', '>=3.0.3') |
| gem.add_dependency('active_link_to', '>=0.0.6') | |
| gem.add_dependency('paperclip', '>=2.3.5') | |
| end | |
| @@ | @@ -45,7 +45,6 @@ rescue LoadError |
| end | |
| end | |
| - | task :test => :check_dependencies |
| task :default => :test | |
| require 'rake/rdoctask' | |
app/controllers/cms_content_controller.rb
+2
-2
| @@ | @@ -28,11 +28,11 @@ protected |
| end | |
| def load_cms_page | |
| - | @cms_page = CmsPage.load_for_full_path!(@cms_site, "/#{params[:cms_path]}") |
| + | @cms_page = CmsPage.published.load_for_full_path!(@cms_site, "/#{params[:cms_path]}") |
| return redirect_to(@cms_page.target_page.full_path) if @cms_page.target_page | |
| rescue ActiveRecord::RecordNotFound | |
| - | if @cms_page = CmsPage.load_for_full_path(@cms_site, '/404') |
| + | if @cms_page = CmsPage.published.load_for_full_path(@cms_site, '/404') |
| render_html(404) | |
| else | |
| render :text => 'Page Not Found', :status => 404 | |
app/models/cms_page.rb
+3
-0
| @@ | @@ -36,6 +36,9 @@ class CmsPage < ActiveRecord::Base |
| :uniqueness => { :scope => :cms_site_id } | |
| validate :validate_target_page | |
| + | # -- Scopes --------------------------------------------------------------- |
| + | scope :published, where(:is_published => true) |
| + | |
| # -- Class Methods -------------------------------------------------------- | |
| # Tree-like structure for pages | |
| def self.options_for_select(cms_site, cms_page = nil, current_page = nil, depth = 0, exclude_self = true, spacer = '. . ') | |
app/views/cms_admin/pages/_form.html.erb
+10
-1
| @@ | @@ -1,4 +1,11 @@ |
| <% content_for :right_column do %> | |
| + | <div id='page_save' class='box'> |
| + | <label> |
| + | <input type='checkbox'/> |
| + | Published |
| + | </label> |
| + | <button></button> |
| + | </div> |
| <%= render :partial => 'cms_admin/uploads/index' %> | |
| <% end %> | |
| @@ | @@ -20,4 +27,6 @@ |
| <%= cms_hook :page_form, :object => form %> | |
| </div> | |
| - | <%= render :partial => 'form_blocks' %> |
| \ No newline at end of file | |
| + | <%= render :partial => 'form_blocks' %> |
| + | |
| + | <%= form.check_box :is_published, :label => 'Published' %> |
| \ No newline at end of file | |
app/views/cms_admin/uploads/_index.html.erb
+0
-2
| @@ | @@ -1,5 +1,3 @@ |
| - | <h2>File Uploads</h2> |
| - | |
| <div id='file_uploads' class='box'> | |
| <button id="uploader_button" href="#">Select Files to Upload</button> | |
| <div id='uploaded_files'> | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+1
-1
| @@ | @@ -36,6 +36,7 @@ class CreateCms < ActiveRecord::Migration |
| t.text :content | |
| t.integer :position, :null => false, :default => 0 | |
| t.integer :children_count, :null => false, :default => 0 | |
| + | t.boolean :is_published, :null => false, :default => true |
| t.timestamps | |
| end | |
| add_index :cms_pages, [:cms_site_id, :full_path] | |
| @@ | @@ -69,7 +70,6 @@ class CreateCms < ActiveRecord::Migration |
| t.timestamps | |
| end | |
| add_index :cms_uploads, [:cms_site_id, :file_file_name] | |
| - | |
| end | |
| def self.down | |
public/javascripts/comfortable_mexican_sofa/cms.js
+18
-2
| @@ | @@ -9,7 +9,8 @@ $.CMS = function(){ |
| $.CMS.load_page_blocks(); | |
| $.CMS.enable_rich_text(); | |
| $.CMS.enable_date_picker(); | |
| - | if($('#uploader_button').get(0)) $.CMS.enable_uploader(); |
| + | if($('#page_save').get(0)) $.CMS.enable_page_save_widget(); |
| + | if($('#uploader_button').get(0)) $.CMS.enable_uploader(); |
| }); | |
| @@ | @@ -49,7 +50,7 @@ $.CMS = function(){ |
| }, | |
| enable_rich_text: function(){ | |
| - | $('.form_element.cms_tag_page_rich_text textarea').tinymce({ |
| + | $('.form_element.cms_tag_page_rich_text textarea, textarea.rich_text').tinymce({ |
| theme : "advanced", | |
| plugins: "", | |
| theme_advanced_buttons1 : "formatselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,link,unlink,anchor,image,|,code", | |
| @@ | @@ -87,6 +88,21 @@ $.CMS = function(){ |
| }); | |
| }, | |
| + | enable_page_save_widget : function(){ |
| + | $('#page_save input').attr('checked', $('input#cms_page_is_published').is(':checked')); |
| + | $('#page_save button').html($('input#cms_page_submit').val()); |
| + | |
| + | $('#page_save input').bind('click', function(){ |
| + | $('input#cms_page_is_published').attr('checked', $(this).is(':checked')); |
| + | }) |
| + | $('input#cms_page_is_published').bind('click', function(){ |
| + | $('#page_save input').attr('checked', $(this).is(':checked')); |
| + | }) |
| + | $('#page_save button').bind('click', function(){ |
| + | $('input#cms_page_submit').click(); |
| + | }) |
| + | }, |
| + | |
| enable_uploader : function(){ | |
| auth_token = $("meta[name=csrf-token]").attr('content'); | |
| var uploader = new plupload.Uploader({ | |
public/stylesheets/comfortable_mexican_sofa/structure.css
+13
-5
| @@ | @@ -54,17 +54,25 @@ html, body { |
| opacity: 1; | |
| } | |
| /* -- Right Column ------------------------------------------------------- */ | |
| - | .right_column_content h2 { |
| - | font: 15px/25px Georgia, serif; |
| - | color: #fff; |
| - | margin-bottom: 10px; |
| - | } |
| .right_column_content .box { | |
| background-color: #ececec; | |
| padding: 5px; | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| + | margin-bottom: 25px; |
| + | overflow: hidden; |
| } | |
| + | #page_save button { |
| + | float: right; |
| + | } |
| + | #page_save label { |
| + | line-height: 20px; |
| + | padding-left: 5px; |
| + | } |
| + | #page_save input { |
| + | margin-right: 5px; |
| + | } |
| + | |
| #file_uploads button { | |
| width: 100%; | |
| margin-bottom: 10px; | |
test/fixtures/cms_pages.yml
+2
-0
| @@ | @@ -8,6 +8,7 @@ default: |
| full_path: '/' | |
| children_count: 1 | |
| position: 0 | |
| + | is_published: true |
| content: |- | |
| layout_content_a | |
| @@ | @@ -28,6 +29,7 @@ child: |
| full_path: '/child-page' | |
| children_count: 0 | |
| position: 0 | |
| + | is_published: true |
| content: |- | |
| layout_content_a | |
test/functional/cms_content_controller_test.rb
+11
-1
| @@ | @@ -32,17 +32,20 @@ class CmsContentControllerTest < ActionController::TestCase |
| end | |
| def test_render_page_not_found_with_custom_404 | |
| - | cms_sites(:default).cms_pages.create!( |
| + | page = cms_sites(:default).cms_pages.create!( |
| :label => '404', | |
| :slug => '404', | |
| :parent_id => cms_pages(:default).id, | |
| :cms_layout_id => cms_layouts(:default).id, | |
| + | :is_published => '1', |
| :cms_blocks_attributes => [ | |
| { :label => 'default_page_text', | |
| :type => 'CmsTag::PageText', | |
| :content => 'custom 404 page content' } | |
| ] | |
| ) | |
| + | assert_equal '/404', page.full_path |
| + | assert page.is_published? |
| get :render_html, :cms_path => 'doesnotexist' | |
| assert_response 404 | |
| assert assigns(:cms_page) | |
| @@ | @@ -57,6 +60,13 @@ class CmsContentControllerTest < ActionController::TestCase |
| assert_redirected_to '/' | |
| end | |
| + | def test_render_page_unpublished |
| + | page = cms_pages(:default) |
| + | page.update_attribute(:is_published, false) |
| + | get :render_html, :cms_path => '' |
| + | assert_response 404 |
| + | end |
| + | |
| def test_render_css | |
| get :render_css, :id => cms_layouts(:default).slug | |
| assert_response :success | |
test/unit/cms_page_test.rb
+22
-0
| @@ | @@ -44,6 +44,22 @@ class CmsPageTest < ActiveSupport::TestCase |
| assert_has_errors_on page, :target_page_id | |
| end | |
| + | def test_creation |
| + | assert_difference ['CmsPage.count', 'CmsBlock.count'] do |
| + | page = cms_sites(:default).cms_pages.create!( |
| + | :label => 'test', |
| + | :slug => 'test', |
| + | :parent_id => cms_pages(:default).id, |
| + | :cms_layout_id => cms_layouts(:default).id, |
| + | :cms_blocks_attributes => [ |
| + | { :label => 'test', |
| + | :content => 'test' } |
| + | ] |
| + | ) |
| + | assert page.is_published? |
| + | end |
| + | end |
| + | |
| def test_initialization_of_full_path | |
| page = CmsPage.new(new_params) | |
| assert page.invalid? | |
| @@ | @@ -201,6 +217,12 @@ class CmsPageTest < ActiveSupport::TestCase |
| assert_not_equal 'changed', page.read_attribute(:content) | |
| end | |
| + | def test_scope_published |
| + | assert_equal 2, CmsPage.published.count |
| + | cms_pages(:child).update_attribute(:is_published, false) |
| + | assert_equal 1, CmsPage.published.count |
| + | end |
| + | |
| protected | |
| def new_params(options = {}) | |