liquify 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,9 @@ module Liquify
8
8
 
9
9
  module ClassMethods
10
10
  protected
11
+ #
12
+ #
13
+ #
11
14
  def liquify_method(*args)
12
15
  liquify_args = instance_variable_get :@liquify_args
13
16
  liquify_args ||= {}
@@ -1,3 +1,3 @@
1
1
  module Liquify
2
- VERSION = "0.2"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/liquify.rb CHANGED
@@ -65,12 +65,20 @@ module Liquify
65
65
  #
66
66
  # template = '{{ drop_name.method }}'
67
67
  # Liquify.invoke(template) # => Rendered Liquid template
68
- def invoke(template)
69
- args = {}
70
- @@drops.each { |name, klass| args[name.to_s] = klass.respond_to?(:call) ? klass.call : klass.new }
68
+ def invoke(template, extra_context={})
69
+ context = {}
70
+ @@drops.each { |name, klass| context[name.to_s] = klass.respond_to?(:call) ? klass.call : klass.new }
71
71
  @@filters.each { |filter| Liquid::Template.register_filter(filter) }
72
72
  @@tags.each { |tag, klass| Liquid::Template.register_tag(tag, klass) }
73
- Liquid::Template.parse(template).render(args)
73
+
74
+ # ensuring any extra context values that come in as symbols are
75
+ # converted to strings
76
+ extra_keys = extra_context.keys.map!(&:to_s)
77
+ extra_context = Hash[extra_keys.zip(extra_context.values)]
78
+
79
+ context.merge!(extra_context)
80
+
81
+ Liquid::Template.parse(template).render(context)
74
82
  end
75
83
 
76
84
  def render(template)
data/spec/liquify_spec.rb CHANGED
@@ -51,5 +51,12 @@ describe Liquify do
51
51
  Liquify.invoke(@template).should == 'Foo'
52
52
  end
53
53
  end
54
+
55
+ context 'when additional context information needs to be added' do
56
+ it 'renders as if it were registered in Liquify' do
57
+ output = Liquify.invoke('{{ qux }}', :qux => 'cux qux')
58
+ output.should == 'cux qux'
59
+ end
60
+ end
54
61
  end
55
62
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: liquify
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "0.2"
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dane Harrigan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-06 00:00:00 -05:00
13
+ date: 2011-03-27 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency