layouts have index page now

Oleg committed Sep 02, 2010
commit c1e6cb6452c6af23b1ebf86697a16587ff844ad9
Showing 8 changed files with 27 additions and 8 deletions
app/controllers/cms_admin/layouts_controller.rb +1 -1
@@ @@ -4,7 +4,7 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController
before_filter :load_cms_layout, :only => [:edit, :update, :destroy]
def index
- @cms_layouts = CmsLayout
+ @cms_layouts = CmsLayout.roots
end
def new
app/models/cms_layout.rb +1 -1
@@ @@ -28,7 +28,7 @@ class CmsLayout < ActiveRecord::Base
# -- Instance Methods -----------------------------------------------------
# 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
+ # is ignored.
def content
if parent
c = parent.content.gsub CmsTag::PageText.regex_tag_signature('content'), read_attribute(:content)
app/views/cms_admin/layouts/_form.html.erb +1 -0
@@ @@ -1,2 +1,3 @@
<%= form.text_field :label, :label => 'Layout Name' %>
+ <%= form.select :parent_id, CmsLayout.options_for_select(@cms_layout), :include_blank => true, :label => 'Parent Layout' %>
<%= form.text_area :content %>
\ No newline at end of file
app/views/cms_admin/layouts/_tree_branch.html.erb +10 -0
@@ @@ -0,0 +1,10 @@
+ <li>
+ <%= link_to tree_branch.label, edit_cms_admin_layout_path(tree_branch) %>
+ <% if tree_branch.children.count > 0 %>
+ <ul>
+ <% tree_branch.children.each do |child| %>
+ <%= render :partial => 'tree_branch', :object => child %>
+ <% end %>
+ </ul>
+ <% end %>
+ </li>
\ No newline at end of file
app/views/cms_admin/layouts/edit.html.erb +2 -2
@@ @@ -1,6 +1,6 @@
<h1> Editing Layout </h1>
- <%= form_for @cms_layout, :url => {:action => :update} do |form| %>
- <%= render :partial => form %>
+ <%= cms_form_for @cms_layout, :url => {:action => :update} do |form| %>
+ <%= render :partial => 'form', :object => form %>
<%= form.submit 'Update Layout' %>
<% end %>
\ No newline at end of file
app/views/cms_admin/layouts/index.html.erb +7 -1
@@ @@ -1,3 +1,9 @@
<h1>Layouts</h1>
- <%= debug @cms_layouts.all %>
\ No newline at end of file
+ <%= link_to 'Create New Layout', new_cms_admin_layout_path %>
+
+ <ul>
+ <% @cms_layouts.each do |layout| %>
+ <%= render :partial => 'tree_branch', :object => layout %>
+ <% end %>
+ </ul>
\ No newline at end of file
comfortable_mexican_sofa/cms_form_builder.rb b/lib/comfortable_mexican_sofa/cms_form_builder.rb +2 -1
@@ @@ -1,7 +1,8 @@
class CmsFormBuilder < ActionView::Helpers::FormBuilder
helpers = field_helpers -
- %w(hidden_field fields_for)
+ %w(hidden_field fields_for) +
+ %w(select)
helpers.each do |name|
class_eval %Q^
test/functional/cms_admin/layouts_controller_test.rb +3 -2
@@ @@ -18,11 +18,12 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
end
def test_get_edit
- get :edit, :id => cms_layouts(:default)
+ layout = cms_layouts(:default)
+ get :edit, :id => layout
assert_response :success
assert assigns(:cms_layout)
assert_template :edit
- assert_select "form[action=/cms-admin/layouts/#{cms_layouts(:default).id}]"
+ assert_select "form[action=/cms-admin/layouts/#{layout.id}]"
end
def test_get_edit_failure