comfortable_mexican_sofa 1.0.30 → 1.0.31

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,4 +7,7 @@ db/schema.rb
7
7
  db/development_structure.sql
8
8
  public/system/*
9
9
  pkg
10
- rdoc
10
+ rdoc
11
+ /tmp
12
+ public/cms-css/
13
+ public/cms-js/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.30
1
+ 1.0.31
@@ -3,7 +3,9 @@ class CmsContentController < ApplicationController
3
3
  before_filter :load_cms_site
4
4
  before_filter :load_cms_page, :only => :render_html
5
5
  before_filter :load_cms_layout, :only => [:render_css, :render_js]
6
-
6
+
7
+ caches_page :render_css, :render_js
8
+
7
9
  def render_html(status = 200)
8
10
  layout = @cms_page.cms_layout.app_layout.blank?? false : @cms_page.cms_layout.app_layout
9
11
  render :inline => @cms_page.content, :layout => layout, :status => status
@@ -6,6 +6,10 @@ class CmsLayout < ActiveRecord::Base
6
6
  belongs_to :cms_site
7
7
  has_many :cms_pages, :dependent => :nullify
8
8
 
9
+ # -- Callbacks ------------------------------------------------------------
10
+ after_save :clear_cache, :clear_cached_page_content
11
+ after_destroy :clear_cache, :clear_cached_page_content
12
+
9
13
  # -- Validations ----------------------------------------------------------
10
14
  validates :cms_site_id,
11
15
  :presence => true
@@ -17,8 +21,7 @@ class CmsLayout < ActiveRecord::Base
17
21
  :format => { :with => /^\w[a-z0-9_-]*$/i }
18
22
  validates :content,
19
23
  :presence => true
20
-
21
- validate :content_tag_presence
24
+ validate :check_content_tag_presence
22
25
 
23
26
  # -- Class Methods --------------------------------------------------------
24
27
  # Tree-like structure for layouts
@@ -98,11 +101,24 @@ class CmsLayout < ActiveRecord::Base
98
101
 
99
102
  protected
100
103
 
101
- def content_tag_presence
104
+ def check_content_tag_presence
102
105
  CmsTag.process_content((test_page = CmsPage.new), content)
103
106
  if test_page.cms_tags.select{|t| t.class.superclass == CmsBlock}.blank?
104
107
  self.errors.add(:content, 'No cms page tags defined')
105
108
  end
106
109
  end
107
110
 
111
+ # After saving need to make sure that cached pages for css and js for this
112
+ # layout and its children are gone. Good enough to avoid using cache sweepers.
113
+ def clear_cache
114
+ FileUtils.rm File.expand_path("cms-css/#{self.slug}.css", Rails.public_path), :force => true
115
+ FileUtils.rm File.expand_path("cms-js/#{self.slug}.js", Rails.public_path), :force => true
116
+ self.children.each{ |child| child.save! }
117
+ end
118
+
119
+ # Forcing page content reload. This will happen in cascade due to #clear_cache mathod above.
120
+ def clear_cached_page_content
121
+ self.cms_pages.each{ |page| page.save! }
122
+ end
123
+
108
124
  end
@@ -17,6 +17,7 @@ class CmsPage < ActiveRecord::Base
17
17
  # -- Callbacks ------------------------------------------------------------
18
18
  before_validation :assign_parent,
19
19
  :assign_full_path
20
+ before_save :set_cached_content
20
21
  after_save :sync_child_pages
21
22
 
22
23
  # -- Validations ----------------------------------------------------------
@@ -93,15 +94,19 @@ class CmsPage < ActiveRecord::Base
93
94
 
94
95
  # Processing content will return rendered content and will populate
95
96
  # self.cms_tags with instances of CmsTag
96
- def content
97
- self.cms_tags = [] # resetting
98
- cms_layout ? CmsTag.process_content(self, cms_layout.merged_content) : ''
97
+ def content(force_reload = false)
98
+ @content = read_attribute(:content)
99
+ @content = nil if force_reload
100
+ @content ||= begin
101
+ self.cms_tags = [] # resetting
102
+ cms_layout ? CmsTag.process_content(self, cms_layout.merged_content) : ''
103
+ end
99
104
  end
100
105
 
101
106
  # Array of cms_tags for a page. Content generation is called if forced.
102
107
  # These also include initialized cms_blocks if present
103
- def cms_tags(force = false)
104
- self.content if force
108
+ def cms_tags(force_reload = false)
109
+ self.content(true) if force_reload
105
110
  @cms_tags ||= []
106
111
  end
107
112
 
@@ -123,6 +128,10 @@ protected
123
128
  end
124
129
  end
125
130
 
131
+ def set_cached_content
132
+ write_attribute(:content, self.content(true))
133
+ end
134
+
126
135
  # Forcing re-saves for child pages so they can update full_paths
127
136
  def sync_child_pages
128
137
  children.each{ |p| p.save! } if full_path_changed?
@@ -3,6 +3,10 @@ class CmsSnippet < ActiveRecord::Base
3
3
  # -- Relationships --------------------------------------------------------
4
4
  belongs_to :cms_site
5
5
 
6
+ # -- Callbacks ------------------------------------------------------------
7
+ after_save :clear_cached_page_content
8
+ after_destroy :clear_cached_page_content
9
+
6
10
  # -- Validations ----------------------------------------------------------
7
11
  validates :cms_site_id,
8
12
  :presence => true
@@ -51,4 +55,13 @@ class CmsSnippet < ActiveRecord::Base
51
55
  nil
52
56
  end
53
57
 
58
+ protected
59
+
60
+ # Note: This might be slow. We have no idea where the snippet is used, so
61
+ # gotta reload every single page. Kinda sucks, but might be ok unless there
62
+ # are hundreds of pages.
63
+ def clear_cached_page_content
64
+ CmsPage.all.each{ |page| page.save! }
65
+ end
66
+
54
67
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{comfortable_mexican_sofa}
8
- s.version = "1.0.30"
8
+ s.version = "1.0.31"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov", "The Working Group Inc"]
12
- s.date = %q{2010-11-25}
12
+ s.date = %q{2010-11-29}
13
13
  s.description = %q{}
14
14
  s.email = %q{oleg@theworkinggroup.ca}
15
15
  s.extra_rdoc_files = [
@@ -8,6 +8,15 @@ default:
8
8
  full_path: '/'
9
9
  children_count: 1
10
10
  position: 0
11
+ content: |-
12
+
13
+ layout_content_a
14
+ default_page_text_content_a
15
+ default_snippet_content
16
+ default_page_text_content_b
17
+ layout_content_b
18
+ default_snippet_content
19
+ layout_content_c
11
20
 
12
21
  child:
13
22
  cms_site: default
@@ -19,3 +28,10 @@ child:
19
28
  full_path: '/child-page'
20
29
  children_count: 0
21
30
  position: 0
31
+ content: |-
32
+
33
+ layout_content_a
34
+
35
+ layout_content_b
36
+ default_snippet_content
37
+ layout_content_c
@@ -36,6 +36,23 @@ class CmsLayoutTest < ActiveSupport::TestCase
36
36
  assert layout.valid?
37
37
  end
38
38
 
39
+ def test_creation
40
+ assert_difference 'CmsLayout.count' do
41
+ layout = cms_sites(:default).cms_layouts.create(
42
+ :label => 'New Layout',
43
+ :slug => 'new-layout',
44
+ :content => '{{cms:page:content}}',
45
+ :css => 'css',
46
+ :js => 'js'
47
+ )
48
+ assert_equal 'New Layout', layout.label
49
+ assert_equal 'new-layout', layout.slug
50
+ assert_equal '{{cms:page:content}}', layout.content
51
+ assert_equal 'css', layout.css
52
+ assert_equal 'js', layout.js
53
+ end
54
+ end
55
+
39
56
  def test_options_for_select
40
57
  assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'],
41
58
  CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first}
@@ -117,4 +134,13 @@ class CmsLayoutTest < ActiveSupport::TestCase
117
134
  assert !CmsLayout.load_for_slug(cms_sites(:default), 'not_found')
118
135
  end
119
136
 
137
+ def test_update_forces_page_content_reload
138
+ layout = cms_layouts(:default)
139
+ page = cms_pages(:default)
140
+ assert_equal layout, page.cms_layout
141
+ layout.update_attribute(:content, 'updated {{cms:page:default_page_text:text}} updated')
142
+ page.reload
143
+ assert_equal "updated default_page_text_content_a\ndefault_snippet_content\ndefault_page_text_content_b updated", page.content
144
+ end
145
+
120
146
  end
@@ -5,6 +5,7 @@ class CmsPageTest < ActiveSupport::TestCase
5
5
  def test_fixtures_validity
6
6
  CmsPage.all.each do |page|
7
7
  assert page.valid?, page.errors.full_messages
8
+ assert_equal page.read_attribute(:content), page.content(true)
8
9
  end
9
10
  end
10
11
 
@@ -189,6 +190,17 @@ class CmsPageTest < ActiveSupport::TestCase
189
190
  assert page.cms_blocks_attributes.first[:id]
190
191
  end
191
192
 
193
+ def test_content_caching
194
+ page = cms_pages(:default)
195
+ assert_equal page.read_attribute(:content), page.content
196
+ assert_equal page.read_attribute(:content), page.content(true)
197
+
198
+ page.update_attribute(:content, 'changed')
199
+ assert_equal page.read_attribute(:content), page.content
200
+ assert_equal page.read_attribute(:content), page.content(true)
201
+ assert_not_equal 'changed', page.read_attribute(:content)
202
+ end
203
+
192
204
  protected
193
205
 
194
206
  def new_params(options = {})
@@ -57,4 +57,13 @@ class CmsSnippetTest < ActiveSupport::TestCase
57
57
  assert !CmsSnippet.load_for_slug(cms_sites(:default), 'not_found')
58
58
  end
59
59
 
60
+ def test_update_forces_page_content_reload
61
+ snippet = cms_snippets(:default)
62
+ page = cms_pages(:default)
63
+ assert_match snippet.content, page.content
64
+ snippet.update_attribute(:content, 'new_snippet_content')
65
+ page.reload
66
+ assert_match /new_snippet_content/, page.content
67
+ end
68
+
60
69
  end
@@ -78,7 +78,7 @@ class CmsTagTest < ActiveSupport::TestCase
78
78
  layout_content_b
79
79
  default_snippet_content
80
80
  layout_content_c'
81
- ), page.content
81
+ ), page.content(true)
82
82
 
83
83
  assert_equal 4, page.cms_tags.size
84
84
  assert_equal 'cms_tag/field_text_default_field_text', page.cms_tags[0].identifier
@@ -173,7 +173,7 @@ class CmsTagTest < ActiveSupport::TestCase
173
173
  default_page_text_content_a
174
174
  default_snippet_content
175
175
  default_page_text_content_b'
176
- ), page.content
176
+ ), page.content(true)
177
177
 
178
178
  assert_equal 6, page.cms_tags.size
179
179
  assert_equal 'cms_tag/field_text_default_field_text', page.cms_tags[0].identifier
@@ -199,7 +199,7 @@ class CmsTagTest < ActiveSupport::TestCase
199
199
  layout_content_b
200
200
  infinite loop
201
201
  layout_content_c'
202
- ), page.content
202
+ ), page.content(true)
203
203
  assert_equal 6, page.cms_tags.size
204
204
  end
205
205
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 30
10
- version: 1.0.30
9
+ - 31
10
+ version: 1.0.31
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oleg Khabarov
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-25 00:00:00 -05:00
19
+ date: 2010-11-29 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency