> Hey all, > > I started using Nesta this morning. The concept seemed interesting, so I thought I'd tinker a bit. I've got it setup, and started writing a post (nesta.haml). Inside my post, I wanted to include some Github Gist snippets, but got tired of typing "%script{:type=>'text/javascript', :src=>'https://gist.github.com/12345.js'></script>". So I thought I'd write a little helper: > > /local/app.rb: > module Nesta > class App > helpers do > def gist(gn) > "<script type='text/javascript' src='https://gist.github.com/#{gn}.js'></script>" > end > end > end > end > > I tried to then use "= gist(12345)" in my /content/nesta.haml page, but the method was not found. After some digging, I realized the issue. In the Page model, the to_html method uses Haml::Engine.new(markup).to_html to render the haml to html. What happens is that it also overrides the scope of the markup to Object.new, and therefore, my helper method no longer exists. http://haml-lang.com/docs/yardoc/Haml/Engine.html#render-instance_method > > At this moment, I haven't thought of a way of getting around this. It seems like at that position, I can't override the scope to what I need (Nesta::App). Does anyone have any idea of how to get it to do what I want? Having helpers in my page files would be ideal, but not the end of the world. I'm still working on my Ruby chops, so I'd love to hear what others would suggest. > > Take care. > -- *Carl Furrow* carlfurrow.com | my google profile <http://google.com/profiles/carl.furrow>| @carlfurrow <http://twitter.com/carl_furrow>
On 23 Nov 2010, at 22:31, Carl Furrow wrote:
> I tried to then use "= gist(12345)" in my /content/nesta.haml page, but
the method was not found. After some digging, I realized the issue. In the
Page model, the to_html method uses Haml::Engine.new(markup).to_html to
render the haml to html. What happens is that it also overrides the scope
of the markup to Object.new, and therefore, my helper method no longer
exists.
http://haml-lang.com/docs/yardoc/Haml/Engine.html#render-instance_method
Yep, that's exactly what it's doing. Glenn Gillen fixed this in his fork a
while ago, and to be honest I thought I'd merged it. I've just found it in
the issue tracker though (still open), so have fixed it and closed the
issue.
There's a link to the patch in the issue (though a `git pull` should just
sort you out).
https://github.com/gma/nesta/issues/issue/10
Cheers,
Graham
P.S. Glenn - if you're reading, your master branch seems to have lost the
fix, so you might want to merge this...
That cleared it right up. Thank you. On Tue, Nov 23, 2010 at 6:52 PM, Graham Ashton <graham@effectif.com> wrote: > On 23 Nov 2010, at 22:31, Carl Furrow wrote: > > > I tried to then use "= gist(12345)" in my /content/nesta.haml page, but > the method was not found. After some digging, I realized the issue. In the > Page model, the to_html method uses Haml::Engine.new(markup).to_html to > render the haml to html. What happens is that it also overrides the scope of > the markup to Object.new, and therefore, my helper method no longer exists. > http://haml-lang.com/docs/yardoc/Haml/Engine.html#render-instance_method > > Yep, that's exactly what it's doing. Glenn Gillen fixed this in his fork a > while ago, and to be honest I thought I'd merged it. I've just found it in > the issue tracker though (still open), so have fixed it and closed the > issue. > > There's a link to the patch in the issue (though a `git pull` should just > sort you out). > > https://github.com/gma/nesta/issues/issue/10 > > Cheers, > Graham > > P.S. Glenn - if you're reading, your master branch seems to have lost the > fix, so you might want to merge this... > -- *Carl Furrow* carlfurrow.com | my google profile <http://google.com/profiles/carl.furrow>| @carlfurrow <http://twitter.com/carl_furrow>