Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper procedure for tag helpers in moustache

I've been reading over the moustache documentation, and it looks cool: https://github.com/defunkt/mustache

There is a clear separation between ruby code and html markup. Having not started a moustache project, my confusion is this: how should ruby that generates markup be handled? Obvious examples would be form helpers and link_to, not to mention any custom methods. Would it be proper (or possible) to do {{link_to ...}}? -- having code in the markup. Or to define a custom method in the view ruby: {{whatever_link}}? -- this seems non-DRY and equally undesirable. Where's the win?

Thanks!
--Peter

like image 991
Peter Ehrlich Avatar asked Nov 24 '10 06:11

Peter Ehrlich


1 Answers

Mustache is very simple by design. Templates are supposed to be renderable in many languages (see https://github.com/defunkt/mustache/wiki/Other-Mustache-implementations). Many web applications chose mustache because templates can be shared by client code (javascript) and server code (whatever language).

The win is not to go against that fact, even if it may look inconvenient at first sight.

Investigate the {{whatever_link}} solution, and keep your code as DRY as you can.

like image 92
Gwendal Roué Avatar answered Sep 27 '22 01:09

Gwendal Roué