ERB generates unwanted EOLs

(Robert William Vesterman) #1

If I add any inline code to an ERB template, extraneous end of line
characters are generated. For example, I want to generate the output:

#include “x.h”
#include “y.h”
#include “z.h”

So I have a template that’s something like:

<% headers.each { |name| %>
#include “<%= name %>”
<% } %>

Instead of the output that I want, this generates:

#include “x.h”

#include “y.h”

#include “z.h”

I can get the output that I want in this case by doing something like:

<% headers.each { |name| %>
#include “<%= name %>”<% } %>

But that’s only good in relatively trivial cases like this - if I want
to put a large amount of code inline, there’s virtually no way I won’t
be getting lots and lots of extraneous EOLs.

I gather, from the book “Code Generation in Action” by Jack
Herrington, that this is not supposed to happen - that is, my expected
output is the output that is supposed to happen.

Am I doing something wrong? Do I have something misconfigured? Is
there a way to fix this problem?

I am running Ruby on Windows XP, in case that matters.

Thanks in advance for any help.

Bob Vesterman.