liquify 0.2.3 → 0.2.5
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/lib/liquify/block.rb +3 -3
- data/lib/liquify/parameter.rb +8 -4
- data/lib/liquify/version.rb +1 -1
- data/spec/liquify/foo_block_spec.rb +3 -2
- data/spec/support/liquify/foo_block.rb +3 -2
- metadata +1 -1
data/lib/liquify/block.rb
CHANGED
@@ -35,7 +35,7 @@ module Liquify
|
|
35
35
|
options = params.dup.extract_options!
|
36
36
|
drop_tokens = @tokens.grep /\{\{\s*#{options['as']}\..*\}\}/
|
37
37
|
|
38
|
-
context[options['as']] = Liquify::Block::Drop.new(self, drop_tokens, context)
|
38
|
+
context[options['as']] = Liquify::Block::Drop.new(self, drop_tokens, context, options['as'])
|
39
39
|
|
40
40
|
args = []
|
41
41
|
args << params if method(:invoke).arity == 1
|
@@ -48,12 +48,12 @@ module Liquify
|
|
48
48
|
end
|
49
49
|
|
50
50
|
class Drop < Liquid::Drop
|
51
|
-
def initialize(obj, tokens, context) # :nodoc:
|
51
|
+
def initialize(obj, tokens, context, as) # :nodoc:
|
52
52
|
@obj = obj
|
53
53
|
@params = {}
|
54
54
|
|
55
55
|
tokens.each do |t|
|
56
|
-
match, key, value = t.match(/\{\{\s
|
56
|
+
match, key, value = t.match(/\{\{\s*#{as}\.(\w+)(.*)\}\}/).to_a
|
57
57
|
|
58
58
|
@params[key] ||= []
|
59
59
|
@params[key] << Liquify::Parameter.new(value, context)
|
data/lib/liquify/parameter.rb
CHANGED
@@ -2,18 +2,18 @@ module Liquify
|
|
2
2
|
class Parameter < Array
|
3
3
|
def initialize(markup, context={})
|
4
4
|
markup = markup.split(',')
|
5
|
+
@markup = markup
|
5
6
|
args = []
|
6
7
|
options = {}
|
7
8
|
|
8
9
|
markup.each do |arg|
|
9
10
|
key, value = arg.split(':')
|
10
|
-
key =
|
11
|
+
key = key.strip
|
11
12
|
|
12
13
|
if value
|
13
|
-
|
14
|
-
options[key] = value
|
14
|
+
options[key] = find_from_context_or_value(value, context)
|
15
15
|
else
|
16
|
-
args << key
|
16
|
+
args << find_from_context_or_value(key, context)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
args << options unless options.empty?
|
@@ -31,5 +31,9 @@ module Liquify
|
|
31
31
|
def strip_quotes(value)
|
32
32
|
value.strip.gsub(/^('|")|('|")$/,'')
|
33
33
|
end
|
34
|
+
|
35
|
+
def find_from_context_or_value(value, context)
|
36
|
+
value =~ /("|')/ ? strip_quotes(value.strip) : context[value.strip]
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
data/lib/liquify/version.rb
CHANGED
@@ -4,10 +4,11 @@ describe FooBlock do
|
|
4
4
|
before(:each) do
|
5
5
|
Liquify.setup do |c|
|
6
6
|
c.register_tag :foo_block, FooBlock
|
7
|
+
c.register_drop :item, lambda { 'Item Text' }
|
7
8
|
end
|
8
9
|
|
9
10
|
@content = <<-STR
|
10
|
-
{% foo_block as: 'f' %}
|
11
|
+
{% foo_block item, as: 'f' %}
|
11
12
|
<p>{{ f.name 'foo' }}</p>
|
12
13
|
<p>{{ f.name }}</p> <!-- intentionally blank -->
|
13
14
|
<p>{{ f.name 'bar' }}</p>
|
@@ -19,7 +20,7 @@ describe FooBlock do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'has wrapper html' do
|
22
|
-
@output.should =~ /<div id="block-wrapper">.*<\/div>/m
|
23
|
+
@output.should =~ /<div id="block-wrapper" data-value="Item Text">.*<\/div>/m
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'has an email field and does not take arguments' do
|