# Newbie html question

**URL:** <https://rubytalk.org/t/newbie-html-question/21984>\
**Category:** ruby-talk\
**Created:** [28 October 2005 12:14 UTC](https://rubytalk.org/t/newbie-html-question/21984 "2005-10-28T12:14:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Newman](https://avatars.discourse-cdn.com/v4/letter/c/4da419/32.png) [@Chris\_Newman](https://rubytalk.org/u/Chris_Newman)\
**Post date:** [28 October 2005 12:14 UTC](https://rubytalk.org/t/newbie-html-question/21984/1 "2005-10-28T12:14:50Z")

</div>

Hi,

I'm just starting to learn ruby and would like to know the best library to  
use to create a static html page from a cron job. The page will contain the  
results of a database query displayed as an html table. Some sort of  
template package might be best. I already have dbi working to do the query.

Any advice would be appreciated.

Thanks,

cn

---

<div class="post-metadata">

**Author:** ![Brian\_Schroder1](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@Brian\_Schroder1](https://rubytalk.org/u/Brian_Schroder1)\
**Post date:** [28 October 2005 12:19 UTC](https://rubytalk.org/t/newbie-html-question/21984/2 "2005-10-28T12:19:50Z")

</div>

Simple onboard possibilities would be the cgi package (though that  
needs some twists to use it as an emitter) or erb/eruby, a general  
templating system.

regards,

Brian

> **···**
>
> On 28/10/05, Chris Newman \<Chris.Newman@dalsemi.com\> wrote:
> 
> > Hi,
> > 
> > I'm just starting to learn ruby and would like to know the best library to  
> > use to create a static html page from a cron job. The page will contain the  
> > results of a database query displayed as an html table. Some sort of  
> > template package might be best. I already have dbi working to do the query.
> > 
> > Any advice would be appreciated.
> > 
> > Thanks,
> > 
> > cn
> 
> --  
> [http://ruby.brian-schroeder.de/](http://ruby.brian-schroeder.de/)
> 
> Stringed instrument chords: [http://chordlist.brian-schroeder.de/](http://chordlist.brian-schroeder.de/)

---

<div class="post-metadata">

**Author:** ![Ezra\_Zygmuntowicz4](https://avatars.discourse-cdn.com/v4/letter/e/d2c977/32.png) [@Ezra\_Zygmuntowicz4](https://rubytalk.org/u/Ezra_Zygmuntowicz4)\
**Post date:** [28 October 2005 17:48 UTC](https://rubytalk.org/t/newbie-html-question/21984/3 "2005-10-28T17:48:14Z")

</div>

> Hi,
> 
> I'm just starting to learn ruby and would like to know the best library to  
> use to create a static html page from a cron job. The page will contain the  
> results of a database query displayed as an html table. Some sort of  
> template package might be best. I already have dbi working to do the query.
> 
> Any advice would be appreciated.

Hey there-  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Here is an example of generating html with erb in the stdlib docs:

Ruby in HTML  
ERB is often used in .rhtml files (HTML with embedded Ruby). Notice the need in this example to provide a special binding when the template is run, so that the instance variables in the Product object can be resolved.

&nbsp;&nbsp;&nbsp;require "erb"

&nbsp;&nbsp;&nbsp;# Build template data class.  
&nbsp;&nbsp;&nbsp;class Product  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def initialize( code, name, desc, cost )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@code = code  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@name = name  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@desc = desc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@cost = cost

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@features =   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def add\_feature( feature )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@features \<\< feature  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Support templating of member data.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def get\_binding  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binding  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ...  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;# Create template.  
&nbsp;&nbsp;&nbsp;template = %{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<html\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<head\>\<title\>Ruby Toys -- \<%= @name %\>\</title\>\</head\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<body\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<h1\>\<%= @name %\> (\<%= @code %\>)\</h1\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<p\>\<%= @desc %\>\</p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<ul\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% @features.each do |f| %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<b\>\<%= f %\>\</b\>\</li\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</ul\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<p\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if @cost \< 10 %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<b\>Only \<%= @cost %\>!!!\</b\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% else %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call for a price, today!  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</body\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</html\>  
&nbsp;&nbsp;&nbsp;}.gsub(/^ /, '')

&nbsp;&nbsp;&nbsp;rhtml = ERB.new(template)

&nbsp;&nbsp;&nbsp;# Set up template data.  
&nbsp;&nbsp;&nbsp;toy = Product.new( "TZ-1002",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Rubysapien",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Geek's Best Friend! Responds to Ruby commands...",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;999.95 )  
&nbsp;&nbsp;&nbsp;toy.add\_feature("Listens for verbal commands in the Ruby language!")  
&nbsp;&nbsp;&nbsp;toy.add\_feature("Ignores Perl, Java, and all C variants.")  
&nbsp;&nbsp;&nbsp;toy.add\_feature("Karate-Chop Action!!!")  
&nbsp;&nbsp;&nbsp;toy.add\_feature("Matz signature on left leg.")  
&nbsp;&nbsp;&nbsp;toy.add\_feature("Gem studded eyes... Rubies, of course!")

&nbsp;&nbsp;&nbsp;# Produce result.  
&nbsp;&nbsp;&nbsp;rhtml.run(toy.get\_binding)  
Generates (some blank lines removed):

&nbsp;&nbsp;&nbsp;&nbsp;\<html\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<head\>\<title\>Ruby Toys -- Rubysapien\</title\>\</head\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<body\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<h1\>Rubysapien (TZ-1002)\</h1\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<p\>Geek's Best Friend! Responds to Ruby commands...\</p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<ul\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<b\>Listens for verbal commands in the Ruby language!\</

> \</li\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<b\>Ignores Perl, Java, and all C variants.\</b\>\</li\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<b\>Karate-Chop Action!!!\</b\>\</li\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<b\>Matz signature on left leg.\</b\>\</li\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<b\>Gem studded eyes... Rubies, of course!\</b\>\</li\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</ul\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<p\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call for a price, today!  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</body\>  
&nbsp;&nbsp;&nbsp;&nbsp;\</html\>

Cheers-

-Ezra Zygmuntowicz  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
ezra@yakima-herald.com

> **···**
>
> On Oct 28, 2005, at 5:14 AM, Chris Newman wrote:
