<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: haml code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 04:29:12 GMT</pubDate>
    <description>DZone Snippets: haml code</description>
    <item>
      <title>Converting all ERb views to Haml</title>
      <link>http://snippets.dzone.com/posts/show/5449</link>
      <description>A little script to convert all your .erb views to .haml using html2haml, which is included with Haml installation.&lt;br /&gt;Just drop this in your rails root folder and run it.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class ToHaml&lt;br /&gt;  def initialize(path)&lt;br /&gt;    @path = path&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def convert!&lt;br /&gt;    Dir["#{@path}/**/*.erb"].each do |file|&lt;br /&gt;      `html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;path = File.join(File.dirname(__FILE__), 'app', 'views')&lt;br /&gt;ToHaml.new(path).convert!&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 01 May 2008 23:27:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5449</guid>
      <author>divoxx (Rodrigo Kochenburger)</author>
    </item>
    <item>
      <title>abbr formatting</title>
      <link>http://snippets.dzone.com/posts/show/5227</link>
      <description>haml (easily transformed to css) snippet to format abbrs in a proper manner - you can still type them in ALL CAPS, but they will be displayed in Titlecase and small-caps. If you're using this, you're probably also using a custom face via @font-face, so you might want to explicitly declare the small-caps and lowercase variants of the typeface - the browser often fucks up auto-small-caps.&lt;br /&gt;&lt;br /&gt;also, not tested in internet explorer. nothing I write is.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;abbr&lt;br /&gt;  :display inline-block&lt;br /&gt;  :text-transform lowercase&lt;br /&gt;  :font-variant small-caps&lt;br /&gt;  &lt;br /&gt;  &amp;:first-letter&lt;br /&gt;    :text-transform uppercase&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Mar 2008 21:13:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5227</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>Convert XML to Haml</title>
      <link>http://snippets.dzone.com/posts/show/4754</link>
      <description>This Ruby code converts a simple XML document into HAML.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;fruit = "&lt;fruit&gt;&lt;apple country='france' month='august'&gt;tasty&lt;gdelicious/&gt;&lt;/apple&gt;&lt;pear&gt;&lt;/pear&gt;&lt;/fruit&gt;"&lt;br /&gt;&lt;br /&gt;doc_fruit = Document.new(fruit)&lt;br /&gt;&lt;br /&gt;def xml2haml(nodex, indent ='')&lt;br /&gt;&lt;br /&gt;  nodex.elements.each do |node|&lt;br /&gt;&lt;br /&gt;    attributex = ' '&lt;br /&gt;    buffer = indent + '%' + node.name&lt;br /&gt;&lt;br /&gt;    if node.attributes.size &gt; 0 then&lt;br /&gt;      alist = Array.new(node.attributes.size)&lt;br /&gt;      i = 0&lt;br /&gt;      node.attributes.each { |x, y|&lt;br /&gt;        alist[i] = " :#{x} =&gt; '#{y}'"  &lt;br /&gt;        i += 1&lt;br /&gt;      }&lt;br /&gt;      attributex = '{' + alist.join(",")  + '} ' &lt;br /&gt;    end&lt;br /&gt; &lt;br /&gt;    buffer +=  attributex + node.text if not node.text.nil?  &lt;br /&gt;    puts buffer&lt;br /&gt;    xml2haml(node, indent + '  ')&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;xml2haml(doc_fruit)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;%fruit&lt;br /&gt;  %apple{ :month =&gt; 'august', :country =&gt; 'france'} tasty&lt;br /&gt;    %gdelicious&lt;br /&gt;  %pear&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 14 Nov 2007 21:34:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4754</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Running Haml stand-alone</title>
      <link>http://snippets.dzone.com/posts/show/4753</link>
      <description>This Ruby code converts HAML to XHTML. code based on the example given at 'A HAML Server for Web Designers' http://urltea.com/23j8 [wiseheartdesign.com]. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'haml'&lt;br /&gt;&lt;br /&gt;def parse_haml(string)&lt;br /&gt;  engine = Haml::Engine.new(string)&lt;br /&gt;  engine.render&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;parse_haml("#hello")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: The above code worked on Ubuntu 7.10, and on Gentoo I declared require 'haml/engine' as an alternative to requiring 'rubygems' and 'haml'.</description>
      <pubDate>Wed, 14 Nov 2007 12:12:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4753</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
