Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/59839


Change subject: Fixing a bug in expanderb.rb. Also avoiding syntax error on -%> 
 closing tags.
......................................................................

Fixing a bug in expanderb.rb.
Also avoiding syntax error on -%>  closing tags.

Change-Id: I9077cc3e89bdb5a240397b3aabad35c17343848e
---
M expanderb.rb
1 file changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/39/59839/1

diff --git a/expanderb.rb b/expanderb.rb
index 11d0ad1..492114b 100755
--- a/expanderb.rb
+++ b/expanderb.rb
@@ -11,6 +11,7 @@
 # Command line option parsing library
 require 'optparse'
 require 'erb'
+require 'ostruct'
 
 # Filename of the ERB template we are going to expand
 $filename = nil
@@ -53,15 +54,21 @@
 end
 p template_values
 
-def get_values(key)
-       template_values[key]
+
+
+def render_erb(template, locals)
+       # make sure we can render templates with -%> closing tags.
+       # Note that this does not actually remove newlines after -%>, it just
+       # avoids a syntax error.
+       ERB.new(template, nil, 
'%<>-').result(OpenStruct.new(locals).instance_eval { binding })
 end
 
 
+# template_binding = TemplateVariables.new(template_values).get_binding
+
 # Parse template
 begin
-       template = ERB.new(File.read($filename))
-       p template.result(get_values)
+  puts render_erb(File.read($filename), template_values)
 rescue
        p "Something went wrong, usually because you are missing a variable."
        p $!.to_s

-- 
To view, visit https://gerrit.wikimedia.org/r/59839
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9077cc3e89bdb5a240397b3aabad35c17343848e
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to