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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45490341d42142a355c3fbf6f5aa00c30d801acc
4
- data.tar.gz: bdf40b4c70137309609cfa3472f634619c13605c
3
+ metadata.gz: a74f19959e3d2566b25c322d1d9365001d95a085
4
+ data.tar.gz: be248f49337bedb4f7747f6d11b26e721a215514
5
5
  SHA512:
6
- metadata.gz: 38aa0a39b40f1219f8bafe6d80072d08f1da5c7825ee9270ba0bc0e5aec23adcba531bd39829c2d05d85fec57162161591b7202366902724b7d389d0b4f0f440
7
- data.tar.gz: 79c63b61bdb204e436c53450327465f60af6a3a4083f9907b604b737c4f7e1622f67aa65a57718d9043b807322768469096728f427ccb4d4721503b2bf538e87
6
+ metadata.gz: 7e77454cdb18b5a10a2a57b205c6fe837bd8e01e0d22ded78ba43a1db5f2717aa987f62a0cc016c02a5a4f1ba322f6424bd3ff45ef80e459ebded2dd6ca32762
7
+ data.tar.gz: 301bc31e4ddc13ae6b224b04ddb43fc4ba09db01b2c080c14bc6fbc126adc3bfd59e0f975d137de179d422ad36975ef67698a1da454595e0f383dee61b8274ad
@@ -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
- raise ContextError, "The expression #{list_expr.inspect} should evaluate to an enumerable but was: #{value.inspect}" unless value.is_a? Enumerable
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)
@@ -1,3 +1,3 @@
1
1
  module Sablon
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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.7
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-09 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri