Skip to content

Commit 1ad5c4c

Browse files
authored
Add partial rendering (#3)
* Add fixtures for partial rendering * Update classes and exe to render partials. * Bumped gem version, updated CHANGELOG and README. * Added simple_partials example * Fixes for some style points from code climate
1 parent f2ed436 commit 1ad5c4c

24 files changed

Lines changed: 186 additions & 20 deletions

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
AllCops:
2+
TargetRubyVersion: 2.3
3+
14
Metrics/LineLength:
25
Max: 119
36
Exclude:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.3.0 (2018-02-02)
2+
3+
Features:
4+
5+
- Partials can now be rendered by calling `render 'path/to/partial.erb'` in the template.
6+
17
## 0.2.0 (2018-01-29)
28

39
Features:

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source "https://rubygems.org"
24

35
gemspec

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ provider](https://www.terraform.io/docs/providers/external/data_source.html) to
2323
terraform passes in the variables to render as a json blob to stdin as described above and expects a json blob
2424
back.
2525

26+
## Rendering Partials
27+
28+
Inside any template you can render a partial template by calling the render method.
29+
30+
For example if you have a partial template in filepath `partials/partial.erb`:
31+
32+
This is a partial, Hello <%= name %>
33+
34+
And your template is
35+
36+
My favourite colour is <%= colour %>
37+
<%= render 'partials/partial.erb' %>
38+
39+
And you execute the command as
40+
41+
echo '{ "colour": "purple", "name": "Jonathan" }' | template_renderer path_to_my_template
42+
43+
You will produce
44+
45+
{ "rendered": "My favourite colour is purple\nThis is a partial, Hello Jonathan\n" }
46+
2647
## ERB Template notes
2748

2849
Trim mode is enabled and the trim character is a hyphen `-`.

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "bundler/gem_tasks"
24
require "rspec/core/rake_task"
35

examples/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
gem "terraform-template-renderer", path: "../"

examples/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
terraform-template-renderer (0.2.0)
4+
terraform-template-renderer (0.3.0)
55

66
GEM
77
remote: https://rubygems.org/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
First partial <%= @partial_key_1 %>
2+
<%= render "partials/string2.erb" -%>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Second partial <%= @partial_key_2 %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
KEY1 [<%=@key1%>]
2+
KEY2 [<%=@key2%>]
3+
<%= render "partials/string1.erb" -%>

0 commit comments

Comments
 (0)