consul-templaterb 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/TemplateAPI.md +18 -0
- data/lib/consul/async/consul_template.rb +10 -0
- data/lib/consul/async/version.rb +1 -1
- data/samples/render_template_from_kv.erb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c208ffa413a78bdf642df954fa20acb422a6f46a0b10728eb6df0c16602071a5
|
4
|
+
data.tar.gz: d92d158795b0d0f641e0cb10e05b8dc66672a68ef420d1d527faee134de0a271
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c46f0b64d5b427c08e0c3aa77ff6174b1dbc26deed18161c7b1108df42ec27ac83ebeb365e50800a8f11c9ebba1586f16ef947c6e20d50fc7e4427781289750
|
7
|
+
data.tar.gz: e6e500eb043d6a5627a22207f94992dfcf13d63f5604418b7f53854ad1557bf49aaafd05a0ca7f500e5e23430d5c88f2a983da2afd75287409fcbac549f4d4ff
|
data/CHANGELOG.md
CHANGED
data/TemplateAPI.md
CHANGED
@@ -295,6 +295,24 @@ Example:
|
|
295
295
|
Will render header.html.erb with parameter title = 'My Title'. `title` can then be accessed within
|
296
296
|
the template using `param('title', 'My default Value')` in the `header.html.erb` file.
|
297
297
|
|
298
|
+
## render_from_string(template_to_render, [params={}])
|
299
|
+
|
300
|
+
Similar to render_file but from a string.
|
301
|
+
Allows to render a template from a string. Useful if you have your templates in KV for instance.
|
302
|
+
|
303
|
+
Example:
|
304
|
+
|
305
|
+
Given the value in Consul's KV `my/template/to_render`: `from KV: <%= 5 * 2 %>`
|
306
|
+
|
307
|
+
```erb
|
308
|
+
<%= render_from_string(kv('my/template/to_render').get_value_decoded) %>
|
309
|
+
```
|
310
|
+
|
311
|
+
Would render the value: `from KV: 10`.
|
312
|
+
|
313
|
+
That's very usefull if you want to centralize your templates and being able to change the value
|
314
|
+
with a simple PUT call in the KV.
|
315
|
+
|
298
316
|
## param(parameter_name, [default_value: nil])
|
299
317
|
|
300
318
|
Can be used within a template to access a parameter. Parameters can be specified with `render_file`
|
@@ -3,6 +3,8 @@ require 'em-http'
|
|
3
3
|
require 'thread'
|
4
4
|
require 'forwardable'
|
5
5
|
require 'erb'
|
6
|
+
require 'digest'
|
7
|
+
|
6
8
|
module Consul
|
7
9
|
module Async
|
8
10
|
class InvalidTemplateException < StandardError
|
@@ -169,6 +171,14 @@ module Consul
|
|
169
171
|
render(File.read(new_path), new_path, params, current_template_info: template_info)
|
170
172
|
end
|
171
173
|
|
174
|
+
# render a sub template from a string template
|
175
|
+
def render_from_string(template_content, params = {})
|
176
|
+
return unless template_content
|
177
|
+
sha1res = Digest::SHA1.hexdigest(template_content)
|
178
|
+
new_path = File.expand_path(":memory:sha1:#{sha1res}", File.dirname(@context[:current_erb_path]))
|
179
|
+
render(template_content, new_path, params, current_template_info: template_info)
|
180
|
+
end
|
181
|
+
|
172
182
|
def find_line(e)
|
173
183
|
return e.message.dup[5..-1] if e.message.start_with? '(erb):'
|
174
184
|
e.backtrace.each do |line|
|
data/lib/consul/async/version.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
<%
|
2
|
+
# This template render a template contained into Consul's KV
|
3
|
+
# Usage: kv_path=my/path/to_template_in_kv consul-templaterb samples/render_template_from_kv.erb
|
4
|
+
|
5
|
+
kv_path = param('kv_path') || ENV['kv_path']
|
6
|
+
template_content = kv(kv_path).get_value_decoded if kv_path
|
7
|
+
%><%= render_from_string(template_content) %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-templaterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SRE Core Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- samples/keys.html.erb
|
212
212
|
- samples/metrics.erb
|
213
213
|
- samples/nodes.html.erb
|
214
|
+
- samples/render_template_from_kv.erb
|
214
215
|
- samples/sample_keys.html.erb
|
215
216
|
- samples/service_checks_metrics.erb
|
216
217
|
- samples/services.html.erb
|