Re: [mustache] Fwd: Solution for yield :parameter Rails use case
- From:
- Mitch Lloyd
- Date:
- 2011-04-26 @ 01:10
I see what you mean about the use of inheritance to address this problem. I
found one of your posts about this after emailing the list, but I wasn't
sure if this was a Sinatra-only feature:
http://ozmm.org/posts/mustache_0_9_0.html
<http://ozmm.org/posts/mustache_0_9_0.html>It seems that the gem that I was
using for Rails integration has an outstanding TODO for subclassing views
and there is another gem that should make this possible. Maybe I'll give
this one a try:
https://github.com/adamsalter/mustache-rails
<https://github.com/adamsalter/mustache-rails>It has been awhile since
anyone has posted on the "Rails Integration" Github issue (
https://github.com/defunkt/mustache/issues/3). Is there a blessed technique
/ gem for integrating Mustache with Rails that you can recommend at this
point?
On Sun, Apr 24, 2011 at 4:04 PM, Chris Wanstrath <chris@ozmm.org> wrote:
> I've never used that Rails gem, but Mustache was designed around
> inheritance. So for page_title, your view would inherit from Layout and
> override the page_title method. The view would then be used to render the
> layout:
>
> https://gist.github.com/30e9a5d879d571f0469d
>
> This is how the Sinatra extension works.
>
> On Apr 23, 2011, at 10:40 AM, Mitch Lloyd <mitch.lloyd@gmail.com> wrote:
>
>
>
> ---------- Forwarded message ----------
> From: Mitch Lloyd < <mitch.lloyd@gmail.com>mitch.lloyd@gmail.com>
> Date: Sat, Apr 23, 2011 at 1:36 PM
> Subject: Solution for yield :parameter Rails use case
> To: <mustache@librelist.com>mustache@librelist.com
>
>
> I posted a question on
stackoverflow<http://stackoverflow.com/questions/4263893/proper-procedure-for-tag-helpers-in-moustache>
asking
> how to handle a situation in Mustache where one would normally use yield
> :parameter and content_for :parameter in Rails. Could anyone point me in
> the right direction on this one?
>
> I've read the threads on this lists about layouts and I've been looking at this
> gist <https://gist.github.com/415329> to try to figure something out.
>
>
> Below I cut and paste the content from the Stackoverflow question.
> Hopefully this won't look too bad in plain text:
>
> I'm using Mustache in Rails 3 with this
gem<https://github.com/goodmike/mustache_rails3> and
> I'm hitting a roadblock when trying to use Mustache in an instance where I
> would normally use yield :parameter.
>
> <html>*
>
> *<head>
>
>
> <title><%= yield :page_title %></title>
>
>
> </head>
>
> </html>
>
> Show post view:
>
> <% content_for :page_title do %>
>
>
> <%= SettingsList.site_title + " " + @post.title %>
>
> <% end %>
>
> Is there a way to reproduce this behavior with Mustache? It appears that
> there may be a way to work this out when the template is compiled:
>
> mustache = MustacheClass.new
>
>
> mustache[:yield_page_title] = content_for(:page_title)
>
> But it seems that that would be awkward to work out with my current setup
> using the mustache_rails3 gem.
>
> I'm also open to any answers that point out a good way to avoid this
yield approach
> altogether. It would be possible to throw enough logic into a
> {{page_title}} tag to handle all my different cases of setting the title,
> but this seems far from ideal.
>
>
Re: [mustache] Fwd: Solution for yield :parameter Rails use case
- From:
- Chris Wanstrath
- Date:
- 2011-04-26 @ 19:17
On Mon, Apr 25, 2011 at 6:10 PM, Mitch Lloyd <mitch.lloyd@gmail.com> wrote:
> It has been awhile since anyone has posted on the "Rails Integration" Github
> issue (https://github.com/defunkt/mustache/issues/3). Is there a blessed
> technique / gem for integrating Mustache with Rails that you can recommend
> at this point?
Not me. I've never used Mustache with Rails :)