sablon 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/sablon/operations.rb +2 -1
- data/lib/sablon/version.rb +1 -1
- data/test/processor_test.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74f19959e3d2566b25c322d1d9365001d95a085
|
4
|
+
data.tar.gz: be248f49337bedb4f7747f6d11b26e721a215514
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e77454cdb18b5a10a2a57b205c6fe837bd8e01e0d22ded78ba43a1db5f2717aa987f62a0cc016c02a5a4f1ba322f6424bd3ff45ef80e459ebded2dd6ca32762
|
7
|
+
data.tar.gz: 301bc31e4ddc13ae6b224b04ddb43fc4ba09db01b2c080c14bc6fbc126adc3bfd59e0f975d137de179d422ad36975ef67698a1da454595e0f383dee61b8274ad
|
data/lib/sablon/operations.rb
CHANGED
@@ -10,7 +10,8 @@ module Sablon
|
|
10
10
|
class Loop < Struct.new(:list_expr, :iterator_name, :block)
|
11
11
|
def evaluate(context)
|
12
12
|
value = list_expr.evaluate(context)
|
13
|
-
|
13
|
+
value = value.to_ary if value.respond_to?(:to_ary)
|
14
|
+
raise ContextError, "The expression #{list_expr.inspect} should evaluate to an enumerable but was: #{value.inspect}" unless value.is_a?(Enumerable)
|
14
15
|
|
15
16
|
content = value.flat_map do |item|
|
16
17
|
iteration_context = context.merge(iterator_name => item)
|
data/lib/sablon/version.rb
CHANGED
data/test/processor_test.rb
CHANGED
@@ -278,6 +278,25 @@ class ProcessorTest < Sablon::TestCase
|
|
278
278
|
document
|
279
279
|
end
|
280
280
|
|
281
|
+
def test_loop_over_collection_convertable_to_an_enumerable
|
282
|
+
style_collection = Class.new do
|
283
|
+
def to_ary
|
284
|
+
["CSS", "SCSS", "LESS"]
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
result = process(snippet("paragraph_loop"), {"technologies" => style_collection.new})
|
289
|
+
assert_equal "CSS SCSS LESS", text(result)
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_loop_over_collection_not_convertable_to_an_enumerable_raises_error
|
293
|
+
not_a_collection = Class.new {}
|
294
|
+
|
295
|
+
assert_raises Sablon::ContextError do
|
296
|
+
process(snippet("paragraph_loop"), {"technologies" => not_a_collection.new})
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
281
300
|
def test_loop_with_missing_variable_raises_error
|
282
301
|
e = assert_raises Sablon::ContextError do
|
283
302
|
process(snippet("paragraph_loop"), {})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sablon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Senn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|