Can you use Erb outside of Apache?

Discussion in 'Ruby' started by Kyle Heon, Jun 30, 2005.

  1. Kyle Heon

    Kyle Heon Guest

    ------=_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




    ------=_NextPart_000_004E_01C57CEC.D7D34340--
     
    Kyle Heon, Jun 30, 2005
    #1
    1. Advertising

  2. Kyle Heon

    Kyle Heon Guest

    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



    -----Original Message-----
    From: Kyle Heon [mailto:]
    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
     
    Kyle Heon, Jun 30, 2005
    #2
    1. Advertising

  3. 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://ruby-doc.org/.

    James Edward Gray II
     
    James Edward Gray II, Jun 30, 2005
    #3
  4. Kyle Heon

    Jacob Fugal Guest

    On 6/29/05, Kyle Heon <> wrote:
    > 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
     
    Jacob Fugal, Jun 30, 2005
    #4
  5. Kyle Heon

    Kyle Heon Guest

    Thanks everyone. One more question.

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

    Kyle Heon



    -----Original Message-----
    From: Jacob Fugal [mailto:]
    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 <> 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, Jul 1, 2005
    #5
  6. 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
     
    James Edward Gray II, Jul 1, 2005
    #6
  7. Kyle Heon

    Gene Tani Guest

    check out Jack Herrington's "Code Generation" book to see what Erb can
    do when you push really hard.
     
    Gene Tani, Jul 1, 2005
    #7
  8. 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.)
     
    Charles Steinman, Jul 1, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon A. Lambert
    Replies:
    1
    Views:
    204
    Jon A. Lambert
    Feb 12, 2004
  2. Steve V
    Replies:
    6
    Views:
    238
    Steve V
    Apr 20, 2005
  3. David Lewis

    erb & action_view outside rails

    David Lewis, Nov 16, 2008, in forum: Ruby
    Replies:
    3
    Views:
    119
    Brian Candler
    Nov 16, 2008
  4. Jonny Noog

    eRuby/erb outside of Rails

    Jonny Noog, Nov 28, 2008, in forum: Ruby
    Replies:
    16
    Views:
    248
    Dave Bass
    Dec 28, 2008
  5. Dan Thomas

    link to .erb file, from .erb file

    Dan Thomas, Jan 26, 2011, in forum: Ruby
    Replies:
    4
    Views:
    166
    Dan Thomas
    Jan 26, 2011
Loading...

Share This Page