views:

333

answers:

6

Hello,

I am looking for a simple templating solution for ruby, i.e. something that will let me write php-like or jsp-like templates (html with embedded code tags), but in ruby. jsp is no good for me, because most hosting services (I'm on dreamhost) don't support it on their default package, and it's a little cumbersome to set up. php is easy to get up and running, but I hate the syntax, and I miss all the greatness of ruby.

erb seems to be close to what I'm looking for, but how do I set up the server (htaccess file etc) to serve it?

P.S. Please do not suggest Ruby On Rails. It's a huge overkill for what I'm doing.

+3  A: 

ERB is built into the language as part of its core. In case you don't know what it is, it's the template engine behind Ruby on Rails that comes with Ruby. (So don't attribute it to Rails.) It is powerful enough for any purpose you have in mind.

I have used ERB on my own to make a script that took an RSS feed and output the articles into an html file. So don't complain that it is heavyweight ... because it was slower to download the articles and parse them through the XML parser than it was to output the html.

The Wicked Flea
+1, it should be enough for your purpose. Now, if you ask me, the PHP way of writing code inside HTML and all that is bad. If you're not, that's fine.
Keltia
It CAN let you make abominable PHP-like messes, yes, but I've never used it for such. Usually these things are output formatting, and boolean and loop constructs.
The Wicked Flea
I've used it for webpages in an RoR site, but also for generating templates for C++ code, Visual Studio project and solution files, among others.
Daemin
+4  A: 

You can find pretty neat tutorial about how to set up all the server stuff for serving html with eruby over here.

Milan Novota
A: 

To add something to the first answer, if you have performance issues with ERB, then you can try Erubis. It is a very fast and compatible version of ERB.

Keltia
+2  A: 

if your webserver has rack you should check out waves. It's a minimal framework that will let you do erb or erubis templated with minimal overhead.

jshen
A: 

ok, I get it. Thanks.

ERB is the way to go for me. The configuration script for dreamhost is here, if you're interested:

Ovesh
A: 

ERB is the obvious choice, but I've grown to like Haml & Sass too. They're extremely terse.

If what you're looking for is a microframework, Sinatra is nice and easy, and supports multiple templating languages, including ERB and Haml.

scottburton11