layouts can be saved with blank content
Oleg
committed May 12, 2011
commit 86f5a323fa867cdb48195a84ffcbe6e0aa289d65
Showing 7
changed files with
44 additions
and 38 deletions
app/models/cms/layout.rb
+0
-10
| @@ | @@ -24,9 +24,6 @@ class Cms::Layout < ActiveRecord::Base |
| :presence => true, | |
| :uniqueness => { :scope => :site_id }, | |
| :format => { :with => /^\w[a-z0-9_-]*$/i } | |
| - | validates :content, |
| - | :presence => true |
| - | validate :check_content_tag_presence |
| # -- Class Methods -------------------------------------------------------- | |
| # Tree-like structure for layouts | |
| @@ | @@ -74,13 +71,6 @@ protected |
| self.label = self.label.blank?? self.slug.try(:titleize) : self.label | |
| end | |
| - | def check_content_tag_presence |
| - | ComfortableMexicanSofa::Tag.process_content((test_page = site.pages.new), content) |
| - | if test_page.tags.select{|t| t.is_cms_block?}.blank? |
| - | self.errors.add(:content, 'No cms page tags defined') |
| - | end |
| - | end |
| - | |
| # After saving need to make sure that cached pages for css and js for this | |
| # layout and its children are gone. Good enough to avoid using cache sweepers. | |
| def clear_cache | |
app/views/cms_admin/pages/_form_blocks.html.erb
+13
-3
| @@ | @@ -1,7 +1,17 @@ |
| + | <% block_tags = @cms_page.tags(true).select{ |t| t.is_cms_block? } %> |
| + | |
| <div id='form_blocks'> | |
| - | <%= fields_for :blocks, nil, :builder => ComfortableMexicanSofa::FormBuilder do |cms_blocks| %> |
| - | <% @cms_page.tags(true).select{|t| t.is_cms_block?}.each do |tag| %> |
| - | <%= cms_blocks.send(tag.class.to_s.demodulize.underscore, tag)%> |
| + | <% if block_tags.empty? %> |
| + | <div class='no_tags'> |
| + | <%= link_to @cms_page.layout.label, edit_cms_admin_layout_path(@cms_page.layout) %> |
| + | Layout has no content tags defined. <br/> |
| + | Edit the content to include a page or field tag, for example: <code>{{cms:page:content}}</code> |
| + | </div> |
| + | <% else %> |
| + | <%= fields_for :blocks, nil, :builder => ComfortableMexicanSofa::FormBuilder do |cms_blocks| %> |
| + | <% block_tags.each do |tag| %> |
| + | <%= cms_blocks.send(tag.class.to_s.demodulize.underscore, tag)%> |
| + | <% end %> |
| <% end %> | |
| <% end %> | |
| </div> | |
| \ No newline at end of file | |
public/stylesheets/comfortable_mexican_sofa/form.css
+18
-0
| @@ | @@ -42,6 +42,24 @@ |
| .page_form_extras { | |
| margin-bottom: 10px; | |
| } | |
| + | #form_blocks .no_tags { |
| + | background-color: #252525; |
| + | color: #aaa; |
| + | border-radius: 3px; |
| + | margin-left: 150px; |
| + | text-align: center; |
| + | padding: 10px; |
| + | } |
| + | #form_blocks .no_tags a { |
| + | color: #fff; |
| + | } |
| + | #form_blocks .no_tags a:hover { |
| + | color: #aaa; |
| + | text-decoration: underline; |
| + | } |
| + | #form_blocks .no_tags code { |
| + | color: #B85042; |
| + | } |
| .form_element.field_datetime .label, | |
| .form_element.field_integer .label, | |
| .form_element.field_string .label, | |
public/stylesheets/comfortable_mexican_sofa/structure.css
+1
-1
| @@ | @@ -130,7 +130,7 @@ input[type='file'] { |
| a.button.big { | |
| float: right; | |
| } | |
| - | |
| + | /* -- Sofa Version ------------------------------------------------------- */ |
| .center_column .sofa { | |
| position: absolute; | |
| background: #000; | |
public/stylesheets/comfortable_mexican_sofa/typography.css
+3
-0
| @@ | @@ -30,4 +30,7 @@ strong { |
| } | |
| em { | |
| font-style: italic; | |
| + | } |
| + | code { |
| + | font: 13px Consolas, Monaco, Courier New, Courier, monospace; |
| } | |
| \ No newline at end of file | |
test/unit/mirror_sites_test.rb
+8
-1
| @@ | @@ -3,13 +3,20 @@ require File.expand_path('../test_helper', File.dirname(__FILE__)) |
| class MirrorSitesTest < ActiveSupport::TestCase | |
| def setup | |
| + | ComfortableMexicanSofa.config.enable_mirror_sites = true |
| Cms::Site.destroy_all | |
| @site_a = Cms::Site.create!(:label => 'Site A', :hostname => 'site-a.host') | |
| @site_b = Cms::Site.create!(:label => 'Site B', :hostname => 'site-b.host') | |
| end | |
| def test_layout_creation | |
| - | |
| + | assert_difference 'Cms::Layout.count', 2 do |
| + | @site_a.layouts.create!(:slug => 'default', :content => '{{cms:page:content}}') |
| + | @site_b.reload |
| + | assert_equal 1, @site_b.layouts.count |
| + | layout = @site_b.layouts.first |
| + | assert_equal 'default', layout.slug |
| + | end |
| end | |
| def test_page_creation | |
test/unit/models/layout_test.rb
+1
-23
| @@ | @@ -11,29 +11,7 @@ class CmsLayoutTest < ActiveSupport::TestCase |
| def test_validations | |
| layout = cms_sites(:default).layouts.create | |
| assert layout.errors.present? | |
| - | assert_has_errors_on layout, [:label, :slug, :content] |
| - | end |
| - | |
| - | def test_validation_of_tag_presence |
| - | layout = cms_sites(:default).layouts.create(:content => 'some text') |
| - | assert_has_errors_on layout, :content |
| - | |
| - | layout = cms_sites(:default).layouts.create(:content => '{cms:snippet:blah}') |
| - | assert_has_errors_on layout, :content |
| - | |
| - | layout = cms_sites(:default).layouts.new( |
| - | :label => 'test', |
| - | :slug => 'test', |
| - | :content => '{{cms:page:blah}}' |
| - | ) |
| - | assert layout.valid? |
| - | |
| - | layout = cms_sites(:default).layouts.new( |
| - | :label => 'test', |
| - | :slug => 'test', |
| - | :content => '{{cms:field:blah}}' |
| - | ) |
| - | assert layout.valid? |
| + | assert_has_errors_on layout, [:label, :slug] |
| end | |
| def test_label_assignment | |