Setting local variables for 'erb' command-line tool

B

Brian Candler

I have a bunch of *.erb files which I would like to expand using the
'erb' command-line tool from within a shell script.

However, I can't see how to set local variables so that <%= foo %>
works, other than piping the input onto stdin whilst prepending a
section like this:

<%
foo=123
bar="baz"
%>

Am I being dense here, or is this the only way to do it?

Thanks,

Brian.
 
J

James Edward Gray II

I have a bunch of *.erb files which I would like to expand using the
'erb' command-line tool from within a shell script.
=20
However, I can't see how to set local variables so that <%=3D foo %>
works, other than piping the input onto stdin whilst prepending a
section like this:
=20
<%
foo=3D123
bar=3D"baz"
%>
=20
Am I being dense here, or is this the only way to do it?

erb has a command-line switch to require a library. That library could =
define top-level methods to serve as your local variables. Just a =
thought.

James Edward Gray II=
 
B

Brian Candler

James Edward Gray II wrote in post #950195:
erb has a command-line switch to require a library. That library could
define top-level methods to serve as your local variables. Just a
thought.

Thanks for that idea.

What I'm doing for now is:

erb -T - erb.conf src.erb

where erb.conf contains local variable definitions:

<%
foo="bar"
... etc
-%>

This is working fine, except that any errors in src.erb are reported
with an offset line number. e.g.

templates/wrapper.sh.erb:41: warning: found = in conditional, should be
==

(error actually in line 26 of that file, and erb.conf is 15 lines long)

Cheers,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top