[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Can you use Erb outside of Apache?

Kyle Heon

6/30/2005 12:55:00 AM

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.codesmith...) 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
kheon@comcast.net


7 Answers

Kyle Heon

6/30/2005 1:10:00 AM

0

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
kheon@comcast.net


-----Original Message-----
From: Kyle Heon [mailto:kheon@comcast.net]
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.codesmith...) 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
kheon@comcast.net





James Gray

6/30/2005 3:21:00 AM

0

On Jun 29, 2005, at 8:10 PM, Kyle Heon wrote:

> 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://rub....

James Edward Gray II


Jacob Fugal

6/30/2005 3:58:00 PM

0

On 6/29/05, Kyle Heon <kheon@comcast.net> wrote:
> 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


Kyle Heon

6/30/2005 11:54:00 PM

0

Thanks everyone. One more question.

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

Kyle Heon
kheon@comcast.net


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

On 6/29/05, Kyle Heon <kheon@comcast.net> wrote:
> 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



James Gray

7/1/2005 12:17:00 AM

0

On Jun 30, 2005, at 6:53 PM, Kyle Heon wrote:

> 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


Gene Tani

7/1/2005 4:34:00 PM

0

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

acharlieblue

7/1/2005 6:09:00 PM

0



Kyle Heon wrote:
> 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.)