<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Ruby on Rails Notes &#187; javascript</title> <atom:link href="http://railsnotes.com/tag/javascript/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Javascript in Haml</title><link>http://railsnotes.com/474-javascript-haml/</link> <comments>http://railsnotes.com/474-javascript-haml/#comments</comments> <pubDate>Thu, 07 May 2009 00:43:20 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[haml]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=474</guid> <description><![CDATA[One thing that is not obvious with HAML is how to add javascript. In the past, haml didn't really like javascript that much but the latest version of haml on github makes it very simple. It's done using the :javascript filter and this post shows you how with an example.]]></description> <content:encoded><![CDATA[<p></p><p>One thing that is not obvious with HAML is how to add javascript. In the past, <a
href="http://b.lesseverything.com/2008/2/19/haml-doesn-t-like-javascript" target="_blank">haml didn&#8217;t really like javascript that much</a> but the latest version of haml on github makes it very simple. It&#8217;s done using the :javascript filter. Here&#8217;s an example:</p><pre>:javascript
  jQuery(function(){
    tog("#forgot_password_clicker", "#login_form");
    tog("#forgot_password_clicker", "#forgot_form", forgot_text);
  });</pre><p>You can also mix in ruby variables by using the standard way of interpolating ruby with strings through: #{ }. Here&#8217;s an example of how it all works in a full page with a ruby variable mixed in:</p><pre>!!! XML
!!!
%html{:xmlns =&gt; "http://www.w3.org/1999/xhtml", "xml:lang" =&gt; "en", :lang =&gt; "en"}
  %head
    %meta{'http-equiv' =&gt; "content-type", :content =&gt; "text/html;charset=UTF-8"}

  %body
    - @some_ruby_variable = "something goes here."
    :javascript
      #{@some_ruby_variable}
      jQuery(function(){
        tog("#forgot_password_clicker", "#login_form");
        tog("#forgot_password_clicker", "#forgot_form", forgot_text);
      });</pre><p>This makes this HTML:</p><pre>&lt;?xml version='1.0' encoding='utf-8' ?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'&gt;
  &lt;head&gt;
    &lt;meta content='text/html;charset=UTF-8' http-equiv='content-type' /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;script type='text/javascript'&gt;
      //&lt;![CDATA[
        something goes here.
        jQuery(function(){
          tog("#forgot_password_clicker", "#login_form");
          tog("#forgot_password_clicker", "#forgot_form", forgot_text);
        });
      //]]&gt;
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>]]></content:encoded> <wfw:commentRss>http://railsnotes.com/474-javascript-haml/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/16 queries in 0.036 seconds using disk

Served from: railsnotes.com @ 2010-09-10 05:55:37 -->