liquify 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
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*f\.(\w+)(.*)\}\}/).to_a
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)
@@ -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 = strip_quotes(key.strip)
11
+ key = key.strip
11
12
 
12
13
  if value
13
- value = (value =~ /("|')/) ? strip_quotes(value.strip) : context[value.strip]
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
@@ -1,3 +1,3 @@
1
1
  module Liquify
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -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
@@ -1,6 +1,7 @@
1
1
  class FooBlock < Liquify::Block
2
- def invoke
3
- "<div id=\"block-wrapper\">#{yield}</div>"
2
+ def invoke(params)
3
+ options = params.extract_options!
4
+ "<div id=\"block-wrapper\" data-value=\"#{params.first}\">#{yield}</div>"
4
5
  end
5
6
 
6
7
  def name(params)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: liquify
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.3
5
+ version: 0.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dane Harrigan