express_templates 0.11.18 → 0.11.19

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: 890df022013fa147cf7e3ebc99ca0e193248b3a5
4
- data.tar.gz: 1f12843eb4d1cb79628a6b93ff5c0e535a4aed3e
3
+ metadata.gz: 046e78dff9573c57fcf8b1ec09fe07b4860aa6fb
4
+ data.tar.gz: f44db99ebba450670130287a56a474fdd49c61fa
5
5
  SHA512:
6
- metadata.gz: 12c5c6aabac29e5c94e7a8e37404f6689d7b09b731e8ce93c1e0fa9c4dce2fe841e87b7ede3f85489ce825580406a0e9275f6ad7b45ccb6fe9f5f283b2c2b303
7
- data.tar.gz: 9fa7499b429c0253d83029343239bfcb25f85932285533d115b1770d22059987c9a83f294a36add75c0f31022fd408eab3bdef1769e2661e2625724b3ae28b5c
6
+ metadata.gz: d6968038236bc2dfd99949e3308e0efb244e50691e3fffe1ac6d741f8e1300f1db0d77a487a53876cff927f7ddab7d33881650c0526e5539585a1c57217c970c
7
+ data.tar.gz: cde66fabcad5fe70a31794d7e5ff6018754600ea525e9a472028c754f0b52210fc30263b43a419c95c6d41f791a35dd95642b8507dd1c8c0e8a82a7ba7e8cbd2
@@ -9,6 +9,8 @@ module ExpressTemplates
9
9
  def self.included(base)
10
10
  base.class_eval do
11
11
 
12
+ has_option :collection, "An optional object implementing Enumerable or a proc returning an Enumerable.", type: [:proc, :array]
13
+
12
14
  # Iterates over the collection calling the block provided to emit markup.
13
15
  #
14
16
  # The collection (symbol) must be available as a method on the component
@@ -19,8 +21,7 @@ module ExpressTemplates
19
21
 
20
22
  def for_all(collection_name, &block)
21
23
  @collection_name = collection_name
22
- raise "#{collection_name} is not a collection" unless self.send(collection_name).respond_to?(:each)
23
- self.send(collection_name).each do |item|
24
+ _normalized_collection.each do |item|
24
25
  old_value = assigns[singular_item_name]
25
26
  assigns[singular_item_name] = item
26
27
  block.call
@@ -42,6 +43,19 @@ module ExpressTemplates
42
43
  assigns[singular_item_name]
43
44
  end
44
45
 
46
+ private
47
+ def _normalized_collection
48
+ case
49
+ when config[:collection].respond_to?(:call)
50
+ config[:collection].call()
51
+ when config[:collection].respond_to?(:each)
52
+ config[:collection]
53
+ else
54
+ raise "#{collection_name} is not a collection" unless self.send(collection_name).respond_to?(:each)
55
+ self.send(collection_name)
56
+ end
57
+ end
58
+
45
59
  end
46
60
  end
47
61
  end
@@ -1,3 +1,3 @@
1
1
  module ExpressTemplates
2
- VERSION = "0.11.18"
2
+ VERSION = "0.11.19"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.18
4
+ version: 0.11.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-12 00:00:00.000000000 Z
12
+ date: 2017-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arbre