config_templates 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config_templates.rb +1 -0
- data/lib/config_templates/collections/components.rb +2 -2
- data/lib/config_templates/criteria/path.rb +25 -2
- data/lib/config_templates/extensions/include.rb +6 -3
- data/lib/config_templates/version.rb +1 -1
- data/spec/fixtures/src/kapacitor/config.erb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2ef886ddd1d008ef5eac84a4ff9f09dbb8bbad
|
4
|
+
data.tar.gz: 575336494ebd01c60efcf01c8bcdae3de8943767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b866e4680f05c4cd026d323637bf63b05d752f5250be05a2b56177a8408a07c97495685fbfb9e31c1fee27147b3640f20ab7c9303b422e214311462d39d253ef
|
7
|
+
data.tar.gz: 77c7a6a8cc40ed17bbbed10c67addb738be7300b64545c004f466eb5155d687e5568fb9974dc47e6e557b1c5311f3dc8bc350d824871f0313aa73843a452b1ed
|
data/lib/config_templates.rb
CHANGED
@@ -15,8 +15,8 @@ module ConfigTemplates::Collections
|
|
15
15
|
.map { |_, component| component }
|
16
16
|
end
|
17
17
|
|
18
|
-
def find_by_path!(path)
|
19
|
-
find_by! ConfigTemplates::Criteria::Path.new path
|
18
|
+
def find_by_path!(path, relative_to = nil)
|
19
|
+
find_by! ConfigTemplates::Criteria::Path.new path, relative_to
|
20
20
|
rescue
|
21
21
|
raise ConfigTemplates::Errors::ComponentNotFound, path
|
22
22
|
end
|
@@ -1,11 +1,34 @@
|
|
1
1
|
module ConfigTemplates::Criteria
|
2
2
|
class Path
|
3
|
-
def initialize(path)
|
3
|
+
def initialize(path, relative_to)
|
4
4
|
@path = path
|
5
|
+
@relative_to = relative_to
|
5
6
|
end
|
6
7
|
|
7
8
|
def filter(hash)
|
8
|
-
|
9
|
+
if @path.start_with? '@'
|
10
|
+
with_absolute_path hash
|
11
|
+
else
|
12
|
+
with_relative_path hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def with_absolute_path(hash)
|
19
|
+
hash.key?(@path.sub!('@', '')) ? { @path => hash[@path] } : {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def with_relative_path(hash)
|
23
|
+
hash.key?(relative_path) ? { relative_path => hash[relative_path] } : {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def relative_path
|
27
|
+
@relative_path ||= begin
|
28
|
+
path = ::File.join ::File.dirname(@relative_to), @path
|
29
|
+
pathname = ::Pathname.new path
|
30
|
+
pathname.cleanpath.to_s
|
31
|
+
end
|
9
32
|
end
|
10
33
|
end
|
11
34
|
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
module ConfigTemplates::Extensions
|
2
2
|
class Include
|
3
3
|
def call(context, invocation)
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
child_component = context.components.find_by_path!(
|
5
|
+
invocation.args.first,
|
6
|
+
context.component.source_path
|
7
|
+
)
|
8
|
+
child_component.child!
|
9
|
+
child_component.render
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
@@ -1 +1 @@
|
|
1
|
-
<%= include('
|
1
|
+
<%= include('include.erb') %>
|