liquify 0.2 → 0.2.1
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/methods.rb +3 -0
- data/lib/liquify/version.rb +1 -1
- data/lib/liquify.rb +12 -4
- data/spec/liquify_spec.rb +7 -0
- metadata +2 -2
data/lib/liquify/methods.rb
CHANGED
data/lib/liquify/version.rb
CHANGED
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
|
-
|
|
70
|
-
@@drops.each { |name, klass|
|
|
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
|
-
|
|
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:
|
|
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-
|
|
13
|
+
date: 2011-03-27 00:00:00 -04:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|