<?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>Made of Everything You&#039;re Not &#187; phphaml</title>
	<atom:link href="http://blog.ericlamb.net/tag/phphaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Wed, 11 Aug 2010 03:58:55 +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>Get Rid of HTML Templates With HAML</title>
		<link>http://blog.ericlamb.net/2010/01/get-rid-of-html-templates-with-haml/</link>
		<comments>http://blog.ericlamb.net/2010/01/get-rid-of-html-templates-with-haml/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 08:14:11 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phphaml]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=2797</guid>
		<description><![CDATA[I was working with a new client the last couple weeks where I met a python developer who introduced me to something I hadn&#8217;t head of before: HAML. HAML stands for XHTML Abstraction Markup Language and is a markup &#8220;language&#8221; modeled after, what appears to me to be, YAML. (The syntax and structure is very [...]]]></description>
			<content:encoded><![CDATA[<p>I was working with a new client the last couple weeks where I met a python developer who introduced me to something I hadn&#8217;t head of before: <a title="HAML" href="http://haml-lang.com/" onclick="return TrackClick('http%3A%2F%2Fhaml-lang.com%2F','HAML')" target="_blank">HAML</a>. HAML stands for X<strong>H</strong>TML <strong>A</strong>bstraction <strong>M</strong>arkup <strong>L</strong>anguage and is a markup &#8220;language&#8221; modeled after, what appears to me to be, YAML. (The syntax and structure is very similar to YAML but I couldn&#8217;t find any reference to this being intentional so I could be wrong.)</p>
<div id="attachment_2820" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2010/01/fireworks.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2010%2F01%2Ffireworks.jpg','Get+Rid+of+Templates+With+HAML')"><img class="size-medium wp-image-2820" title="Get Rid of Templates With HAML" src="http://blog.ericlamb.net/wp-content/uploads/2010/01/fireworks-300x240.jpg" alt="Get Rid of Templates With HAML" width="300" height="240" /></a><p class="wp-caption-text">Get Rid of Templates With HAML</p></div>
<p>Anywho, it looks like HAML was originally created for Ruby on Rails but has been adopted by a few other programming languages and environments like <a title="phpHaml" href="http://phphaml.sourceforge.net/" onclick="return TrackClick('http%3A%2F%2Fphphaml.sourceforge.net%2F','phpHaml')" onclick="return TrackClick('http%3A%2F%2Fphphaml.sourceforge.net%2F','phpHaml')" target="_blank">PHP</a>. According to the official site:</p>
<blockquote><p>Haml is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ASP, and ERB, the templating language used in most Ruby on Rails applications. However, Haml avoids the need for explicitly coding HTML into the template, because it itself is a description of the HTML, with some code to generate dynamic content.</p></blockquote>
<p>So in a nutshell HAML allows for the replacement of the normal, everyday, HTML markup with something a little more &#8220;elegant&#8221;. The <a title="HAML Wikipedia" href="http://en.wikipedia.org/wiki/Haml" onclick="return TrackClick('http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHaml','HAML+Wikipedia')" target="_blank">HAML Wikipedia</a> page has a really good example of the differences between HTML and HAML (which I&#8217;ve stolen and placed below):</p>
<h3>HAML</h3>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">!!!
%html{ :xmlns =&gt; &quot;http://www.w3.org/1999/xhtml&quot;, :lang =&gt; &quot;en&quot;, &quot;xml:lang&quot; =&gt; &quot;en&quot;}
  %head
    %title BoBlog
    %meta{&quot;http-equiv&quot; =&gt; &quot;Content-Type&quot;, :content =&gt; &quot;text/html; charset=utf-8&quot;}
    = stylesheet_link_tag 'main'
  %body
    #header
      %h1 BoBlog
      %h2 Bob's Blog
    #content
      - @entries.each do |entry|
        .entry
          %h3.title= entry.title
          %p.date= entry.posted.strftime(&quot;%A, %B %d, %Y&quot;)
          %p.body= entry.body
    #footer
      %p
        All content copyright © Bob</pre></div></div>

<h3>HTML</h3>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'&gt;
  &lt;head&gt;
    &lt;title&gt;BoBlog&lt;/title&gt;
    &lt;meta content='text/html; charset=utf-8' http-equiv='Content-Type' /&gt;
    &lt;link href=&quot;/stylesheets/main.css&quot; media=&quot;screen&quot; rel=&quot;Stylesheet&quot; type=&quot;text/css&quot; /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id='header'&gt;
      &lt;h1&gt;BoBlog&lt;/h1&gt;
      &lt;h2&gt;Bob's Blog&lt;/h2&gt;
    &lt;/div&gt;
    &lt;div id='content'&gt;
      &lt;div class='entry'&gt;
        &lt;h3 class='title'&gt;Halloween&lt;/h3&gt;
        &lt;p class='date'&gt;Tuesday, October 31, 2006&lt;/p&gt;
        &lt;p class='body'&gt;
          Happy Halloween, glorious readers! I'm going to a party this evening... I'm very excited.
        &lt;/p&gt;
      &lt;/div&gt;
      &lt;div class='entry'&gt;
        &lt;h3 class='title'&gt;New Rails Templating Engine&lt;/h3&gt;
        &lt;p class='date'&gt;Friday, August 11, 2006&lt;/p&gt;
        &lt;p class='body'&gt;
          There's a very cool new Templating Engine out for Ruby on Rails. It's called Haml.
        &lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id='footer'&gt;
      &lt;p&gt;
        All content copyright © Bob
      &lt;/p&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>After comparing the two examples above it should be pretty obvious how HAML is structured compared to good old HTML. There&#8217;s nothing too crazy going on in the syntax but that doesn&#8217;t matter nearly as much as there&#8217;s another <em>syntax to learn</em>. Still, if you can get past that HAML is pretty intriguing and worth it to look at. </p>
<p>Now, if you&#8217;re a PHP developer you may be saying, &#8220;That&#8217;s great and all but what the fuck do I care about a Ruby on Rails tool?&#8221;. Well, that&#8217;s one of the cool parts; there&#8217;s a PHP implementation of HAML a PHP class called <a href="http://phphaml.sourceforge.net/" onclick="return TrackClick('http%3A%2F%2Fphphaml.sourceforge.net%2F','phpHaml')" onclick="return TrackClick('http%3A%2F%2Fphphaml.sourceforge.net%2F','phpHaml')" target="_blank" title="phpHaml">phpHaml</a>. phpHaml is a PHP class to compile HAML code into static HTML templates, which is useful if you want to jump right in and build a template system. </p>
<p>At it&#8217;s most basic a phpHaml script looks like the below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #22f;">require_once</span> <span style="color: #0000ff;">'./includes/haml/HamlParser.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$parser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HamlParser<span style="color: #000;">&#40;</span><span style="color: #0000ff;">'./tpl'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'./tmp/haml'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #22f;">echo</span> <span style="color: #000088;">$parser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFile</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'example2.haml'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Simple. Simple. Simple. Obviously, there are other, more advanced options for working with phpHaml but 3 lines is really all it takes for the learning portion. </p>
<p>My interest in HAML is a little greater than my time allows so I haven&#8217;t been able to play too deeply with phpHaml. From my limited time with it though I do feel that the the compiler works as expected on the limited HTML I threw at it and it&#8217;s probably worth a deeper look. Oh, yeah, as an added bonus phpHaml also includes a SASS parser (but that&#8217;s a whole other post) to play with. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/01/get-rid-of-html-templates-with-haml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
