layouts look ok now
Oleg
committed Oct 13, 2010
commit a394c0e7e7af78fc206e7b038f181f7fca8d3b59
Showing 7
changed files with
44 additions
and 15 deletions
app/controllers/cms_admin/layouts_controller.rb
+5
-2
| @@ | @@ -17,17 +17,19 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController |
| def create | |
| @cms_layout.save! | |
| - | flash[:notice] = 'Layout successfully created' |
| + | flash[:notice] = 'Layout created' |
| redirect_to :action => :edit, :id => @cms_layout | |
| rescue ActiveRecord::RecordInvalid | |
| + | flash.now[:error] = 'Failed to create layout' |
| render :action => :new | |
| end | |
| def update | |
| @cms_layout.update_attributes!(params[:cms_layout]) | |
| - | flash[:notice] = 'Layout successfully updated' |
| + | flash[:notice] = 'Layout updated' |
| redirect_to :action => :edit, :id => @cms_layout | |
| rescue ActiveRecord::RecordInvalid | |
| + | flash.now[:error] = 'Failed to update layout' |
| render :action => :edit | |
| end | |
| @@ | @@ -41,6 +43,7 @@ protected |
| def build_cms_layout | |
| @cms_layout = CmsLayout.new(params[:cms_layout]) | |
| + | @cms_layout.parent ||= CmsLayout.find_by_id(params[:parent_id]) |
| end | |
| def load_cms_layout | |
app/models/cms_layout.rb
+4
-4
| @@ | @@ -29,12 +29,12 @@ class CmsLayout < ActiveRecord::Base |
| # magical merging tag is <cms:page:content> If parent layout has this tag | |
| # defined its content will be merged. If no such tag found, parent content | |
| # is ignored. | |
| - | def content |
| + | def merged_content |
| if parent | |
| - | c = parent.content.gsub CmsTag::PageText.regex_tag_signature('content'), read_attribute(:content) |
| - | c == parent.content ? read_attribute(:content) : c |
| + | c = parent.merged_content.gsub CmsTag::PageText.regex_tag_signature('content'), content |
| + | c == parent.merged_content ? content : c |
| else | |
| - | read_attribute(:content) |
| + | content |
| end | |
| end | |
app/models/cms_page.rb
+1
-1
| @@ | @@ -43,7 +43,7 @@ class CmsPage < ActiveRecord::Base |
| # Processing content will return rendered content and will populate | |
| # self.cms_tags with instances of CmsTag | |
| def content | |
| - | cms_layout ? CmsTag.process_content(self, cms_layout.content.dup) : '' |
| + | cms_layout ? CmsTag.process_content(self, cms_layout.merged_content) : '' |
| end | |
| # Array of cms_tags for a page. Content generation is called if forced. | |
app/views/cms_admin/layouts/_index_branch.html.erb
+24
-0
| @@ | @@ -0,0 +1,24 @@ |
| + | <% cms_layout ||= index_branch %> |
| + | |
| + | <li id='cms_layout_<%= cms_layout.id %>'> |
| + | <div class='item'> |
| + | <div class='icon'> |
| + | <% if cms_layout.siblings.size > 0 %> |
| + | <div class='dragger'></div> |
| + | <% end %> |
| + | </div> |
| + | <div class='action_links'> |
| + | <%= link_to 'Add Child Layout', new_cms_admin_layout_path(:parent_id => cms_layout.id) %> |
| + | <%= link_to 'Edit', edit_cms_admin_layout_path(cms_layout) %> |
| + | <%= link_to 'Delete', cms_admin_layout_path(cms_layout), :method => :delete, :confirm => 'Are you sure?' %> |
| + | </div> |
| + | <div class='label'> |
| + | <%= link_to cms_layout.label, edit_cms_admin_layout_path(cms_layout) %> |
| + | </div> |
| + | </div> |
| + | <% if cms_layout.children.present? %> |
| + | <ul> |
| + | <%= render :partial => 'index_branch', :collection => cms_layout.children %> |
| + | </ul> |
| + | <% end %> |
| + | </li> |
| \ No newline at end of file | |
app/views/cms_admin/layouts/index.html.erb
+2
-2
| @@ | @@ -1,6 +1,6 @@ |
| <%= link_to span_tag('Create New Layout'), new_cms_admin_layout_path, :class => 'big_button' %> | |
| <h1>Layouts</h1> | |
| - | <ul> |
| - | <%= render :partial => 'tree_branch', :collection => @cms_layouts %> |
| + | <ul class='tree'> |
| + | <%= render :partial => 'index_branch', :collection => @cms_layouts %> |
| </ul> | |
| \ No newline at end of file | |
test/functional/cms_admin/layouts_controller_test.rb
+4
-2
| @@ | @@ -41,7 +41,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| } | |
| assert_response :redirect | |
| assert_redirected_to :action => :edit, :id => CmsLayout.last | |
| - | assert_equal 'Layout successfully created', flash[:notice] |
| + | assert_equal 'Layout created', flash[:notice] |
| end | |
| end | |
| @@ | @@ -50,6 +50,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| post :create, :cms_layout => { } | |
| assert_response :success | |
| assert_template :new | |
| + | assert_equal 'Failed to create layout', flash[:error] |
| end | |
| end | |
| @@ | @@ -61,7 +62,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| } | |
| assert_response :redirect | |
| assert_redirected_to :action => :edit, :id => layout | |
| - | assert_equal 'Layout successfully updated', flash[:notice] |
| + | assert_equal 'Layout updated', flash[:notice] |
| layout.reload | |
| assert_equal 'New Label', layout.label | |
| assert_equal 'New Content', layout.content | |
| @@ | @@ -76,6 +77,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_template :edit | |
| layout.reload | |
| assert_not_equal '', layout.label | |
| + | assert_equal 'Failed to update layout', flash[:error] |
| end | |
| def test_destroy | |
test/unit/cms_layout_test.rb
+4
-4
| @@ | @@ -20,15 +20,15 @@ class CmsLayoutTest < ActiveSupport::TestCase |
| assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_layouts(:nested)).collect{|t| t.first} | |
| end | |
| - | def test_content |
| + | def test_merged_content |
| parent_layout = cms_layouts(:nested) | |
| layout = cms_layouts(:child) | |
| - | assert_equal "<cms:page:header/>\n<cms:page:left_column>\n<cms:page:right_column>", layout.content |
| - | assert_equal "<cms:page:left_column>\n<cms:page:right_column>", layout.read_attribute(:content) |
| + | assert_equal "<cms:page:header/>\n<cms:page:left_column>\n<cms:page:right_column>", layout.merged_content |
| + | assert_equal "<cms:page:left_column>\n<cms:page:right_column>", layout.content |
| parent_layout.update_attribute(:content, '<cms:page:whatever/>') | |
| layout.reload | |
| - | assert_equal "<cms:page:left_column>\n<cms:page:right_column>", layout.content |
| + | assert_equal "<cms:page:left_column>\n<cms:page:right_column>", layout.merged_content |
| end | |
| def test_merged_css | |