Can you use Erb outside of Apache?

K

Kyle Heon

------=_NextPart_000_004E_01C57CEC.D7D34340
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

I hope this doesn't sound like an odd question but as I'm learning Ruby I'm
trying to apply it to "real-world" applications that have some value at
work.

One of the projects that I've started working on is building a set of
code-generation templates (kind of like what CodeSmith
http://www.codesmithtools.com/) does in the .NET world.

Essentially what I want to be able to do is create a series of "templates"
that contain mostly static output that includes tags which are processed by
Ruby when read in much like the way Erb works inside an rhtml page.

So, my question is basically this: Can I embed Erb tags in a txt file (for
instance) and get them to process? All I've been able to find so far shows
how to use Erb in an rhtml page running on Apache. That isn't the
environment I want to work in.

Any pointers people can offer up is very much appreciated. If I am going
about this in a completely backwards (or reinvent the wheel) way and know of
a different approach I'm all ears -- as I said, I'm beginning to learn Ruby.

Thanks!

Kyle Heon
(e-mail address removed)



------=_NextPart_000_004E_01C57CEC.D7D34340--
 
K

Kyle Heon

Nevermind. I figured it out.

code:

require 'erb'
@foo = "Hello World!"
erb = ERB.new("<pre>foo: <%= @foo %></pre>")
erb.run

result:

<pre>foo: Hello World!</pre>

If there is a better way, I'm still open.

Kyle Heon
(e-mail address removed)


-----Original Message-----
From: Kyle Heon [mailto:[email protected]]
Sent: Wednesday, June 29, 2005 8:55 PM
To: ruby-talk ML
Subject: Can you use Erb outside of Apache?

I hope this doesn't sound like an odd question but as I'm learning Ruby I'm
trying to apply it to "real-world" applications that have some value at
work.

One of the projects that I've started working on is building a set of
code-generation templates (kind of like what CodeSmith
http://www.codesmithtools.com/) does in the .NET world.

Essentially what I want to be able to do is create a series of "templates"
that contain mostly static output that includes tags which are processed by
Ruby when read in much like the way Erb works inside an rhtml page.

So, my question is basically this: Can I embed Erb tags in a txt file (for
instance) and get them to process? All I've been able to find so far shows
how to use Erb in an rhtml page running on Apache. That isn't the
environment I want to work in.

Any pointers people can offer up is very much appreciated. If I am going
about this in a completely backwards (or reinvent the wheel) way and know of
a different approach I'm all ears -- as I said, I'm beginning to learn Ruby.

Thanks!

Kyle Heon
(e-mail address removed)
 
J

James Edward Gray II

Nevermind. I figured it out.

code:

require 'erb'
@foo = "Hello World!"
erb = ERB.new("<pre>foo: <%= @foo %></pre>")
erb.run

result:

<pre>foo: Hello World!</pre>

If there is a better way, I'm still open.

As you've seen, ERb is a general templating engine. Use it anywhere
you like.

If you want to know more, it is documented at http://ruby-doc.org/.

James Edward Gray II
 
J

Jacob Fugal

Nevermind. I figured it out.
=20
code:
=20
require 'erb'
@foo =3D "Hello World!"
erb =3D ERB.new("<pre>foo: <%=3D @foo %></pre>")
erb.run
=20
result:
=20
<pre>foo: Hello World!</pre>
=20
If there is a better way, I'm still open.

You can also use eruby on the command line:

$ cat hello.template=20
<%
def greet( who )
"Hello, #{who}!"
end
%><pre>foo: <%=3D greet( "world" ) %></pre>

$ eruby hello.template=20
<pre>foo: Hello, world!</pre>

Jacob Fugal
 
K

Kyle Heon

Thanks everyone. One more question.

What, if any, is the difference between Erb and eRuby?

Kyle Heon
(e-mail address removed)


-----Original Message-----
From: Jacob Fugal [mailto:[email protected]]
Sent: Thursday, June 30, 2005 11:58 AM
To: ruby-talk ML
Subject: Re: Can you use Erb outside of Apache?

Nevermind. I figured it out.

code:

require 'erb'
@foo = "Hello World!"
erb = ERB.new("<pre>foo: <%= @foo %></pre>") erb.run

result:

<pre>foo: Hello World!</pre>

If there is a better way, I'm still open.

You can also use eruby on the command line:

$ cat hello.template
<%
def greet( who )
"Hello, #{who}!"
end
%><pre>foo: <%= greet( "world" ) %></pre>

$ eruby hello.template
<pre>foo: Hello, world!</pre>

Jacob Fugal
 
J

James Edward Gray II

Thanks everyone. One more question.

What, if any, is the difference between Erb and eRuby?

ERb is pure Ruby and included with a Ruby install. eRuby is not
either of those.

Generally, I say use ERb unless it's too slow for your needs.

James Edward Gray II
 
G

Gene Tani

check out Jack Herrington's "Code Generation" book to see what Erb can
do when you push really hard.
 
C

Charles Steinman

Kyle said:
What, if any, is the difference between Erb and eRuby?

ERb is eRuby written in Ruby. (Both can be run from the command line,
by the way.)
 

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

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top