mirrors wip
Oleg
committed May 13, 2011
commit e282134eddf60d4194c1e02e6af8aeec6eec1b5a
Showing 8
changed files with
57 additions
and 13 deletions
Gemfile
+1
-0
| @@ | @@ -11,4 +11,5 @@ end |
| group :test do | |
| gem 'sqlite3' | |
| gem 'jeweler', '>=1.4.0' | |
| + | gem 'turn' |
| end | |
app/models/cms/layout.rb
+1
-1
| @@ | @@ -3,7 +3,7 @@ class Cms::Layout < ActiveRecord::Base |
| set_table_name :cms_layouts | |
| acts_as_tree | |
| - | |
| + | is_mirrored |
| has_revisions_for :content, :css, :js | |
| # -- Relationships -------------------------------------------------------- | |
app/models/cms/page.rb
+1
-1
| @@ | @@ -3,7 +3,7 @@ class Cms::Page < ActiveRecord::Base |
| set_table_name :cms_pages | |
| acts_as_tree :counter_cache => :children_count | |
| - | |
| + | # is_mirrored |
| has_revisions_for :blocks_attributes | |
| attr_accessor :tags, | |
app/models/cms/snippet.rb
+1
-1
| @@ | @@ -1,7 +1,7 @@ |
| class Cms::Snippet < ActiveRecord::Base | |
| set_table_name :cms_snippets | |
| - | |
| + | is_mirrored |
| has_revisions_for :content | |
| # -- Relationships -------------------------------------------------------- | |
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb
+1
-0
| @@ | @@ -13,6 +13,7 @@ end |
| 'comfortable_mexican_sofa/form_builder', | |
| 'comfortable_mexican_sofa/acts_as_tree', | |
| 'comfortable_mexican_sofa/has_revisions', | |
| + | 'comfortable_mexican_sofa/is_mirrored', |
| 'comfortable_mexican_sofa/tag', | |
| 'comfortable_mexican_sofa/fixtures' | |
| ].each do |path| | |
comfortable_mexican_sofa/is_mirrored.rb b/lib/comfortable_mexican_sofa/is_mirrored.rb
+48
-0
| @@ | @@ -0,0 +1,48 @@ |
| + | module ComfortableMexicanSofa::IsMirrored |
| + | |
| + | def self.included(base) |
| + | base.send :extend, ClassMethods |
| + | end |
| + | |
| + | module ClassMethods |
| + | |
| + | def is_mirrored |
| + | include ComfortableMexicanSofa::IsMirrored::InstanceMethods |
| + | |
| + | attr_accessor :is_mirrored |
| + | |
| + | after_save :sync_mirror |
| + | after_destroy :destroy_mirror |
| + | end |
| + | end |
| + | |
| + | module InstanceMethods |
| + | |
| + | def sync_mirror |
| + | return if self.is_mirrored |
| + | |
| + | Cms::Site.all.each do |site| |
| + | mirror = case self |
| + | when Cms::Layout |
| + | site.layouts.find_by_slug(self.slug) || site.layouts.new(:slug => self.slug) |
| + | when Cms::Page |
| + | |
| + | when Cms::Snippet |
| + | site.snippets.find_by_slug(self.slug) || site.snippets.new(:slug => self.slug) |
| + | end |
| + | |
| + | mirror.is_mirrored = true |
| + | mirror.save! |
| + | end |
| + | end |
| + | |
| + | def destroy_mirror |
| + | return if self.is_mirrored |
| + | |
| + | # TODO |
| + | end |
| + | end |
| + | |
| + | end |
| + | |
| + | ActiveRecord::Base.send :include, ComfortableMexicanSofa::IsMirrored |
| \ No newline at end of file | |
public/stylesheets/comfortable_mexican_sofa/structure.css
+1
-6
| @@ | @@ -15,8 +15,6 @@ html, body { |
| margin: 0px 250px 0px 175px; | |
| min-height: 100%; | |
| background-color: #D8D8D8; | |
| - | border-left: 1px solid #484848; |
| - | border-right: 1px solid #484848; |
| } | |
| .center_column .center_column_content { | |
| padding: 25px; | |
| @@ | @@ -69,19 +67,16 @@ html, body { |
| overflow: hidden; | |
| color: #fff; | |
| } | |
| - | |
| /* -- Flash Messages ----------------------------------------------------- */ | |
| .flash { | |
| text-align: center; | |
| - | line-height: 25px; |
| + | padding: 8px; |
| color: #fff; | |
| background-color: #066B12; | |
| - | margin: 0px 2px; |
| } | |
| .flash.error { | |
| background-color: #9e0b0f; | |
| } | |
| - | |
| /* -- Buttons ------------------------------------------------------------ */ | |
| a.button, | |
| button, | |
test/unit/mirror_sites_test.rb
+3
-4
| @@ | @@ -4,17 +4,16 @@ class MirrorSitesTest < ActiveSupport::TestCase |
| def setup | |
| ComfortableMexicanSofa.config.enable_mirror_sites = true | |
| - | Cms::Site.destroy_all |
| + | Cms::Site.delete_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_a.layouts.create!(:slug => 'default') |
| @site_b.reload | |
| - | assert_equal 1, @site_b.layouts.count |
| - | layout = @site_b.layouts.first |
| + | assert layout = @site_b.layouts.first |
| assert_equal 'default', layout.slug | |
| end | |
| end | |