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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d992cca0fe8acc08d28b9d284f033caf1f84804a3a0597474d6a915aaeb9b1b
4
- data.tar.gz: b9ca91c0a8ad433926232cd85103829cdb4e285e343e1801497828014930d827
3
+ metadata.gz: c208ffa413a78bdf642df954fa20acb422a6f46a0b10728eb6df0c16602071a5
4
+ data.tar.gz: d92d158795b0d0f641e0cb10e05b8dc66672a68ef420d1d527faee134de0a271
5
5
  SHA512:
6
- metadata.gz: 5a1866f696551f174f146172633f9613b133a4caf9aa797670d8e6ace14e06e0bf7647f194881db57cb5e6f4e5918a3e7d78bf2ab2524d93aeffc5bb13c69322
7
- data.tar.gz: 46e23baa70aefeb927cd60965708206818844a130ba9dc4f4214a850583a6be67f3969bfdbd2720abd330d321400a4a129d0f4049a0e49d9ddd80ee134743d24
6
+ metadata.gz: 8c46f0b64d5b427c08e0c3aa77ff6174b1dbc26deed18161c7b1108df42ec27ac83ebeb365e50800a8f11c9ebba1586f16ef947c6e20d50fc7e4427781289750
7
+ data.tar.gz: e6e500eb043d6a5627a22207f94992dfcf13d63f5604418b7f53854ad1557bf49aaafd05a0ca7f500e5e23430d5c88f2a983da2afd75287409fcbac549f4d4ff
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## (UNRELEASED)
4
4
 
5
+ ## 1.11.0 (March 16, 2019)
6
+
7
+ NEW FEATURES:
8
+
9
+ * Added new function render_from_string() to render a template from a string (useful with KV)
10
+
5
11
  ## 1.10.1 (February 28, 2019)
6
12
 
7
13
  BUGFIX:
@@ -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|
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.10.1'.freeze
3
+ VERSION = '1.11.0'.freeze
4
4
  end
5
5
  end
@@ -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.10.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-02-28 00:00:00.000000000 Z
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