# Code behind HTML

**URL:** <https://www.ruby-forum.com/t/code-behind-html/72479>\
**Category:** Ruby\
**Created:** [October 17, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479 "2006-10-17T15:15:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 17, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/1 "2006-10-17T15:15:49Z")

</div>

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](http://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?

Thank you,  
Vince

P.S  
Im not interested in Rails.

---

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 17, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/2 "2006-10-17T18:13:26Z")

</div>

Vince /. \<totalharmonicdistortion [hotmail.com](http://hotmail.com)\> writes:

> Hi,

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](http://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.

How does [ASP.NET](http://ASP.NET) give users feedback (i.e. generate error messages and  
other  
dynamic content?) It seems to me that HTML must be programmatically  
generated  
somewhere along the way…

---

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 18, 2006, 8:18pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/3 "2006-10-18T20:18:55Z")

</div>

> Wilson B. wrote:
> 
> … you could go with a templating solution such as Liquid, instead of ERb. That way  
> there’s no direct ‘Ruby’ code mixed into your HTML.

Or with a templating solution such as:

[http://amrita2.rubyforge.org](http://amrita2.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 17, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/4 "2006-10-17T20:01:57Z")

</div>

On 10/17/06, Vince /. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

What you’ve described isn’t actually how [ASP.NET](http://ASP.NET) works, but I can  
understand what you’re looking for.  
I would say that ‘Merb’ is probably as close as it gets for Ruby  
webapps right now:  
[http://brainspl.at/articles/2006/10/09/introducing-the-merb](http://brainspl.at/articles/2006/10/09/introducing-the-merb)

Alternatively (or in addition to Merb), you could go with a templating  
solution such as Liquid, instead of ERb. That way there’s no direct  
‘Ruby’ code mixed into your HTML. Some people like it that way.

---

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 18, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/5 "2006-10-18T22:33:25Z")

</div>

On 10/18/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> <?r end ?>
> 
> ```
> 
> \<?r end ?\>

Similarly, MasterView another template library which keeps the code  
out of the html, the code would look like this.

- this will be replaced with actual title

MasterView has been primarily designed to work with Rails having  
directives that utilize rails helpers, however it can also be used  
with standard Ruby ERB if you forgo the Rails based directives.

The project is in Rubyforge and other documentation/videos are available  
at  
[http://masterview.org/](http://masterview.org/)

If you have any questions just shoot me an email.

Jeff

---

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 18, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/6 "2006-10-18T22:39:30Z")

</div>

oops. Forgot the namespace for the attributes should be prefixed with  
mv: I have corrected it inline below.

On 10/18/06, Jeff B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > </div>
> > <?r end ?>
> > 
> > ```
> > 
> > \<?r end ?\>
> 
> Similarly, MasterView another template library which keeps the code  
> out of the html, the code would look like this.

- this will be replaced with actual title

---

<div class="post-metadata">

**Author:** ![vincpa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e19adc/32.png) [@vincpa](https://www.ruby-forum.com/u/vincpa)\
**Post date:** [October 18, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/code-behind-html/72479/7 "2006-10-18T21:59:07Z")

</div>

On Tue, 17 Oct 2006, Vince /. wrote:

> 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](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](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](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:

| @nav\_name | @fundsym | @nav.price | @nav.change\_price | [Check YTD](https://www.ruby-forum.com/performance.html) |

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| ?\> 

#{todolist.title}
 \<?r todolist.items.each do |item| ?\> 

#{item.title}

#{item.text}

 \<?r end ?\> 
\<?r end ?\>

Kirk H.
