olivernn / poirot

mustaches in your rails
http://olivernn.github.com/poirot
108 stars 21 forks source link

Poirot With Cells #22

Open timscott opened 12 years ago

timscott commented 12 years ago

I'm trying to use Cells [https://github.com/apotonick/cells] to create reusable view components. The view that I want to make reusable already exists, and it uses Poirot templates. The problem is template_include_tag which requires that all templates live inside of app\views whereas Cell keeps its view templates in app\cells.

A secondary problem is that, while cells are like controllers, they don't implement the controller_name method. This could be hacked around using an absolute path if Poirot had some way to either specify a rooted path (kinda yuck) or to search for templates in the current folder. Regarding this last suggestion I'm not sure if there is a way to know from a helper what file it's running from. If not, maybe there could be some way to denote that the file references is rooted at app instead of app/views. Perhaps like ~/path/to/mustache/template

olivernn commented 12 years ago

I'm not overly familiar with the cells project, though it sounds like it should be possible to get poirot working better with it.

You can currently set the template path in your views, so as to be able to put your mustache templates in app/cells for example. Inside your ruby view class you should be able to do the following:

self.template_path = Rails.root.join('app', 'cells', view_class.name.split('::').first.downcase)

This is currently being done in the Poirot::View class anyway, so you should be able to customise it further, see here

There are a few changes I want to make to the template_include_tag anyway so I'll take into account loading templates from places other than app/cells.

Let me know how you get on with customising the template path, and I'll take a closer look at cells to see if there is a simpler way to get the two working together better.