express_templates 0.11.17 → 0.11.18
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/arbre/patches.rb +4 -4
- data/lib/express_templates/compiler.rb +7 -8
- data/lib/express_templates/components.rb +1 -0
- data/lib/express_templates/components/all.rb +7 -12
- data/lib/express_templates/components/capabilities/iteration.rb +50 -0
- data/lib/express_templates/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 890df022013fa147cf7e3ebc99ca0e193248b3a5
|
4
|
+
data.tar.gz: 1f12843eb4d1cb79628a6b93ff5c0e535a4aed3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c5c6aabac29e5c94e7a8e37404f6689d7b09b731e8ce93c1e0fa9c4dce2fe841e87b7ede3f85489ce825580406a0e9275f6ad7b45ccb6fe9f5f283b2c2b303
|
7
|
+
data.tar.gz: 9fa7499b429c0253d83029343239bfcb25f85932285533d115b1770d22059987c9a83f294a36add75c0f31022fd408eab3bdef1769e2661e2625724b3ae28b5c
|
data/lib/arbre/patches.rb
CHANGED
@@ -19,11 +19,11 @@ module Arbre
|
|
19
19
|
tag.parent = current_arbre_element
|
20
20
|
|
21
21
|
with_current_arbre_element tag do
|
22
|
-
begin
|
22
|
+
# begin
|
23
23
|
tag.build(*args, &block)
|
24
|
-
rescue Exception => e
|
25
|
-
|
26
|
-
end
|
24
|
+
# rescue Exception => e
|
25
|
+
# on_component_error(tag, e)
|
26
|
+
# end
|
27
27
|
end
|
28
28
|
|
29
29
|
tag
|
@@ -2,14 +2,13 @@ module ExpressTemplates
|
|
2
2
|
module Compiler
|
3
3
|
def compile(template_or_src=nil, &block)
|
4
4
|
template, src = _normalize(template_or_src)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
}
|
5
|
+
|
6
|
+
# local_assigns = {} if !defined?(local_assigns)
|
7
|
+
# merged_assigns = assigns.merge(template_virtual_path: @virtual_path)
|
8
|
+
# .merge(local_assigns)
|
9
|
+
# The following must be one-line otherwise we lose accurate
|
10
|
+
# line reporting on the stack.
|
11
|
+
%Q{Arbre::Context.new(assigns.merge(template_virtual_path: @virtual_path).merge(defined?(local_assigns) ? local_assigns : {}), self) { #{src || block.source_body} }.to_s}
|
13
12
|
end
|
14
13
|
|
15
14
|
private
|
@@ -6,6 +6,7 @@ end
|
|
6
6
|
# Abbreviation for your component class definitions
|
7
7
|
ET = ExpressTemplates
|
8
8
|
|
9
|
+
require 'express_templates/components/capabilities/iteration'
|
9
10
|
require 'express_templates/components/registry'
|
10
11
|
require 'express_templates/components/base'
|
11
12
|
require 'express_templates/components/configurable'
|
@@ -2,26 +2,21 @@ module ExpressTemplates
|
|
2
2
|
module Components
|
3
3
|
module Presenters
|
4
4
|
class All < Container
|
5
|
+
include Capabilities::Iteration
|
5
6
|
|
6
|
-
has_argument :id, "Name of the collection",
|
7
|
+
has_argument :id, "Name of the collection", type: :symbol
|
8
|
+
|
9
|
+
def start_tag; ''; end
|
10
|
+
def end_tag; ''; end
|
7
11
|
|
8
12
|
contains -> (&block) {
|
9
13
|
prepended
|
10
|
-
|
11
|
-
assigns[member_name.to_sym] = item
|
14
|
+
for_all(config[:id]) {
|
12
15
|
block.call(self) if block
|
13
|
-
|
16
|
+
}
|
14
17
|
appended
|
15
18
|
}
|
16
19
|
|
17
|
-
def member_name
|
18
|
-
config[:collection_name].to_s.singularize.to_sym
|
19
|
-
end
|
20
|
-
|
21
|
-
def collection
|
22
|
-
self.send(config[:collection_name])
|
23
|
-
end
|
24
|
-
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ExpressTemplates
|
2
|
+
module Components
|
3
|
+
module Capabilities
|
4
|
+
|
5
|
+
# Provides iteration to components that iterate over a collection.
|
6
|
+
|
7
|
+
module Iteration
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.class_eval do
|
11
|
+
|
12
|
+
# Iterates over the collection calling the block provided to emit markup.
|
13
|
+
#
|
14
|
+
# The collection (symbol) must be available as a method on the component
|
15
|
+
# or as a local (assigns) value in the rendering context.
|
16
|
+
#
|
17
|
+
# The collection name is singularized and a local value is set
|
18
|
+
# for each item in the collection.
|
19
|
+
|
20
|
+
def for_all(collection_name, &block)
|
21
|
+
@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
|
+
old_value = assigns[singular_item_name]
|
25
|
+
assigns[singular_item_name] = item
|
26
|
+
block.call
|
27
|
+
assigns[singular_item_name] = old_value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def collection_name
|
34
|
+
@collection_name
|
35
|
+
end
|
36
|
+
|
37
|
+
def singular_item_name
|
38
|
+
collection_name.to_s.singularize.to_sym
|
39
|
+
end
|
40
|
+
|
41
|
+
def item
|
42
|
+
assigns[singular_item_name]
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
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.
|
4
|
+
version: 0.11.18
|
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
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arbre
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/express_templates/components/base.rb
|
74
74
|
- lib/express_templates/components/capabilities/configurable.rb
|
75
75
|
- lib/express_templates/components/capabilities/hideable.rb
|
76
|
+
- lib/express_templates/components/capabilities/iteration.rb
|
76
77
|
- lib/express_templates/components/capabilities/resourceful.rb
|
77
78
|
- lib/express_templates/components/capabilities/suppressable.rb
|
78
79
|
- lib/express_templates/components/configurable.rb
|