I'm trying to implement a Rake task that will syntax validate an ERB
template. Up to now I was always able to do this with "erb -P -x -T '-'
/path/to/template | ruby -c" on the command line but doing this
individually for a lot of files becomes slow pretty quickly.

I'd hoped to implement this in Ruby and so far I'v got this:


error_string = ""
failures = 0
Dir["**/*.erb"].each do |template|
    begin
        ERB.new(File.read(File.expand_path(template)), nil, '-').result
    rescue SyntaxError => e
        error_string += "Template Error on #{template}: #{e.message}\n"
        failures += 1
    end
end


Unfortunately this blows up fairly explosively since I'm not providing a
binding in result() causing the evaluation of the template to fail
because different variables that have things done to them in the
template are now nil so a lot of method calls fail.

Looking at some of the ERB code I figured I could try run() to with and
without passing on TOPLEVEL_BINDING.taint but that didn't change
anything. I have no idea what TOPLEVEL_BINDING.taint is supposed to do
in the first place or how that would magically solve the issue.

However, the command line seems to be able to get past this issue and
just check the syntax, not try to evaluate the template but I can't seem
to replicate that. I was curious if someone knew what I need to do to
fix this?

-- 
Posted via http://www.ruby-forum.com/.