CGI programming

R

Robert

What do you use when programming Ruby/CGI? Do you just use straight Ruby or
do you use any templating modules?

I am running Apache on Windows XP.

Robert
 
L

Lothar Scholz

Hello Robert,

R> What do you use when programming Ruby/CGI? Do you just use straight Ruby or
R> do you use any templating modules?

Amrita and eRuby.
 
D

David A. Black

Hi --

What do you use when programming Ruby/CGI? Do you just use straight Ruby or
do you use any templating modules?

I've made a lot of use of the Template module from RubLog.


David
 
R

Robert Klemme

There's a class CGI. And there's a lot of templating systems, eruby, amrita
you name it.

robert
 
S

Sam Stephenson

Hi Robert,

What do you use when programming Ruby/CGI? Do you just use straight Ruby or
do you use any templating modules?

Here is a tiny template ``engine'' I use that creates a Struct class
and defines its #to_s method:

| class StructTemplate
| TEMPLATES = {}
| def StructTemplate.new(template, *args)
| klass = Struct.new(*args)
| TEMPLATES[klass] = template.to_s
| klass.class_eval do
| def to_s
| TEMPLATES[self.class].gsub(/\#\{(.*?)\}/) do
| method($1).call.to_s if respond_to? $1
| end
| end
| end
| klass
| end
| end

You might have a file template that looks like this (let's call it
``page.tmpl''):

| <html>
| <head>
| <title>#{title}</title>
| </head>
| <body>
| #{content}
| </body>
| </html>

Then you could use it like this:

| require 'cgi'
| cgi = CGI.new
| PageT = StructTemplate.new('page.tmpl', :title, :content)
|
| page = PageT.new
| page.title = 'Hello World!'
| page.content = 'Content goes here'
| cgi.out {page}

Since StructTemplate#to_s calls #to_s on each member as it's being
substituted into the template, you can create fairly complex output by
nesting templates. If you have a page with many ``objects'' that are
alike (say, for instance, a weblog with multiple ``entries''), you can
create StructTemplates for those objects and pass an array of them to
the page template for its content.

It's not advanced by any means, but it's certainly simple and
relatively easy to use.

Sam
 
A

Austin Ziegler

Hi --



I've made a lot of use of the Template module from RubLog.

Speaking of that, the current CVS HEAD of Ruwiki has a heavily
modified version of the Template module from Rdoc (I think they're
similar; if they have !INCLUDE! directives, they probably arte) that
you may want to play with. I actually think that the modified version
has some neat features (labels vs. variables, optional labels and
names, inline if/ifnots and repeats).

-austin
 
K

Kirk Haines

What do you use when programming Ruby/CGI? Do you just use straight Ruby

I personally use Iowa. Iowa is an object based web application & dynamic
content framework that runs on both *nix and Windows platforms. It features
seperation of code from layout. In that contiuum it inhabits a place
somewhere between Rails and CGIKit, with much greater seperation than Rails,
but less forced seperation than CGIKit requires.

Iowa templates are simple. They are straight HTML with a small amount of
very simple but flexible special markup. Templates create components, and
components are embedable in other components. In this way one can create
reusable widgets.

i.e. a conditional:

<if oid="has_user?"><p>Welcome @user!</p></if>

It can be found at http://rubyforge.org/projects/iowa

Anyway, it is what I use. I've been using it for over two years on a
variety of successful production web sites and web based applications from
small to large.

If you want to check it out, it's at Rubyforge:

http://rubyforge.org/projects/iowa

Feel free to email me with any question.


Kirk Haines
 

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
474,155
Messages
2,570,871
Members
47,401
Latest member
CliffGrime

Latest Threads

Top