killing off content_path_prefix
Oleg
committed Jun 08, 2011
commit 086e5fffa7987d5b83c19f190dcfdf03898c4891
Showing 12
changed files with
14 additions
and 58 deletions
app/models/cms/site.rb
+3
-10
| @@ | @@ -9,16 +9,12 @@ class Cms::Site < ActiveRecord::Base |
| has_many :uploads, :dependent => :destroy | |
| # -- Callbacks ------------------------------------------------------------ | |
| - | before_validation :assign_label, |
| - | :assign_path |
| + | before_validation :assign_label |
| before_save :clean_path | |
| # -- Validations ---------------------------------------------------------- | |
| validates :label, | |
| :presence => true | |
| - | validates :path, |
| - | :presence => true, |
| - | :format => { :with => /^\/[\w\d\-\/]*$/ } |
| validates :hostname, | |
| :presence => true, | |
| :uniqueness => { :scope => :path }, | |
| @@ | @@ -33,13 +29,10 @@ protected |
| self.label = self.label.blank?? self.hostname : self.label | |
| end | |
| - | def assign_path |
| - | self.path ||= '/' |
| - | end |
| - | |
| def clean_path | |
| + | self.path ||= '' |
| self.path.squeeze!('/') | |
| - | self.path.gsub!(/\/$/, '') unless self.path == '/' |
| + | self.path.gsub!(/\/$/, '') |
| end | |
| end | |
| \ No newline at end of file | |
config/initializers/comfortable_mexican_sofa.rb
+0
-5
| @@ | @@ -11,11 +11,6 @@ ComfortableMexicanSofa.configure do |config| |
| # entirely set this to '' or nil | |
| # config.admin_route_prefix = 'cms-admin' | |
| - | # By default Cms content is served directly from the root. Change this setting |
| - | # if you wish to restrict all content to a section of your site. |
| - | # To have root page served from http://yourhost/content/ set config below to 'content' |
| - | # config.content_route_prefix = '' |
| - | |
| # Path: /cms-admin redirects to /cms-admin/pages but you can change it | |
| # config.admin_route_redirect = 'pages' | |
config/routes.rb
+3
-4
| @@ | @@ -31,10 +31,9 @@ Rails.application.routes.draw do |
| end unless ComfortableMexicanSofa.config.admin_route_prefix.blank? | |
| scope :controller => :cms_content do | |
| - | prefix = ComfortableMexicanSofa.config.content_route_prefix |
| - | get "#{prefix}/cms-css/:id" => :render_css, :as => 'cms_css' |
| - | get "#{prefix}/cms-js/:id" => :render_js, :as => 'cms_js' |
| - | get "#{prefix}/" => :render_html, :as => 'cms_html', :path => "#{prefix}/(*cms_path)" |
| + | get 'cms-css/:id' => :render_css, :as => 'cms_css' |
| + | get 'cms-js/:id' => :render_js, :as => 'cms_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
-2
| @@ | @@ -5,10 +5,10 @@ class CreateCms < ActiveRecord::Migration |
| create_table :cms_sites do |t| | |
| t.string :label | |
| t.string :hostname | |
| - | t.string :path, :null => false, :default => '/' |
| + | t.string :path |
| t.boolean :is_mirrored, :null => false, :default => false | |
| end | |
| - | add_index :cms_sites, [:hostname, :path] |
| + | add_index :cms_sites, :hostname |
| add_index :cms_sites, :is_mirrored | |
| # -- Layouts ------------------------------------------------------------ | |
migrate/upgrades/04_upgrade_to_1_3_0.rb b/db/migrate/upgrades/04_upgrade_to_1_3_0.rb
+1
-5
| @@ | @@ -1,16 +1,12 @@ |
| class UpgradeTo130 < ActiveRecord::Migration | |
| def self.up | |
| add_column :cms_sites, :is_mirrored, :boolean, :null => false, :default => false | |
| - | add_column :cms_sites, :path, :string, :null => false, :default => '/' |
| - | remove_index :cms_sites, :hostname |
| - | add_index :cms_sites, [:hostname, :path] |
| + | add_column :cms_sites, :path, :string |
| add_index :cms_sites, :is_mirrored | |
| end | |
| def self.down | |
| - | remove_index :cms_sites, [:hostname, :path] |
| remove_index :cms_sites, :is_mirrored | |
| - | add_index :cms_sites, :hostname |
| remove_column :cms_sites, :path | |
| remove_column :cms_sites, :is_mirrored | |
| end | |
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb
+0
-5
| @@ | @@ -10,10 +10,6 @@ class ComfortableMexicanSofa::Configuration |
| # You can change 'cms-admin' to 'admin', for example. | |
| attr_accessor :admin_route_prefix | |
| - | # Default url to content directly is http://yourhost/ |
| - | # You can change '' to 'preview', for example. |
| - | attr_accessor :content_route_prefix |
| - | |
| # /cms-admin redirects to /cms-admin/pages but you can change it | |
| # to something else | |
| attr_accessor :admin_route_redirect | |
| @@ | @@ -47,7 +43,6 @@ class ComfortableMexicanSofa::Configuration |
| @seed_data_path = nil | |
| @admin_route_prefix = 'cms-admin' | |
| @admin_route_redirect = 'pages' | |
| - | @content_route_prefix = '' |
| @enable_multiple_sites = false | |
| @allow_irb = false | |
| @enable_caching = true | |
comfortable_mexican_sofa/tags/asset.rb b/lib/comfortable_mexican_sofa/tags/asset.rb
+2
-2
| @@ | @@ -13,11 +13,11 @@ class ComfortableMexicanSofa::Tag::Asset |
| case type | |
| when 'css' | |
| - | out = "#{ComfortableMexicanSofa.config.content_route_prefix}/cms-css/#{label}.css" |
| + | out = "#{page.site.path}/cms-css/#{label}.css" |
| out = "<link href='#{out}' media='screen' rel='stylesheet' type='text/css' />" if format == 'html_tag' | |
| out | |
| when 'js' | |
| - | out = "#{ComfortableMexicanSofa.config.content_route_prefix}/cms-js/#{label}.js" |
| + | out = "#{page.site.path}/cms-js/#{label}.js" |
| out = "<script src='#{out}' type='text/javascript'></script>" if format == 'html_tag' | |
| out | |
| end | |
test/fixtures/cms/sites.yml
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| default: | |
| label: Default Site | |
| hostname: test.host | |
| - | path: / |
| + | path: |
| is_mirrored: false | |
| \ No newline at end of file | |
test/integration/routing_extensions_test.rb
+0
-15
| @@ | @@ -7,21 +7,6 @@ class RoutingExtensionsTest < ActionDispatch::IntegrationTest |
| load(File.expand_path('config/routes.rb', Rails.root)) | |
| end | |
| - | def test_get_public_with_content_route_prefix |
| - | ComfortableMexicanSofa.config.content_route_prefix = 'custom' |
| - | load(File.expand_path('config/routes.rb', Rails.root)) |
| - | |
| - | get '/custom' |
| - | assert_response :success |
| - | assert assigns(:cms_page) |
| - | assert_equal '/', assigns(:cms_page).full_path |
| - | |
| - | get '/custom/child-page' |
| - | assert_response :success |
| - | assert assigns(:cms_page) |
| - | assert_equal '/child-page', assigns(:cms_page).full_path |
| - | end |
| - | |
| def test_get_admin_with_admin_route_prefix | |
| ComfortableMexicanSofa.config.admin_route_prefix = 'custom-admin' | |
| load(File.expand_path('config/routes.rb', Rails.root)) | |
test/test_helper.rb
+0
-1
| @@ | @@ -17,7 +17,6 @@ class ActiveSupport::TestCase |
| config.cms_title = 'ComfortableMexicanSofa MicroCMS' | |
| config.authentication = 'ComfortableMexicanSofa::HttpAuth' | |
| config.admin_route_prefix = 'cms-admin' | |
| - | config.content_route_prefix = '' |
| config.admin_route_redirect = 'pages' | |
| config.enable_multiple_sites = false | |
| config.allow_irb = false | |
test/unit/configuration_test.rb
+0
-1
| @@ | @@ -7,7 +7,6 @@ class ConfigurationTest < ActiveSupport::TestCase |
| assert_equal 'ComfortableMexicanSofa MicroCMS', config.cms_title | |
| assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication | |
| assert_equal 'cms-admin', config.admin_route_prefix | |
| - | assert_equal '', config.content_route_prefix |
| assert_equal 'pages', config.admin_route_redirect | |
| assert_equal false, config.enable_multiple_sites | |
| assert_equal false, config.allow_irb | |
test/unit/models/site_test.rb
+2
-7
| @@ | @@ -19,10 +19,6 @@ class CmsSiteTest < ActiveSupport::TestCase |
| site = Cms::Site.new(:label => 'My Site', :hostname => 'my-site.host') | |
| assert site.valid? | |
| - | |
| - | site = Cms::Site.new(:hostname => 'test.host', :path => 'invalid') |
| - | assert site.invalid? |
| - | assert_has_errors_on site, :path |
| end | |
| def test_validation_path_uniqueness | |
| @@ | @@ -41,11 +37,10 @@ class CmsSiteTest < ActiveSupport::TestCase |
| assert s2.valid? | |
| end | |
| - | def test_label_and_path_assignment |
| + | def test_label_assignment |
| site = Cms::Site.new(:hostname => 'my-site.host') | |
| assert site.valid? | |
| assert_equal 'my-site.host', site.label | |
| - | assert_equal '/', site.path |
| end | |
| def test_clean_path | |
| @@ | @@ -53,7 +48,7 @@ class CmsSiteTest < ActiveSupport::TestCase |
| assert_equal '/en/test', site.path | |
| site = Cms::Site.create!(:hostname => 'my-site.host', :path => '/') | |
| - | assert_equal '/', site.path |
| + | assert_equal '', site.path |
| end | |
| def test_cascading_destroy | |