Well, also, I'll hint here that I've been working on a Javascript replacement language that I'm going to reveal at RubyFringe.
It most likely won't be fully implemented, and most likely won't go anywhere. But, I kept getting mad at JS, so I decided to fix it. http://www.rubyfringe.com -hampton. On Sun, Apr 27, 2008 at 2:13 PM, Jesús <[EMAIL PROTECTED]> wrote: > > On Sun, Apr 27, 2008 at 7:28 PM, Nathan Weizenbaum <[EMAIL PROTECTED]> > wrote: > > > > There's not a great, general way to do this in Haml 1.8. For the first > > example, you could do > > > > > > - content_for :onload_scripts do > > == $(#{highlighted_item.to_json}).effect('highlight'); > > > > Calling out to ERB is probably the best option for the second script. > > > > However, in the master branch you can use filters with variable > > interpolation, like so: > > > > > > - content_for :onload_scripts do > > :plain > > $('#search_items').autocomplete( > > #{url_for(:controller => '/items', :action => 'search').to_json}, > > { selectFirst: false, minChars: 2 }); > > > > Note that I'm calling to_json on the strings before putting them into > > the document; that guarantees that they'll result in valid Javascript. > > > > - Nathan > > Thanks Nathan! i forgot about == operator! (i'm fucking noob, 2hours > ago i didn't know about haml :D) > > For second example we can use both == and | operators and get a > reasonable way of doing that with haml. > - content_for :onload_scripts do > == $('#search_items').autocomplete(' | > #{url_for(:controller => '/items', :action => > 'search').to_json}, { | > selectFirst: false, | > minChars: 2 > }); > > Though your way is also nice, thanks again! > > > Jesús wrote: > > > Hi, i've just met Haml (and i love it!), but i'm having problems > > > translating some erb views. > > > > > > i usually have (erb) code like this: > > > > > > <% content_for :onload_scripts do %> > > > $('#<%= highlighted_item %>').effect('highlight'); > > > <% end %> > > > > > > or > > > > > > <% content_for :onload_scripts do %> > > > $('#search_items').autocomplete( > > > '<%= url_for :controller => '/items', > > > :action => 'search' %>', { > > > selectFirst: false, > > > minChars: 2 > > > }); > > > <% end %> > > > > > > ie, to generate javascript with erb. > > > > > > How can i write code like this in haml that doesn't suck? i think that > > > the only way to do this is with something respectively like: > > > > > > - content_for :onload_scripts do > > > $(' > > > = highlighted_item > > > ').effectt('highlight'); > > > > > > - content_for :onload_scripts do > > > $('#search_items').autocomplete(' > > > = url_for :controller => '/items', :action => 'search' > > > ', {selectFirst: false, minChars: 2}); > > > > > > that's really ugly, don't you think? for now i'm using a > > > = render :partial => 'an_erb_file' > > > and putting all that stuff there, but that method sucks too :( > > > > > > > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Haml" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/haml?hl=en -~----------~----~----~----~------~----~------~--~---
