comfortable_mexican_sofa 1.4.19 → 1.4.20
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/comfortable_mexican_sofa.gemspec +5 -3
- data/lib/comfortable_mexican_sofa/form_builder.rb +17 -10
- data/lib/comfortable_mexican_sofa/tag.rb +1 -1
- data/lib/comfortable_mexican_sofa/tags/collection.rb +54 -0
- data/test/functional/cms_admin/pages_controller_test.rb +11 -0
- data/test/unit/tag_test.rb +10 -6
- data/test/unit/tags/collection_test.rb +76 -0
- data/test/unit/tags/{page_rich_text.rb → page_rich_text_test.rb} +0 -0
- metadata +12 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.20
|
@@ -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.4.
|
8
|
+
s.version = "1.4.20"
|
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-
|
12
|
+
s.date = %q{2011-09-24}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{oleg@theworkinggroup.ca}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -218,6 +218,7 @@ Gem::Specification.new do |s|
|
|
218
218
|
"lib/comfortable_mexican_sofa/form_builder.rb",
|
219
219
|
"lib/comfortable_mexican_sofa/tag.rb",
|
220
220
|
"lib/comfortable_mexican_sofa/tags/asset.rb",
|
221
|
+
"lib/comfortable_mexican_sofa/tags/collection.rb",
|
221
222
|
"lib/comfortable_mexican_sofa/tags/field_datetime.rb",
|
222
223
|
"lib/comfortable_mexican_sofa/tags/field_integer.rb",
|
223
224
|
"lib/comfortable_mexican_sofa/tags/field_string.rb",
|
@@ -283,6 +284,7 @@ Gem::Specification.new do |s|
|
|
283
284
|
"test/unit/revisions_test.rb",
|
284
285
|
"test/unit/tag_test.rb",
|
285
286
|
"test/unit/tags/asset_test.rb",
|
287
|
+
"test/unit/tags/collection_test.rb",
|
286
288
|
"test/unit/tags/field_datetime_test.rb",
|
287
289
|
"test/unit/tags/field_integer_test.rb",
|
288
290
|
"test/unit/tags/field_string_test.rb",
|
@@ -291,7 +293,7 @@ Gem::Specification.new do |s|
|
|
291
293
|
"test/unit/tags/helper_test.rb",
|
292
294
|
"test/unit/tags/page_datetime_test.rb",
|
293
295
|
"test/unit/tags/page_integer_test.rb",
|
294
|
-
"test/unit/tags/
|
296
|
+
"test/unit/tags/page_rich_text_test.rb",
|
295
297
|
"test/unit/tags/page_string_test.rb",
|
296
298
|
"test/unit/tags/page_text_test.rb",
|
297
299
|
"test/unit/tags/partial_test.rb",
|
@@ -78,16 +78,8 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
|
|
78
78
|
:id => nil,
|
79
79
|
:class => field_css_class
|
80
80
|
)
|
81
|
-
|
82
|
-
|
83
|
-
<div class='form_element #{css_class}'>
|
84
|
-
<div class='label'>#{label}</div>
|
85
|
-
<div class='value'>
|
86
|
-
#{field}
|
87
|
-
#{@template.hidden_field_tag('page[blocks_attributes][][label]', tag.label, :id => nil)}
|
88
|
-
</div>
|
89
|
-
</div>
|
90
|
-
).html_safe
|
81
|
+
content = "#{field} #{@template.hidden_field_tag('page[blocks_attributes][][label]', tag.label, :id => nil)}"
|
82
|
+
simple_field(label, content, :class => css_class)
|
91
83
|
end
|
92
84
|
|
93
85
|
def field_date_time(tag)
|
@@ -126,4 +118,19 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
|
|
126
118
|
default_tag_field(tag, :content_field_method => :text_area_tag)
|
127
119
|
end
|
128
120
|
|
121
|
+
def collection(tag)
|
122
|
+
options = [["---- Select #{tag.collection_class.titleize} ----", nil]] +
|
123
|
+
tag.collection_class.constantize.all.collect do |m|
|
124
|
+
[m.send(tag.collection_title), m.send(tag.collection_identifier)]
|
125
|
+
end
|
126
|
+
|
127
|
+
content = @template.select_tag(
|
128
|
+
'page[blocks_attributes][][content]',
|
129
|
+
@template.options_for_select(options, :selected => tag.content),
|
130
|
+
:id => nil
|
131
|
+
)
|
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 )
|
134
|
+
end
|
135
|
+
|
129
136
|
end
|
@@ -88,7 +88,7 @@ module ComfortableMexicanSofa::Tag
|
|
88
88
|
|
89
89
|
# Checks if this tag is using Cms::Block
|
90
90
|
def is_cms_block?
|
91
|
-
%w(page field).member?(self.class.to_s.demodulize.underscore.split(/_/).first)
|
91
|
+
%w(page field collection).member?(self.class.to_s.demodulize.underscore.split(/_/).first)
|
92
92
|
end
|
93
93
|
|
94
94
|
# Used in displaying form elements for Cms::Block
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class ComfortableMexicanSofa::Tag::Collection
|
2
|
+
include ComfortableMexicanSofa::Tag
|
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 }}
|
11
|
+
def self.regex_tag_signature(label = nil)
|
12
|
+
label ||= /[\w\/\-]+/
|
13
|
+
/\{\{\s*cms:collection:(#{label}):([\w\/\-\:]+)\s*\}\}/
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection_partial
|
17
|
+
self.params.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def collection_class
|
21
|
+
label.classify
|
22
|
+
end
|
23
|
+
|
24
|
+
def collection_title
|
25
|
+
self.params[1] || 'label'
|
26
|
+
end
|
27
|
+
|
28
|
+
def collection_identifier
|
29
|
+
self.params[2] || 'id'
|
30
|
+
end
|
31
|
+
|
32
|
+
def collection_params
|
33
|
+
self.params[3..-1] || []
|
34
|
+
end
|
35
|
+
|
36
|
+
def content=(value)
|
37
|
+
block.content = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def content
|
41
|
+
block.content
|
42
|
+
end
|
43
|
+
|
44
|
+
def render
|
45
|
+
if self.content.present?
|
46
|
+
ps = collection_params.collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
|
47
|
+
ps = ps.present?? ", #{ps}" : ''
|
48
|
+
"<%= render :partial => '#{collection_partial}', :locals => {:model => '#{collection_class}', :identifier => '#{content}'#{ps}} %>"
|
49
|
+
else
|
50
|
+
''
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -101,6 +101,17 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
|
|
101
101
|
assert_select "textarea[name='page[blocks_attributes][][content]'][class='code']"
|
102
102
|
assert_select "input[type='hidden'][name='page[blocks_attributes][][label]'][value='test_label']"
|
103
103
|
end
|
104
|
+
|
105
|
+
def test_get_new_with_collection
|
106
|
+
snippet = cms_snippets(:default)
|
107
|
+
cms_layouts(:default).update_attribute(:content, '{{cms:collection:cms/snippet:snippets/show}}')
|
108
|
+
get :new, :site_id => cms_sites(:default)
|
109
|
+
assert_select "select[name='page[blocks_attributes][][content]']" do
|
110
|
+
assert_select "option[value='']", :html => '---- Select Cms/Snippet ----'
|
111
|
+
assert_select "option[value='#{snippet.id}']", :html => snippet.label
|
112
|
+
end
|
113
|
+
assert_select "input[type='hidden'][name='page[blocks_attributes][][label]'][value='cms/snippet']"
|
114
|
+
end
|
104
115
|
|
105
116
|
def test_get_new_with_rich_page_text
|
106
117
|
cms_layouts(:default).update_attribute(:content, '{{cms:page:test_label:rich_text}}')
|
data/test/unit/tag_test.rb
CHANGED
@@ -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}} <%= 1 + 1 %>'
|
229
|
+
:content => '<% 1 + 1 %> {{cms:page:content}} {{cms:collection:cms/snippet:snippets/show}} <%= 1 + 1 %>'
|
230
230
|
)
|
231
231
|
snippet = site.snippets.create!(
|
232
232
|
:slug => 'no-irb-snippet',
|
@@ -238,10 +238,12 @@ class TagTest < ActiveSupport::TestCase
|
|
238
238
|
:layout_id => layout.id,
|
239
239
|
:blocks_attributes => [
|
240
240
|
{ :label => 'content',
|
241
|
-
:content => 'text {{ cms:snippet:no-irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' }
|
241
|
+
:content => 'text {{ cms:snippet:no-irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' },
|
242
|
+
{ :label => 'cms/snippet',
|
243
|
+
:content => snippet.id }
|
242
244
|
]
|
243
245
|
)
|
244
|
-
assert_equal "<% 1 + 1 %> text <% 2 + 2 %> snippet <%= 2 + 2 %> <%= render :partial => 'path/to' %> <%= method() %> text <%= 1 + 1 %>", page.content
|
246
|
+
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
|
245
247
|
end
|
246
248
|
|
247
249
|
def test_content_with_irb_enabled
|
@@ -250,7 +252,7 @@ class TagTest < ActiveSupport::TestCase
|
|
250
252
|
site = cms_sites(:default)
|
251
253
|
layout = site.layouts.create!(
|
252
254
|
:slug => 'irb-layout',
|
253
|
-
:content => '<% 1 + 1 %> {{cms:page:content}} <%= 1 + 1 %>'
|
255
|
+
:content => '<% 1 + 1 %> {{cms:page:content}} {{cms:collection:cms/snippet:snippets/show}} <%= 1 + 1 %>'
|
254
256
|
)
|
255
257
|
snippet = site.snippets.create!(
|
256
258
|
:slug => 'irb-snippet',
|
@@ -262,10 +264,12 @@ class TagTest < ActiveSupport::TestCase
|
|
262
264
|
:layout_id => layout.id,
|
263
265
|
:blocks_attributes => [
|
264
266
|
{ :label => 'content',
|
265
|
-
:content => 'text {{ cms:snippet:irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' }
|
267
|
+
:content => 'text {{ cms:snippet:irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' },
|
268
|
+
{ :label => 'cms/snippet',
|
269
|
+
:content => snippet.id }
|
266
270
|
]
|
267
271
|
)
|
268
|
-
assert_equal "<% 1 + 1 %> text <% 2 + 2 %> snippet <%= 2 + 2 %> <%= render :partial => 'path/to' %> <%= method() %> text <%= 1 + 1 %>", page.content
|
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
|
269
273
|
end
|
270
274
|
|
271
275
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class CollectionTagTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_initialize_tag
|
6
|
+
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
7
|
+
cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial }}'
|
8
|
+
)
|
9
|
+
assert_equal 'cms/snippet', tag.label
|
10
|
+
assert_equal 'Cms::Snippet', tag.collection_class
|
11
|
+
assert_equal 'path/to/partial', tag.collection_partial
|
12
|
+
assert_equal 'label', tag.collection_title
|
13
|
+
assert_equal 'id', tag.collection_identifier
|
14
|
+
assert_equal [], tag.collection_params
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize_tag_detailed
|
18
|
+
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
19
|
+
cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial:title:slug:param_a:param_b }}'
|
20
|
+
)
|
21
|
+
assert_equal 'cms/snippet', tag.label
|
22
|
+
assert_equal 'Cms::Snippet', tag.collection_class
|
23
|
+
assert_equal 'path/to/partial', tag.collection_partial
|
24
|
+
assert_equal 'title', tag.collection_title
|
25
|
+
assert_equal 'slug', tag.collection_identifier
|
26
|
+
assert_equal ['param_a', 'param_b'], tag.collection_params
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_initialize_tag_failure
|
30
|
+
[
|
31
|
+
'{{cms:collection}}',
|
32
|
+
'{{cms:collection:label}}',
|
33
|
+
'{{cms:not_collection:label:partial}}',
|
34
|
+
'{not_a_tag}'
|
35
|
+
].each do |tag_signature|
|
36
|
+
assert_nil ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
37
|
+
cms_pages(:default), tag_signature
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_content_and_render
|
43
|
+
tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
44
|
+
cms_pages(:default), '{{ cms:collection:cms/snippet:path/to/partial }}'
|
45
|
+
)
|
46
|
+
assert tag.content.blank?
|
47
|
+
|
48
|
+
snippet = cms_snippets(:default)
|
49
|
+
tag.content = snippet.id
|
50
|
+
assert_equal snippet.id, tag.block.content
|
51
|
+
assert_equal snippet.id, tag.content
|
52
|
+
assert_equal "<%= render :partial => 'path/to/partial', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %>", tag.render
|
53
|
+
end
|
54
|
+
|
55
|
+
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 }}'
|
58
|
+
)
|
59
|
+
assert tag.content.blank?
|
60
|
+
|
61
|
+
snippet = cms_snippets(:default)
|
62
|
+
tag.content = snippet.slug
|
63
|
+
assert_equal snippet.slug, tag.block.content
|
64
|
+
assert_equal snippet.slug, tag.content
|
65
|
+
assert_equal "<%= render :partial => 'path/to/partial', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.slug}', :param_1 => 'param_a', :param_2 => 'param_b'} %>", tag.render
|
66
|
+
end
|
67
|
+
|
68
|
+
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 }}'
|
71
|
+
)
|
72
|
+
assert tag.content.blank?
|
73
|
+
assert_equal '', tag.render
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
File without changes
|
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.
|
4
|
+
version: 1.4.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,12 +10,12 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-24 00:00:00.000000000 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
18
|
-
requirement: &
|
18
|
+
requirement: &70220046708640 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: 3.0.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70220046708640
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: active_link_to
|
29
|
-
requirement: &
|
29
|
+
requirement: &70220046707420 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 1.0.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70220046707420
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: paperclip
|
40
|
-
requirement: &
|
40
|
+
requirement: &70220046706160 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: 2.3.14
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70220046706160
|
49
49
|
description: ''
|
50
50
|
email: oleg@theworkinggroup.ca
|
51
51
|
executables: []
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- lib/comfortable_mexican_sofa/form_builder.rb
|
256
256
|
- lib/comfortable_mexican_sofa/tag.rb
|
257
257
|
- lib/comfortable_mexican_sofa/tags/asset.rb
|
258
|
+
- lib/comfortable_mexican_sofa/tags/collection.rb
|
258
259
|
- lib/comfortable_mexican_sofa/tags/field_datetime.rb
|
259
260
|
- lib/comfortable_mexican_sofa/tags/field_integer.rb
|
260
261
|
- lib/comfortable_mexican_sofa/tags/field_string.rb
|
@@ -320,6 +321,7 @@ files:
|
|
320
321
|
- test/unit/revisions_test.rb
|
321
322
|
- test/unit/tag_test.rb
|
322
323
|
- test/unit/tags/asset_test.rb
|
324
|
+
- test/unit/tags/collection_test.rb
|
323
325
|
- test/unit/tags/field_datetime_test.rb
|
324
326
|
- test/unit/tags/field_integer_test.rb
|
325
327
|
- test/unit/tags/field_string_test.rb
|
@@ -328,7 +330,7 @@ files:
|
|
328
330
|
- test/unit/tags/helper_test.rb
|
329
331
|
- test/unit/tags/page_datetime_test.rb
|
330
332
|
- test/unit/tags/page_integer_test.rb
|
331
|
-
- test/unit/tags/
|
333
|
+
- test/unit/tags/page_rich_text_test.rb
|
332
334
|
- test/unit/tags/page_string_test.rb
|
333
335
|
- test/unit/tags/page_text_test.rb
|
334
336
|
- test/unit/tags/partial_test.rb
|
@@ -349,7 +351,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
351
|
version: '0'
|
350
352
|
segments:
|
351
353
|
- 0
|
352
|
-
hash:
|
354
|
+
hash: -2622555031626774518
|
353
355
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
354
356
|
none: false
|
355
357
|
requirements:
|