comfortable_mexican_sofa 1.0.3 → 1.0.4

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{comfortable_mexican_sofa}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
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"]
@@ -6,7 +6,8 @@
6
6
  # end
7
7
  module CmsTag
8
8
 
9
- attr_accessor :parent
9
+ attr_accessor :params,
10
+ :parent
10
11
 
11
12
  module ClassMethods
12
13
  # Regex that is used to match tags in the content
@@ -26,7 +27,8 @@ module CmsTag
26
27
  self.initialize_or_find(cms_page, match[1])
27
28
  else
28
29
  tag = self.new
29
- tag.label = match[1]
30
+ tag.label = match[1]
31
+ tag.params = match[2]
30
32
  tag
31
33
  end
32
34
  end
@@ -6,7 +6,7 @@ class CmsTag::Helper
6
6
 
7
7
  def self.regex_tag_signature(label = nil)
8
8
  label ||= /\w+/
9
- /<\s*cms:helper:(#{label})\s*\/?>/
9
+ /<\s*cms:helper:(#{label}):?(.*?)\s*\/?>/
10
10
  end
11
11
 
12
12
  def regex_tag_signature
@@ -14,7 +14,7 @@ class CmsTag::Helper
14
14
  end
15
15
 
16
16
  def content
17
- "<%= #{label} %>"
17
+ "<%= #{label}(#{params.split(':').collect{|p| "'#{p}'"}.join(', ')}) %>"
18
18
  end
19
19
 
20
20
  end
@@ -6,7 +6,7 @@ class CmsTag::Partial
6
6
 
7
7
  def self.regex_tag_signature(label = nil)
8
8
  label ||= /[\w\/]+/
9
- /<\s*cms:partial:(#{label})\s*\/?>/
9
+ /<\s*cms:partial:(#{label}):?(.*?)\s*\/?>/
10
10
  end
11
11
 
12
12
  def regex_tag_signature
@@ -14,7 +14,8 @@ class CmsTag::Partial
14
14
  end
15
15
 
16
16
  def content
17
- "<%= render :partial => '#{label}' %>"
17
+ ps = params.split(':').collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
18
+ "<%= render :partial => '#{label}'#{ps.blank?? nil : ", :locals => {#{ps}}"} %>"
18
19
  end
19
20
 
20
21
  end
@@ -1,5 +1,7 @@
1
1
  class CmsTag::Snippet < CmsSnippet
2
2
 
3
+ attr_accessor :label
4
+
3
5
  include CmsTag
4
6
 
5
7
  def identifier
@@ -8,4 +8,15 @@ class String
8
8
  def capitalize_all(delimiter = ' ')
9
9
  self.split(delimiter).collect{|w| w.capitalize }.join(' ')
10
10
  end
11
+ end
12
+
13
+ module Enumerable
14
+ # Like a normal collect, only with index
15
+ def collect_with_index
16
+ result = []
17
+ self.each_with_index do |elt, idx|
18
+ result << yield(elt, idx)
19
+ end
20
+ result
21
+ end
11
22
  end
@@ -3,11 +3,13 @@ require File.dirname(__FILE__) + '/../../test_helper'
3
3
  class HelperTest < ActiveSupport::TestCase
4
4
 
5
5
  def test_initialize_tag
6
- %w(
7
- <cms:helper:method_name/>
8
- ).each do |tag_signature|
9
- assert tag = CmsTag::Helper.initialize_tag(cms_pages(:default), tag_signature)
10
- end
6
+ assert CmsTag::Helper.initialize_tag(cms_pages(:default), '<cms:helper:method_name/>')
7
+ end
8
+
9
+ def test_initialize_tag_with_parameters
10
+ assert tag = CmsTag::Helper.initialize_tag(cms_pages(:default), '<cms:helper:method_name:param1:param2/>')
11
+ assert tag.label = 'method_name'
12
+ assert tag.params = 'param1:param2'
11
13
  end
12
14
 
13
15
  def test_initialize_tag_failure
@@ -22,8 +24,12 @@ class HelperTest < ActiveSupport::TestCase
22
24
 
23
25
  def test_content_and_render
24
26
  tag = CmsTag::Helper.initialize_tag(cms_pages(:default), "<cms:helper:method_name/>")
25
- assert_equal "<%= method_name %>", tag.content
26
- assert_equal "<%= method_name %>", tag.render
27
+ assert_equal "<%= method_name() %>", tag.content
28
+ assert_equal "<%= method_name() %>", tag.render
29
+
30
+ tag = CmsTag::Helper.initialize_tag(cms_pages(:default), "<cms:helper:method_name:param1:param2/>")
31
+ assert_equal "<%= method_name('param1', 'param2') %>", tag.content
32
+ assert_equal "<%= method_name('param1', 'param2') %>", tag.render
27
33
  end
28
34
 
29
35
  end
@@ -11,6 +11,12 @@ class PartialTest < ActiveSupport::TestCase
11
11
  end
12
12
  end
13
13
 
14
+ def test_initialize_tag_with_parameters
15
+ assert tag = CmsTag::Partial.initialize_tag(cms_pages(:default), '<cms:partial:path/to/partial:param1:param2/>')
16
+ assert tag.label = 'path/to/partial'
17
+ assert tag.params = 'param1:param2'
18
+ end
19
+
14
20
  def test_initialize_tag_failure
15
21
  %w(
16
22
  <cms:partial>
@@ -25,6 +31,10 @@ class PartialTest < ActiveSupport::TestCase
25
31
  tag = CmsTag::Partial.initialize_tag(cms_pages(:default), "<cms:partial:path/to/patial>")
26
32
  assert_equal "<%= render :partial => 'path/to/patial' %>", tag.content
27
33
  assert_equal "<%= render :partial => 'path/to/patial' %>", tag.render
34
+
35
+ tag = CmsTag::Partial.initialize_tag(cms_pages(:default), '<cms:partial:path/to/partial:param1:param2/>')
36
+ assert_equal "<%= render :partial => 'path/to/partial', :locals => {:param_1 => 'param1', :param_2 => 'param2'} %>", tag.content
37
+ assert_equal "<%= render :partial => 'path/to/partial', :locals => {:param_1 => 'param1', :param_2 => 'param2'} %>", tag.render
28
38
  end
29
39
 
30
40
  end
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: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oleg Khabarov