Hi,
After having some issues with eRuby and embedded ruby in HTML, Im trying
to find out if its possible to develop a web page in the same way that
ASP.NET works.
Basically you straight HTML with no embedded script and when all the
data is posted back to the server, you can use c# (or any language) to
handle and process the data returned.
I think CGI is different to what im after. Im looking at doing all my
processing in ruby and keeping my html 'clean'
Can someone point me in the right direction?
Probably, but it is a little hard to figure out just what direction is
actually the right one for you.
My assumption is that you don't want to embed code right inside your HTML,
like erb does with Ruby, or like the traditional PHP development style.
Rather, you want to write straight HTML. Have your forms forms, links, or
whatever trigger Ruby code execution which handles the data submitted, and
then either returns dynamically generated HTML or redirects to another
static page?
I think, to varying extents, you can some some or all of the above with
any of (in alphabetical order), Camping, IOWA, or Nitro.
Camping makes use of a nice little Ruby DSL called markaby to let you
write Ruby code that looks like the HTML that it generates. From the
camping web site: (
http://code.whytheluckystiff.net/camping)
p 'Hi my name is Charles.'
p 'Here are some links:'
ul do
li { a 'Google', :href => '
http://google.com' }
li { a 'A sample page', :href => '/sample' }
end
There is a community of people to help with it on freenode, at #camping.
IOWA is my framework. I went and ripped up its internals in interesting
ways over the last few months, but it's mostly stable again. I released
0.99.2.17 -- It's Mostly Stable Again! -- today on Rubyforge
(
http://rubyforge.org/frs/?group_id=198). The codebase is now running a
new production web site, so I feel it's pretty darn close to stable again.
It uses a templating system that does not permit directly intermingling
Ruby with HTML. Instead, it offers a very small set of special purpose
tags to facilitate looping and conditional content, combined with the
ability to embed the output of Ruby methods into the generated content.
The combination is easy to learn to use but keeps the templates looking
like clean HTML.
http://enigo.com/projects/iowa for some old docs that
are still pretty much accurate when it comes to the templating. See the
/examples/hello_world/iowa dir for a simple sample app. I'm usually on
#iowa on freenode, too, if you have questions.
A snippet of an IOWA template:
<table id="DailyNav">
<repeat oid="nav data" list="navs" item="nav">
<tr class="@rowclass">
<td class="left">
@nav_name
</td>
<td>
@fundsym
</td>
<td>
@nav.price
</td>
<td>
@nav.change_price
</td>
<td>
<a href="/performance.html">Check YTD</a>
</td>
</tr></repeat>
</table>
Nitro is a framework that uses an xhtml oriented templating system. It is
a capable, performant framework, too. Nitro does allow you to embed code
in with the HTML, but also offers a way to do render HTML content from
within Ruby code. There are always folks on freenode at #nitro who are
happy to answer Nitro questions.
A snippet of a Nitro template;
<?r @todolists.each do |todolist| ?>
<div class="todolist">
<div class="todolist_title">#{todolist.title}</div>
<?r todolist.items.each do |item| ?>
<div class="todolist_item">
<div class="todolist_item_title">#{item.title}</div>
<div class="todolist_item_text">#{item.text}</div>
</div>
<?r end ?>
</div>
<?r end ?>
Kirk Haines