# Erb with -%\> from command line?

**URL:** <https://www.ruby-forum.com/t/erb-with-from-command-line/110752>\
**Category:** Rails\
**Created:** [July 30, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/erb-with-from-command-line/110752 "2007-07-30T17:11:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 30, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/erb-with-from-command-line/110752/1 "2007-07-30T17:11:59Z")

</div>

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.

Thank you  
Hugh

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 30, 2007, 5:23pm UTC](https://www.ruby-forum.com/t/erb-with-from-command-line/110752/2 "2007-07-30T17:23:00Z")

</div>

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 🙂

-Chuck V.

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 30, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/erb-with-from-command-line/110752/3 "2007-07-30T17:55:07Z")

</div>

On Mon, 30 Jul 2007, Chuck V. wrote:

> 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.

1. 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.

2. Haml seems geared to tackle the verbosity of HTML, abut I don’t  
immediately see from the tutorial how it helps with Ruby  
interpolation.

3. 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.

```
    Thank you
    Hugh
```

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 30, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/erb-with-from-command-line/110752/4 "2007-07-30T18:18:09Z")

</div>

> 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.

when I invoke `erb -T "-" tom.rhtml` I get

tom.rhtml:

\<% @tom = 3 -%\>

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.

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 30, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/erb-with-from-command-line/110752/5 "2007-07-30T18:39:14Z")

</div>

On Mon, 30 Jul 2007, Chuck V. wrote:

```
    [...]

```

> > 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 “-” tom.rhtml

```
0 1 2 3 4
```

hgs@Q2P14HGS ~/nonsense-0.6  
$ cat tom.rhtml

```
<%= s = ""; 5.times{|k| s += k.to_s + " "}; s -%>
```

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:in`upto’  
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
```
