Which template for ruby-begin project?

Hi,

Once we used Template::Toolkit (Perl) and Smarty (PHP) for templates,
both are great.
Now if we begin a new web project with Ruby, and choose the Sinatra
framework, what’s the corrensponding template for it?
And I believe Sinatra is lighter and easier to learn than Rails, is it?

Thanks.

Ruby N. wrote:

Hi,

Once we used Template::Toolkit (Perl) and Smarty (PHP) for templates,
both are great.
Now if we begin a new web project with Ruby, and choose the Sinatra
framework, what’s the corrensponding template for it?
And I believe Sinatra is lighter and easier to learn than Rails, is it?

Thanks.

Most of the people I know use HAML ( http://haml-lang.com/). Erb and
Mustache( GitHub - defunkt/mustache-sinatra-example: An example of using Mustache in a Sinatra app.) are
options too.

From Sinatra Book →
http://www.sinatrarb.com/book.html#template_languages

Ruby N. wrote:

And I believe Sinatra is lighter and easier to learn than Rails, is it?

Yes - in the sense that it’s very much smaller, and you can easily grasp
the whole of it.

You’ll probably end up writing your own helper methods for the things
you need - which in many cases is easier that wading through Rails APIs
to try and find whether Rails has something pre-existing that you could
use, and how to use it.

As regards templates: note the following comment from the HEAD
(unreleased) version of Sinatra.

= 1.0 / unreleased

  • Sinatra now uses Tilt http://github.com/rtomayko/tilt for rendering
    templates. This adds support for template caching, consistent
    template backtraces, and support for new template engines, like
    markaby and liquid.

So that’s a good place to look at available templating options.

For generating (X)HTML I use HAML - you’ll either love it or hate it. I
love it because my templates are tiny, I never have to close any tags,
and I’m always guaranteed well-formed XML.

On Sat, Dec 12, 2009 at 9:14 PM, Brian C. [email protected]
wrote:

As regards templates: note the following comment from the HEAD
(unreleased) version of Sinatra.

Thank you Brian for the useful information.

Oh, and for an example of a ‘larger’ Sinatra app, look at Vegas:

I don’t like the default choice of templating language, but you can
steal ideas about how to bolt together things like ActiveRecord and
unit/functional tests.

On the subject of testing, have a look at Cucumber too, as that should
also play nicelyu with Sinatra, according to
http://wiki.github.com/aslakhellesoy/cucumber/sinatra

Brian C. wrote:
[…]

For generating (X)HTML I use HAML - you’ll either love it or hate it. I
love it because my templates are tiny, I never have to close any tags,
and I’m always guaranteed well-formed XML.

Unfortunately, you don’t want well-formed XML for Web apps – you want
well-formed HTML4. XHTML never quite fulfilled its promise, and is not
really supported in IE. (No, serving it as HTML is not the answer – the
syntaxes are just incompatible enough.) I used to serve XHTML from Web
apps, but I’ve changed them to HTML now that I understand the problems.

Fortunately, with Haml, this is just a question of tweaking an option or
two. With Rails, you also need the html_output plugin to get the
helpers playing along; I’m not sure about Sinatra.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]