I can’t seem to google this one effectively: Can someone tell me
how to invoke erb in such a way that the -%> sequence kills newlines
as it does in rails? I’ve tried everything I can think of, effectively
for i in 0 1 2 ‘-’ do
erb -T $i template.rhtml
done
but I can’t get it to work – erb still sees the - as part of the
text. Does Rails invoke something else? I can’t see any refs to
what that might be in AWDWR. I’m trying to create something outside
rails, so can’t just put this where a template would live.
I don’t know the answer to this problem but i may have a workaround.
If you’re just using it to generate html have you considered Haml or
Markaby instead of erb? They might be easier to use and suffer newline
problems differently.
On the other hand, if you’re using erb to parse text (eg: a yaml file)
then this probably wouldn’t help much.
If nothing my hope is that you didn’t know about Haml and fall
instantly in love with it
I don’t know the answer to this problem but i may have a workaround.
If you’re just using it to generate html have you considered Haml or
Markaby instead of erb? They might be easier to use and suffer newline
problems differently.
OK, I’ve looked at that now.
I’m trying to do this outside rails, so I get static data for
my fixtures generated just the once, for now. Maybe later I’ll
regenerate it each time to cook up stress tests, but for now…
So this being a plugin is not actually much help unless it is
accessible outside Rails. I don’t see much about that from
the tutorial.
Haml seems geared to tackle the verbosity of HTML, abut I don’t
immediately see from the tutorial how it helps with Ruby
interpolation.
It’s just one more wafer thin syntax to learn.
On the other hand, if you’re using erb to parse text (eg: a yaml file)
then this probably wouldn’t help much.
I’m generating YAML programmatically.
If nothing my hope is that you didn’t know about Haml and fall
instantly in love with it
People are going to have a job spreading this meme to their parents
with things like this in the tutorial:
“Yrg’f gnxr gung shpxre naq znxr vg n Unzy Unvxh!!!”.rot13
Programs that semi-automatically decide on site blocking may get
interesting results, as well…
-Chuck V.
Thank you for your answer, all the same. I’ve not closed my
mind to this possibility, and it may well have other features
I need, even for other things.
as it does in rails? I’ve tried everything I can think of, effectively
for i in 0 1 2 ‘-’ do
erb -T $i template.rhtml
done
[…]
Doesn’t even work with the other trim settings. Can you drop us the
rhtml you’re using? Not sure why it seems to work on mine but not on
yours.
Ah. I see what is happening now. If I reduce my example to slightly
bigger than yours I get this (Cygwin):
hgs@Q2P14HGS ~/nonsense-0.6
$ erb -T “-” test_employees.rhtml
test_employees.rhtml:13:in ``’: Interrupt
from test_employees.rhtml:13:in nonsense' from test_employees.rhtml:128 from test_employees.rhtml:123:inupto’
from test_employees.rhtml:123
hgs@Q2P14HGS ~/nonsense-0.6
$
So If I don’t use -T “-” or -T ‘-’ I get the errors I had before,
but when this didn’t do anything I thought it was treating the - as
stdin and it was sitting there, waiting. I’ve disproved that now, so
I’ve thereby proved something is taking forever in my code, which is
being interpreted correctly. I’ll spare you the details of my buggy
code, and thank you for helping me prove that assumption (of stdin)
was wrong.
Thank you,
Hugh
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.