comfortable_mexican_sofa 1.4.20 → 1.4.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  # - 1.9.3
5
- - rbx-2.0
5
+ # - rbx-2.0
6
6
  - ree
7
7
  # - jruby
8
8
  gemfile:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.20
1
+ 1.4.21
@@ -101,6 +101,9 @@ protected
101
101
  def preview_cms_page
102
102
  if params[:preview]
103
103
  layout = @page.layout.app_layout.blank?? false : @page.layout.app_layout
104
+ @cms_site = @page.site
105
+ @cms_layout = @page.layout
106
+ @cms_page = @page
104
107
  render :inline => @page.content(true), :layout => layout
105
108
  end
106
109
  end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{comfortable_mexican_sofa}
8
- s.version = "1.4.20"
7
+ s.name = "comfortable_mexican_sofa"
8
+ s.version = "1.4.21"
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{2011-09-24}
13
- s.description = %q{}
14
- s.email = %q{oleg@theworkinggroup.ca}
12
+ s.date = "2011-09-26"
13
+ s.description = ""
14
+ s.email = "oleg@theworkinggroup.ca"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.md"
@@ -300,10 +300,10 @@ Gem::Specification.new do |s|
300
300
  "test/unit/tags/snippet_test.rb",
301
301
  "test/unit/view_methods_test.rb"
302
302
  ]
303
- s.homepage = %q{http://github.com/twg/comfortable-mexican-sofa}
303
+ s.homepage = "http://github.com/twg/comfortable-mexican-sofa"
304
304
  s.require_paths = ["lib"]
305
- s.rubygems_version = %q{1.6.2}
306
- s.summary = %q{ComfortableMexicanSofa is a powerful CMS Engine for Ruby on Rails 3 applications}
305
+ s.rubygems_version = "1.8.10"
306
+ s.summary = "ComfortableMexicanSofa is a powerful CMS Engine for Ruby on Rails 3 applications"
307
307
 
308
308
  if s.respond_to? :specification_version then
309
309
  s.specification_version = 3
@@ -120,7 +120,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
120
120
 
121
121
  def collection(tag)
122
122
  options = [["---- Select #{tag.collection_class.titleize} ----", nil]] +
123
- tag.collection_class.constantize.all.collect do |m|
123
+ tag.collection_objects.collect do |m|
124
124
  [m.send(tag.collection_title), m.send(tag.collection_identifier)]
125
125
  end
126
126
 
@@ -130,7 +130,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
130
130
  :id => nil
131
131
  )
132
132
  content << @template.hidden_field_tag('page[blocks_attributes][][label]', tag.label, :id => nil)
133
- simple_field(tag.collection_class.titleize, content, :class => tag.class.to_s.demodulize.underscore )
133
+ simple_field(tag.label, content, :class => tag.class.to_s.demodulize.underscore )
134
134
  end
135
135
 
136
136
  end
@@ -1,36 +1,50 @@
1
1
  class ComfortableMexicanSofa::Tag::Collection
2
2
  include ComfortableMexicanSofa::Tag
3
3
 
4
- # Simple example for Albums collection rendered out by albums/show partial
5
- # making assumtion that we will use `label` and `id` as Album attributes
6
- # {{ cms:collection:Album:albums/show }}
7
- # If Album uses `title` and `slug` tag will look as follows:
8
- # {{ cms:collection:Album:albums/show:title:slug }}
9
- # If you need to send more paramers to the partial just attach them as such:
10
- # {{ cms:collection:Album:albums/show:title:slug:param_a:param_b }}
4
+ # Here's a full tag signature:
5
+ # {{ cms:collection:label:collection_class:collection_partial:collection_title:collection_identifier:collection_params }}
6
+ # Most minimal tag can look like this:
7
+ # {{ cms:collection:album:foo/my_album }}
8
+ # A more complete example of the above:
9
+ # {{ cms:collection:album:foo/my_album:albums/show:title:slug:param_a:param_b }}
11
10
  def self.regex_tag_signature(label = nil)
12
11
  label ||= /[\w\/\-]+/
13
- /\{\{\s*cms:collection:(#{label}):([\w\/\-\:]+)\s*\}\}/
12
+ /\{\{\s*cms:collection:(#{label}):(.*?)\s*\}\}/
14
13
  end
15
14
 
16
- def collection_partial
17
- self.params.first
15
+ # Class definitition. It's basically `Herp::DerpityDerp.undescore` so an example
16
+ # of valid definition is: `herp/derpity_derp`
17
+ def collection_class
18
+ self.params[0].classify
18
19
  end
19
20
 
20
- def collection_class
21
- label.classify
21
+ # Path to the partial. Example: `path/to/partial`
22
+ def collection_partial
23
+ self.params[1] || self.collection_class.underscore.pluralize
22
24
  end
23
25
 
26
+ # Title method for the Collection objects. Default is `label`
24
27
  def collection_title
25
- self.params[1] || 'label'
28
+ self.params[2] || 'label'
26
29
  end
27
30
 
31
+ # Identifier that will be used to find selected collection object. Defaults to `id`
28
32
  def collection_identifier
29
- self.params[2] || 'id'
33
+ self.params[3] || 'id'
30
34
  end
31
35
 
36
+ # Extra params that will be passed to the partial AND ALSO will be passed as parameters
37
+ # for the `cms_collection` scope you can define for your Collection object
32
38
  def collection_params
33
- self.params[3..-1] || []
39
+ self.params[4..-1] || []
40
+ end
41
+
42
+ # Array of objects used in the collection
43
+ # You may set up a scope on the model `scope :cms_collection, lambda|*args| do ... end `
44
+ # `args` will be the set of `collection_params`
45
+ def collection_objects
46
+ klass = self.collection_class.constantize
47
+ klass.respond_to?(:cms_collection) ? klass.cms_collection(*collection_params).all : klass.all
34
48
  end
35
49
 
36
50
  def content=(value)
@@ -104,13 +104,13 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
104
104
 
105
105
  def test_get_new_with_collection
106
106
  snippet = cms_snippets(:default)
107
- cms_layouts(:default).update_attribute(:content, '{{cms:collection:cms/snippet:snippets/show}}')
107
+ cms_layouts(:default).update_attribute(:content, '{{cms:collection:snippet:cms/snippet}}')
108
108
  get :new, :site_id => cms_sites(:default)
109
109
  assert_select "select[name='page[blocks_attributes][][content]']" do
110
110
  assert_select "option[value='']", :html => '---- Select Cms/Snippet ----'
111
111
  assert_select "option[value='#{snippet.id}']", :html => snippet.label
112
112
  end
113
- assert_select "input[type='hidden'][name='page[blocks_attributes][][label]'][value='cms/snippet']"
113
+ assert_select "input[type='hidden'][name='page[blocks_attributes][][label]'][value='snippet']"
114
114
  end
115
115
 
116
116
  def test_get_new_with_rich_page_text
@@ -280,12 +280,15 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
280
280
  end
281
281
 
282
282
  def test_creation_preview
283
+ site = cms_sites(:default)
284
+ layout = cms_layouts(:default)
285
+
283
286
  assert_no_difference 'Cms::Page.count' do
284
- post :create, :site_id => cms_sites(:default), :preview => 'Preview', :page => {
287
+ post :create, :site_id => site, :preview => 'Preview', :page => {
285
288
  :label => 'Test Page',
286
289
  :slug => 'test-page',
287
290
  :parent_id => cms_pages(:default).id,
288
- :layout_id => cms_layouts(:default).id,
291
+ :layout_id => layout.id,
289
292
  :blocks_attributes => [
290
293
  { :label => 'default_page_text',
291
294
  :content => 'preview content' }
@@ -293,6 +296,11 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
293
296
  }
294
297
  assert_response :success
295
298
  assert_match /preview content/, response.body
299
+
300
+ assert_equal site, assigns(:cms_site)
301
+ assert_equal layout, assigns(:cms_layout)
302
+ assert assigns(:cms_page)
303
+ assert assigns(:cms_page).new_record?
296
304
  end
297
305
  end
298
306
 
@@ -311,6 +319,10 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
311
319
  assert_match /preview content/, response.body
312
320
  page.reload
313
321
  assert_not_equal 'Updated Label', page.label
322
+
323
+ assert_equal page.site, assigns(:cms_site)
324
+ assert_equal page.layout, assigns(:cms_layout)
325
+ assert_equal page, assigns(:cms_page)
314
326
  end
315
327
  end
316
328
 
@@ -226,7 +226,7 @@ class TagTest < ActiveSupport::TestCase
226
226
  site = cms_sites(:default)
227
227
  layout = site.layouts.create!(
228
228
  :slug => 'no-irb-layout',
229
- :content => '<% 1 + 1 %> {{cms:page:content}} {{cms:collection:cms/snippet:snippets/show}} <%= 1 + 1 %>'
229
+ :content => '<% 1 + 1 %> {{cms:page:content}} {{cms:collection:snippet:cms/snippet}} <%= 1 + 1 %>'
230
230
  )
231
231
  snippet = site.snippets.create!(
232
232
  :slug => 'no-irb-snippet',
@@ -239,11 +239,11 @@ class TagTest < ActiveSupport::TestCase
239
239
  :blocks_attributes => [
240
240
  { :label => 'content',
241
241
  :content => 'text {{ cms:snippet:no-irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' },
242
- { :label => 'cms/snippet',
242
+ { :label => 'snippet',
243
243
  :content => snippet.id }
244
244
  ]
245
245
  )
246
- assert_equal "&lt;% 1 + 1 %&gt; text &lt;% 2 + 2 %&gt; snippet &lt;%= 2 + 2 %&gt; <%= render :partial => 'path/to' %> <%= method() %> text <%= render :partial => 'snippets/show', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %> &lt;%= 1 + 1 %&gt;", page.content
246
+ assert_equal "&lt;% 1 + 1 %&gt; text &lt;% 2 + 2 %&gt; snippet &lt;%= 2 + 2 %&gt; <%= render :partial => 'path/to' %> <%= method() %> text <%= render :partial => 'cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %> &lt;%= 1 + 1 %&gt;", page.content
247
247
  end
248
248
 
249
249
  def test_content_with_irb_enabled
@@ -252,7 +252,7 @@ class TagTest < ActiveSupport::TestCase
252
252
  site = cms_sites(:default)
253
253
  layout = site.layouts.create!(
254
254
  :slug => 'irb-layout',
255
- :content => '<% 1 + 1 %> {{cms:page:content}} {{cms:collection:cms/snippet:snippets/show}} <%= 1 + 1 %>'
255
+ :content => '<% 1 + 1 %> {{cms:page:content}} {{cms:collection:snippet:cms/snippet}} <%= 1 + 1 %>'
256
256
  )
257
257
  snippet = site.snippets.create!(
258
258
  :slug => 'irb-snippet',
@@ -265,11 +265,11 @@ class TagTest < ActiveSupport::TestCase
265
265
  :blocks_attributes => [
266
266
  { :label => 'content',
267
267
  :content => 'text {{ cms:snippet:irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' },
268
- { :label => 'cms/snippet',
268
+ { :label => 'snippet',
269
269
  :content => snippet.id }
270
270
  ]
271
271
  )
272
- assert_equal "<% 1 + 1 %> text <% 2 + 2 %> snippet <%= 2 + 2 %> <%= render :partial => 'path/to' %> <%= method() %> text <%= render :partial => 'snippets/show', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %> <%= 1 + 1 %>", page.content
272
+ assert_equal "<% 1 + 1 %> text <% 2 + 2 %> snippet <%= 2 + 2 %> <%= render :partial => 'path/to' %> <%= method() %> text <%= render :partial => 'cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %> <%= 1 + 1 %>", page.content
273
273
  end
274
274
 
275
275
  end
@@ -2,13 +2,20 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
2
 
3
3
  class CollectionTagTest < ActiveSupport::TestCase
4
4
 
5
+ module TestCollectionScope
6
+ def self.included(base)
7
+ base.scope :cms_collection, lambda{|*args| base.where(:slug => args.first) if args.first }
8
+ end
9
+ end
10
+ Cms::Snippet.send(:include, TestCollectionScope)
11
+
5
12
  def test_initialize_tag
6
13
  assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
7
- cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial }}'
14
+ cms_pages(:default), '{{ cms:collection:snippet:cms/snippet }}'
8
15
  )
9
- assert_equal 'cms/snippet', tag.label
16
+ assert_equal 'snippet', tag.label
10
17
  assert_equal 'Cms::Snippet', tag.collection_class
11
- assert_equal 'path/to/partial', tag.collection_partial
18
+ assert_equal 'cms/snippets', tag.collection_partial
12
19
  assert_equal 'label', tag.collection_title
13
20
  assert_equal 'id', tag.collection_identifier
14
21
  assert_equal [], tag.collection_params
@@ -16,9 +23,9 @@ class CollectionTagTest < ActiveSupport::TestCase
16
23
 
17
24
  def test_initialize_tag_detailed
18
25
  assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
19
- cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial:title:slug:param_a:param_b }}'
26
+ cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial:title:slug:param_a:param_b }}'
20
27
  )
21
- assert_equal 'cms/snippet', tag.label
28
+ assert_equal 'snippet', tag.label
22
29
  assert_equal 'Cms::Snippet', tag.collection_class
23
30
  assert_equal 'path/to/partial', tag.collection_partial
24
31
  assert_equal 'title', tag.collection_title
@@ -30,7 +37,7 @@ class CollectionTagTest < ActiveSupport::TestCase
30
37
  [
31
38
  '{{cms:collection}}',
32
39
  '{{cms:collection:label}}',
33
- '{{cms:not_collection:label:partial}}',
40
+ '{{cms:not_collection:label:class:partial}}',
34
41
  '{not_a_tag}'
35
42
  ].each do |tag_signature|
36
43
  assert_nil ComfortableMexicanSofa::Tag::Collection.initialize_tag(
@@ -39,9 +46,33 @@ class CollectionTagTest < ActiveSupport::TestCase
39
46
  end
40
47
  end
41
48
 
49
+ def test_collection_objects
50
+ assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
51
+ cms_pages(:default), '{{ cms:collection:snippet:cms/snippet }}'
52
+ )
53
+ assert snippets = tag.collection_objects
54
+ assert_equal 1, snippets.count
55
+ assert snippets.first.is_a?(Cms::Snippet)
56
+ end
57
+
58
+ def test_collection_objects_with_scope
59
+ assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
60
+ cms_pages(:default), "{{ cms:collection:snippet:cms/snippet:path/to/partial:label:slug:#{cms_snippets(:default).slug} }}"
61
+ )
62
+ assert snippets = tag.collection_objects
63
+ assert_equal 1, snippets.count
64
+ assert snippets.first.is_a?(Cms::Snippet)
65
+
66
+ assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
67
+ cms_pages(:default), "{{ cms:collection:snippet:cms/snippet:path/to/partial:label:slug:invalid }}"
68
+ )
69
+ assert snippets = tag.collection_objects
70
+ assert_equal 0, snippets.count
71
+ end
72
+
42
73
  def test_content_and_render
43
- tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
44
- cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial }}'
74
+ assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
75
+ cms_pages(:default), '{{ cms:collection:snippet:cms/snippet }}'
45
76
  )
46
77
  assert tag.content.blank?
47
78
 
@@ -49,12 +80,12 @@ class CollectionTagTest < ActiveSupport::TestCase
49
80
  tag.content = snippet.id
50
81
  assert_equal snippet.id, tag.block.content
51
82
  assert_equal snippet.id, tag.content
52
- assert_equal "<%= render :partial => 'path/to/partial', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %>", tag.render
83
+ assert_equal "<%= render :partial => 'cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %>", tag.render
53
84
  end
54
85
 
55
86
  def test_content_and_render_detailed
56
- tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
57
- cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial:label:slug:param_a:param_b }}'
87
+ assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
88
+ cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial:label:slug:param_a:param_b }}'
58
89
  )
59
90
  assert tag.content.blank?
60
91
 
@@ -66,8 +97,8 @@ class CollectionTagTest < ActiveSupport::TestCase
66
97
  end
67
98
 
68
99
  def test_content_and_render_with_no_content
69
- tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
70
- cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial }}'
100
+ assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
101
+ cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial }}'
71
102
  )
72
103
  assert tag.content.blank?
73
104
  assert_equal '', tag.render
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.20
4
+ version: 1.4.21
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-24 00:00:00.000000000 -04:00
14
- default_executable:
13
+ date: 2011-09-26 00:00:00.000000000Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rails
18
- requirement: &70220046708640 !ruby/object:Gem::Requirement
17
+ requirement: &70347786828380 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ! '>='
@@ -23,10 +22,10 @@ dependencies:
23
22
  version: 3.0.0
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *70220046708640
25
+ version_requirements: *70347786828380
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: active_link_to
29
- requirement: &70220046707420 !ruby/object:Gem::Requirement
28
+ requirement: &70347786827600 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ! '>='
@@ -34,10 +33,10 @@ dependencies:
34
33
  version: 1.0.0
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: *70220046707420
36
+ version_requirements: *70347786827600
38
37
  - !ruby/object:Gem::Dependency
39
38
  name: paperclip
40
- requirement: &70220046706160 !ruby/object:Gem::Requirement
39
+ requirement: &70347786826860 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ! '>='
@@ -45,7 +44,7 @@ dependencies:
45
44
  version: 2.3.14
46
45
  type: :runtime
47
46
  prerelease: false
48
- version_requirements: *70220046706160
47
+ version_requirements: *70347786826860
49
48
  description: ''
50
49
  email: oleg@theworkinggroup.ca
51
50
  executables: []
@@ -336,7 +335,6 @@ files:
336
335
  - test/unit/tags/partial_test.rb
337
336
  - test/unit/tags/snippet_test.rb
338
337
  - test/unit/view_methods_test.rb
339
- has_rdoc: true
340
338
  homepage: http://github.com/twg/comfortable-mexican-sofa
341
339
  licenses: []
342
340
  post_install_message:
@@ -351,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
351
349
  version: '0'
352
350
  segments:
353
351
  - 0
354
- hash: -2622555031626774518
352
+ hash: -4146543032644537540
355
353
  required_rubygems_version: !ruby/object:Gem::Requirement
356
354
  none: false
357
355
  requirements:
@@ -360,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
360
358
  version: '0'
361
359
  requirements: []
362
360
  rubyforge_project:
363
- rubygems_version: 1.6.2
361
+ rubygems_version: 1.8.10
364
362
  signing_key:
365
363
  specification_version: 3
366
364
  summary: ComfortableMexicanSofa is a powerful CMS Engine for Ruby on Rails 3 applications