Unverified Commit ca147910 authored by j.knedlik's avatar j.knedlik Committed by GitHub
Browse files

Render Arrays and sub-Arrays via ERB if specified (#3)

* Render specified fields using ERB (#2)

* Add field 'template_fields' that runs ERB /fields

* Run template_field test only once per resource

* Also expand resource 'name' when specified

* Add small comments for erb expansion

* Enable trim mode for one line 'each'

* Updated Readme for ERB style attributes

* Remove unneeded node configs

* Fix minor typos

* Render Array elem if they are String (notifies)

* Render Subarrays recusively
parent 20d141de
...@@ -44,6 +44,22 @@ resource_list = %w( ...@@ -44,6 +44,22 @@ resource_list = %w(
route route
mount mount
) )
# func(value,node-object) recursively render Arrays and Strings using ERB
module BaseTemplateERB
def self.render_erbs(value,node)
case value
when Array
value=value.collect{|v| render_erbs(v,node) }
when String
if not node['base']['resources'].empty? if not node['base']['resources'].empty?
resource_list += node['base']['resources'] resource_list += node['base']['resources']
...@@ -85,14 +101,14 @@ resource_list.each do |resource| ...@@ -85,14 +101,14 @@ resource_list.each do |resource|
# Expand user defined 'name' of resource via ERB if specified # Expand user defined 'name' of resource via ERB if specified
expanded_name = template_fields.include?("name") ? expanded_name = template_fields.include?("name") ?
ERB.new(name,nil,'-').result_with_hash(node:node) : BaseTemplateERB::render_erbs(name,node) :
name name
public_send(resource, expanded_name) do public_send(resource, expanded_name) do
conf.each do |key,value| conf.each do |key,value|
# Expand config field via ERB if specified # Expand config field via ERB if specified
value=ERB.new(value,nil,'-').result_with_hash(node:node) if template_fields.include?key value=BaseTemplateERB::render_erbs(value,node) if template_fields.include?key
case key case key
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment