newbie html question

C

Chris Newman

------_=_NextPart_001_01C5DBB9.285BFEBC
Content-Type: text/plain

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

------_=_NextPart_001_01C5DBB9.285BFEBC--
 
B

Brian Schröder

Hi,

I'm just starting to learn ruby and would like to know the best library t= o
use to create a static html page from a cron job. The page will contain t= he
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 quer= y.

Any advice would be appreciated.

Thanks,

cn

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
 
E

Ezra Zygmuntowicz

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

require "erb"

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

@features = [ ]
end

def add_feature( feature )
@features << feature
end

# Support templating of member data.
def get_binding
binding
end

# ...
end

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

<h1><%= @name %> (<%= @code %>)</h1>
<p><%= @desc %></p>

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

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

</body>
</html>
}.gsub(/^ /, '')

rhtml = ERB.new(template)

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

# Produce result.
rhtml.run(toy.get_binding)
Generates (some blank lines removed):

<html>
<head><title>Ruby Toys -- Rubysapien</title></head>
<body>

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

<ul>
<li><b>Listens for verbal commands in the Ruby language!</
b></li>
<li><b>Ignores Perl, Java, and all C variants.</b></li>
<li><b>Karate-Chop Action!!!</b></li>
<li><b>Matz signature on left leg.</b></li>
<li><b>Gem studded eyes... Rubies, of course!</b></li>
</ul>

<p>
Call for a price, today!
</p>

</body>
</html>


Cheers-

-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
(e-mail address removed)
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top