Logic free templates for Ruby on Rails - ruby-on-rails

I am looking for a technique for moving Ruby on Rails methods and logic (<% if, link_to etc.) away from templates. So far I have been looking at the mustache template language, but I am not entire sure if this is the way to go.
Any thoughts? Would you recommend mustache or is there a better choice?

In addition to Mustache, there is Liquid (used by Shopify) and Radius (used by Radiant). You may want to check them out.

Related

Ruby on Rails Views. (Best Practice)

This might seem like a strange question. But have been pondering over this for quite some time now.
Is it better to use RAW HTML in Rails views or to go with Rails view helpers??
If i understand correctly Rails views helpers are converted back to raw HTML. So would it affect the performance of the application by a great deal ??
And is there a tool that would allow me to convert HTML to ERB :)
I'm aware of the HTML to HAML converter.
Thank you,
Certainly better to use a rails helper, as this allows you to create dynamic elements
Use Rails helpers, they guarantee the latest HTML good practice are used and up to date.

Using handlebarsjs as a template for Rails instead of HAML or Slim?

I'm potentially looking to standardize view/design templates for projects across the board with a singular template framework. Given that we are starting to see work for JS frameworks that can leverage Handlebars, it would seem potentially prudent to likewise begin using Handlebars to replace our usage of HAML (via Handlebars.rb and handlebars_assets).
Does this, experientially, work effectively? Or can you provide a link to some explanation of why or why not this will work or an example of such a use case?
Obviously HAML and (more sexy) Slim offer a cleaner template syntax for the most part, but Handlebars.js does have advantages that it carries from Liquid in that it's much more like plain HTML and therefore more "designer friendly."

Pure HTML template solution for Rails?

I love HAML, however recently our projects have come under some scrutiny with regards to reliance on non-html structured templates. I thought I'd take it a step further by asking the question, "How can we use pure HTML design based templates in Ruby on Rails?"
The closest thing I've found so far is a very interesting project that has it's most recent update from 2010 called Kwartz from the author of Erubis.
Is there a project that upholds this pure HTML isolation for designers that is up-to-date and viable on Rails 3.2.x?
Your designers are correct that HAML does not have widespread HTML tool support.
A really excellent solution IMHO is Handlebars. It is simpler than HAML, and will work with more HTML tools because Handlebars emphasizes moving code out of the page template and into the controller. This also is good for writing maintainable pages with designers and also for security.
Handlebars is led by Yehuda Katz, who helped write Rails 3, is a core contributor to JavaScript, and is currently working on Ember.js which also leverages Handlebars.
http://handlebarsjs.com/
You are either going to do something with the templates, right? As in, the designer gives you the template, you strip out the parts that already belong to app/views/layouts/application, inject the necessary ruby to get your data into the view etc.
So what's the problem? Let the designers provide their templates in HTML, you convert them to HAML when using in the app, instead of converting them to ERB.

Is there anything like Grails taglibs for Ruby on Rails?

I have a few months of experience with Ruby on Rails and really loved it from the beginning on. Now, for work, I was asked to code in Grails and although I first had some objections, I now think it's a very decent framework.
One thing that really impressed me in Grails are Taglibs because they make frontend modularity so much easier.
I would really like to do something with Rails.
Is there anything like Taglibs for Rails?
If not, what are the best practices for accomplishing this kind of view modularity (and, in essence, making my life easier)?
You can build your own helpers and the views can access those helpers. Take as an example formtastic, which provides extra methods/tags to build forms.
Strictly speaking, formtastic is a rails plugin, but it follows the same principles.

Using liquid with haml

I'm planning to develop a CMS with ruby/rails. One of the main key features that I'm planning is to give the user to edit their layout (I'm planning to do this through liquid)
meanwhile i have red some good articles on HAML and SaaS. So just wondering whether i can use
haml + liquid + sass for my work
If possible i would thankful if you could point me some resources
thanks in advance
cheers,
sameera
I think that is possible, take a look at this project mixing Jekyll, Haml and SCSS.
I don't think that HAML and Liquid are really compatible. Plus, as HAML has significant whitespace, i don't see it as a good idea to introduce it as the markup for CMS content editing (assuming we are dealing with an average webmaster or a regular user with a WYSIWYG editor here).
I've seen haml and liquid working at least once on this jekyll fork:
http://github.com/henrik/jekyll
So what you are proposing is certainly possible. I don't know whether it will be "easy", though.

Resources