layouts now have slugs like everything else

Oleg committed Oct 25, 2010
commit 3bf9d9799a14e11b71e1203dfaee75271113608c
Showing 9 changed files with 55 additions and 43 deletions
app/models/cms_layout.rb +12 -5
@@ @@ -7,9 +7,16 @@ class CmsLayout < ActiveRecord::Base
has_many :cms_pages, :dependent => :nullify
# -- Validations ----------------------------------------------------------
- validates :cms_site_id, :presence => true
- validates :label, :presence => true
- validates :content, :presence => true
+ validates :cms_site_id,
+ :presence => true
+ validates :label,
+ :presence => true
+ validates :slug,
+ :presence => true,
+ :uniqueness => { :scope => :cms_site_id },
+ :format => { :with => /^\w[a-z0-9_-]*$/i }
+ validates :content,
+ :presence => true
# -- Class Methods --------------------------------------------------------
# Tree-like structure for layouts
@@ @@ -58,10 +65,10 @@ class CmsLayout < ActiveRecord::Base
end
def merged_css
- self.parent ? self.parent.merged_css + self.css : self.css.to_s
+ self.parent ? [self.parent.merged_css, self.css].join("\n") : self.css.to_s
end
def merged_js
- self.parent ? self.parent.merged_js + self.js : self.js.to_s
+ self.parent ? [self.parent.merged_js, self.js].join("\n") : self.js.to_s
end
end
app/views/cms_admin/layouts/_form.html.erb +2 -1
@@ @@ -1,4 +1,5 @@
- <%= form.text_field :label, :label => 'Layout Name' %>
+ <%= form.text_field :label, :label => 'Layout Name', :id => (@cms_layout.new_record?? 'slugify' : nil)%>
+ <%= form.text_field :slug, :id => 'slug' %>
<%= form.select :parent_id, CmsLayout.options_for_select(@cms_site, @cms_layout), :include_blank => true %>
<%= form.select :app_layout, CmsLayout.app_layouts_for_select, :include_blank => true %>
<%= form.text_area :content %>
app/views/cms_admin/layouts/_index_branch.html.erb +3 -0
@@ @@ -14,6 +14,9 @@
</div>
<div class='label'>
<%= link_to cms_layout.label, edit_cms_admin_layout_path(cms_layout) %>
+ <div class='sublabel'>
+ <%= link_to cms_layout.slug, edit_cms_admin_layout_path(cms_layout) %>
+ </div>
</div>
</div>
<% if cms_layout.children.present? %>
comfortable_mexican_sofa.gemspec +14 -5
@@ @@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{comfortable_mexican_sofa}
- s.version = "1.0.2"
+ s.version = "1.0.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Oleg Khabarov", "The Working Group Inc"]
- s.date = %q{2010-10-19}
+ s.date = %q{2010-10-25}
s.description = %q{}
s.email = %q{oleg@theworkinggroup.ca}
s.extra_rdoc_files = [
@@ @@ -85,6 +85,7 @@ Gem::Specification.new do |s|
"lib/comfortable_mexican_sofa/cms_tag/field_integer.rb",
"lib/comfortable_mexican_sofa/cms_tag/field_string.rb",
"lib/comfortable_mexican_sofa/cms_tag/field_text.rb",
+ "lib/comfortable_mexican_sofa/cms_tag/helper.rb",
"lib/comfortable_mexican_sofa/cms_tag/page_datetime.rb",
"lib/comfortable_mexican_sofa/cms_tag/page_integer.rb",
"lib/comfortable_mexican_sofa/cms_tag/page_string.rb",
@@ @@ -120,7 +121,12 @@ Gem::Specification.new do |s|
"public/stylesheets/comfortable_mexican_sofa/structure.css",
"public/stylesheets/comfortable_mexican_sofa/typography.css",
"script/rails",
- "test/fixtures/README.md",
+ "test/cms_seeds/test.host/layouts/default.yml",
+ "test/cms_seeds/test.host/layouts/nested.yml",
+ "test/cms_seeds/test.host/pages/child.yml",
+ "test/cms_seeds/test.host/pages/child/subchild.yml",
+ "test/cms_seeds/test.host/pages/index.yml",
+ "test/cms_seeds/test.host/snippets/default.yml",
"test/fixtures/cms_blocks.yml",
"test/fixtures/cms_layouts.yml",
"test/fixtures/cms_pages.yml",
@@ @@ -136,6 +142,7 @@ Gem::Specification.new do |s|
"test/functional/cms_admin/uploads_controller_test.rb",
"test/functional/cms_content_controller_test.rb",
"test/integration/authentication_test.rb",
+ "test/integration/render_cms_seed_test.rb",
"test/integration/render_cms_test.rb",
"test/integration/sites_test.rb",
"test/test_helper.rb",
@@ @@ -150,14 +157,14 @@ Gem::Specification.new do |s|
"test/unit/cms_tags/field_integer_test.rb",
"test/unit/cms_tags/field_string_test.rb",
"test/unit/cms_tags/field_text_test.rb",
+ "test/unit/cms_tags/helper_test.rb",
"test/unit/cms_tags/page_datetime_test.rb",
"test/unit/cms_tags/page_integer_test.rb",
"test/unit/cms_tags/page_string_test.rb",
"test/unit/cms_tags/page_text_test.rb",
"test/unit/cms_tags/partial_test.rb",
"test/unit/cms_tags/snippet_test.rb",
- "test/unit/cms_upload_test.rb",
- "tmp/restart.txt"
+ "test/unit/cms_upload_test.rb"
]
s.homepage = %q{http://github.com/theworkinggroup/comfortable-mexican-sofa}
s.rdoc_options = ["--charset=UTF-8"]
@@ @@ -172,6 +179,7 @@ Gem::Specification.new do |s|
"test/functional/cms_admin/uploads_controller_test.rb",
"test/functional/cms_content_controller_test.rb",
"test/integration/authentication_test.rb",
+ "test/integration/render_cms_seed_test.rb",
"test/integration/render_cms_test.rb",
"test/integration/sites_test.rb",
"test/test_helper.rb",
@@ @@ -186,6 +194,7 @@ Gem::Specification.new do |s|
"test/unit/cms_tags/field_integer_test.rb",
"test/unit/cms_tags/field_string_test.rb",
"test/unit/cms_tags/field_text_test.rb",
+ "test/unit/cms_tags/helper_test.rb",
"test/unit/cms_tags/page_datetime_test.rb",
"test/unit/cms_tags/page_integer_test.rb",
"test/unit/cms_tags/page_string_test.rb",
config/routes.rb +3 -3
@@ @@ -14,9 +14,9 @@ Rails.application.routes.draw do
end
scope :controller => :cms_content do
- get '/cms-css/:id' => :render_css, :format => 'css'
- get '/cms-js/:id' => :render_js, :format => 'js'
- get '/' => :render_html, :path => '(*cms_path)'
+ get '/cms-css/:id' => :render_css, :as => 'cms_css', :format => 'css'
+ get '/cms-js/:id' => :render_js, :as => 'cms_js', :format => 'js'
+ get '/' => :render_html, :as => 'cms_html', :path => '(*cms_path)'
end
end
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb +2 -1
@@ @@ -14,14 +14,15 @@ class CreateCms < ActiveRecord::Migration
t.integer :parent_id
t.string :app_layout
t.string :label
+ t.string :slug
t.text :content
t.text :css
t.text :js
t.integer :position, :null => false, :default => 0
t.timestamps
end
- add_index :cms_layouts, [:cms_site_id, :label]
add_index :cms_layouts, [:parent_id, :position]
+ add_index :cms_layouts, [:cms_site_id, :slug], :unique => true
# -- Pages --------------------------------------------------------------
create_table :cms_pages do |t|
test/fixtures/cms_layouts.yml +9 -20
@@ @@ -1,6 +1,7 @@
default:
cms_site: default
label: Default Layout
+ slug: default
parent:
content: |-
<cms:field:default_field_text:text>
@@ @@ -9,39 +10,27 @@ default:
layout_content_b
<cms:snippet:default>
layout_content_c
- css: |-
- body { background-color: red }
- p { color: #fff }
- js: |-
- $(document).ready(function() {
- alert('hi');
- })
+ css: default_css
+ js: default_js
nested:
cms_site: default
label: Nested Layout
+ slug: nested
parent:
content: |-
<cms:page:header/>
<cms:page:content/>
- css: |-
- body { background-color: red }
- js: |-
- $(document).ready(function() {
- alert('hi');
- })
+ css: nested_css
+ js: nested_js
child:
cms_site: default
label: Child Layout
+ slug: child
parent: nested
content: |-
<cms:page:left_column>
<cms:page:right_column>
- css: |-
- body { p: #fff }
- js: |-
- js: |-
- $(document).ready(function() {
- alert('sup');
- })
\ No newline at end of file
+ css: child_css
+ js: child_js
\ No newline at end of file
test/functional/cms_admin/layouts_controller_test.rb +1 -0
@@ @@ -37,6 +37,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
assert_difference 'CmsLayout.count' do
post :create, :cms_layout => {
:label => 'Test Layout',
+ :slug => 'test',
:content => 'Test Content'
}
assert_response :redirect
test/unit/cms_layout_test.rb +9 -8
@@ @@ -11,13 +11,16 @@ class CmsLayoutTest < ActiveSupport::TestCase
def test_validations
layout = CmsLayout.create
assert layout.errors.present?
- assert_has_errors_on layout, [:label, :content]
+ assert_has_errors_on layout, [:label, :slug, :content]
end
def test_options_for_select
- assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'], CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first}
- assert_equal ['Default Layout', 'Nested Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first}
- assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first}
+ assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'],
+ CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first}
+ assert_equal ['Default Layout', 'Nested Layout'],
+ CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first}
+ assert_equal ['Default Layout'],
+ CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first}
end
def test_app_layouts_for_select
@@ @@ -36,13 +39,11 @@ class CmsLayoutTest < ActiveSupport::TestCase
end
def test_merged_css
- merged_css = cms_layouts(:nested).css + cms_layouts(:child).css
- assert_equal merged_css, cms_layouts(:child).merged_css
+ assert_equal "nested_css\nchild_css", cms_layouts(:child).merged_css
end
def test_merged_js
- merged_js = cms_layouts(:nested).js + cms_layouts(:child).js
- assert_equal merged_js, cms_layouts(:child).merged_js
+ assert_equal "nested_js\nchild_js", cms_layouts(:child).merged_js
end
def test_load_from_file