<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Random Inconsequential Thoughts]]></title>
  <link href="http://www.duckpuppy.com/atom.xml" rel="self"/>
  <link href="http://www.duckpuppy.com/"/>
  <updated>2012-01-23T10:38:48-05:00</updated>
  <id>http://www.duckpuppy.com/</id>
  <author>
    <name><![CDATA[DuckPuppy]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Switching to Octopress]]></title>
    <link href="http://www.duckpuppy.com/blog/2011/11/29/switching-to-octopress/"/>
    <updated>2011-11-29T16:06:00-05:00</updated>
    <id>http://www.duckpuppy.com/blog/2011/11/29/switching-to-octopress</id>
    <content type="html"><![CDATA[<p>I recently discovered <a href="http://octopress.org">Octopress</a>, and after some investigation discovered that I was basically working toward my own very similar version of Octopress.  Rather than travel further down a road already travelled, I am switching over to Octopress.  I plan to port some of my extensions over (and in the process switch Octopress to use ejekyll), but this will let me focus more on getting content into the blog rather than spend too much more time messing with the site generation.  Hopefully I’ll start blogging on a more regular basis.</p>

<p>I’m also switching to Heroku for hosting.  The code for my site is private, allowing me to store more sensitive information in the configuration and automate things like Flickr integration which require a secret key.  Publishing is really simple - I just push to my heroku repo and the site is live.  Very simple.  I like it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using Haml with Jekyll]]></title>
    <link href="http://www.duckpuppy.com/blog/2011/10/31/using-haml-with-jekyll/"/>
    <updated>2011-10-31T13:48:25-04:00</updated>
    <id>http://www.duckpuppy.com/blog/2011/10/31/using-haml-with-jekyll</id>
    <content type="html"><![CDATA[<p>While I have been working on my Jekyll workflow, I&#8217;ve come across one big annoyance: all of the methods of integrating Haml layouts into my workflow have one of two undesirable side effects.</p>
<ol>
	<li>They leave html files lying around my source folder.  Ideally, the html should be generated into some temporary staging area as needed</li>
	<li>They don&#8217;t integrate well with the auto-generation cycle for quick turnaround while modifying the site content.</li>
</ol>
<p>I&#8217;ve been using the <a href="https://github.com/rfelix/jekyll_ext">jekyll_ext</a> gem for a while now.  The aspect-oriented approach lets me go above and beyond the existing plugin architecture without having to fork jekyll itself and maintain my own changes.  One of the pre-existing extensions that I tried to use was the <a href="https://github.com/codegram/haml-jekyll-extension">haml-jekyll-extension</a>.  It would be executed as part of the automatic regeneration step each time I changed a haml layout file and I could preview the changes instantly without manually rebuilding the site.  I didn&#8217;t like that it also tried to handle the s{c|a}ss for you.  I&#8217;m using compass for that.  I also didn&#8217;t like that it generated the html files right alongside the haml source files.  A litle bit of hacking gives you <a href="https://gist.github.com/1308318">this code</a>.  I have modified the extension to only handle .haml layout files, and they generate into the <code>_cache</code> folder.</p>
<p><!--more--><br />
<div><script src='https://gist.github.com/1308318.js?file=haml.rb'></script><br />
<noscript><pre><code># Original idea came from https://github.com/codegram/haml-jekyll-extension</p>
<ol>
	<li>and http://rfelix.com/2010/01/19/jekyll-extensions-minus-equal-pain/ <br />
#</li>
	<li>This extension allows the use of Haml layout templates in Jekyll.  It has</li>
	<li>the benefit of not requiring the use to generate the html files in the</li>
	<li>source folder. Instead, we generate the <span class="caps">HTML</span> into the _cache folder and</li>
	<li>then load the Layout objects from those files.  This does affect any other</li>
	<li>plugin or extension that directly reads the layout files rather than</li>
	<li>referencing the layout objects from the Jekyll site instance.<br />
begin<br />
  require &#8216;haml&#8217;<br />
rescue LoadError<br />
  require &#8216;rubygems&#8217;<br />
  require &#8216;haml&#8217;<br />
end</li>
</ol>
<p>module Jekyll<br />
  class Site<br />
    def compile_haml_layouts<br />
      Dir.glob(File.join(self.source, &quot;<em>layouts&quot;, &quot;*.haml&quot;)).each do |f| <br />
        begin<br />
          origin = File.open(f).read<br />
          result = Haml::Engine.new(origin).render<br />
          raise HamlErrorException.new if result.empty?<br />
          puts &quot;Rendering #{f}&quot;<br />
          output_file_name = File.join(&quot;<em>cache&quot;, &quot;<em>layouts&quot;, File.basename(f, &#8216;.haml&#8217;) + &#8216;.html&#8217;)<br />
          FileUtils.mkpath(File.dirname(output_file_name))<br />
          File.open(output_file_name,&#8216;w&#8217;) {|f| f.write(result)} if !File.exists?(output_file_name) or (File.exists?(output_file</em>name) and result != File.read(output</em>file</em>name))<br />
        rescue HamlErrorException =&gt; e<br />
        end<br />
      end<br />
    end<br />
  end</p>
class HamlErrorException &lt; Exception
end
<span class="caps">AOP</span>.around(Site, :read_layouts) do |site_instance, args, proceed, abort|
site_instance.compile_haml_layouts
old_source = site_instance.source
site_instance.source = &#8216;_cache&#8217;
result = proceed.call
site_instance.source = old_source
result
end
<p>end</code></pre></noscript></div></p>
<p>I didn&#8217;t change the actual generation code much other than to change where it generates the html files, but I want to highlight the extension code for anyone who might not be familiar with how it works.  All you really need to know is that it generates the html into the <code>cache/_layouts</code> folder.</p>
<ul>
	<li>Line 38 tells <code>jekyll_ext</code> that you want to run this code around the specified method, not simply before or after.  This allows you to control more precisely where in the code flow you want the original behavior to execute.  I wanted to wrap the <code>read_layouts</code> function of the <code>Site</code> class to change the location it will load the html layouts from.</li>
	<li>Line 39 calls the haml generation code from earlier in the class. This will generate the html layout files into <code>_cache/_layouts</code></li>
	<li>Line 40 saves off the existing source configuration so we can restore it later.</li>
	<li>Line 41 sets the source location to our <code>_cache</code> folder.</li>
	<li>Line 42 calls the existing <code>read_layouts</code> method.  The <code>proceed</code> object passed to us in the block is a <a href="http://www.ruby-doc.org/core-1.9.2/Proc.html">Proc</a> object representing the original method.  The <code>read_layouts</code> method will look in the configured source folder for a folder named <code>_layouts</code> and read the html layouts from there into <code>Layout</code> objects.  This is why we changed the source folder earlier &#8211; we want to make <code>read_layouts</code> read from the <code>_cache</code> folder rather than the existing source folder.</li>
	<li>Line 43 sets the source folder back to the value we saved earlier.</li>
	<li>Line 44 returns the result of the <code>read_layouts</code> call.</li>
</ul>
<p>The great thing with this approach is that we don&#8217;t clutter our source folders with both source and generated content, something I <strong>really</strong> hate.  When I edit a Haml layout, it gets regenerated and used to generate the rest of the site in <code>--auto</code> mode.</p>
<p>I hope this helps someone out there&#8230; I hope to have a compass plugin that works the same way. I really want to be able to quickly iterate on my styles without having to constantly kill and restart the jekyll server.</p>
<p><strong><span class="caps">UPDATE</span></strong><br />
My compass extension is now ready as well.</p>]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[First post with Jekyll]]></title>
    <link href="http://www.duckpuppy.com/blog/2011/10/02/first-post-with-jekyll/"/>
    <updated>2011-10-02T15:17:02-04:00</updated>
    <id>http://www.duckpuppy.com/blog/2011/10/02/first-post-with-jekyll</id>
    <content type="html"><![CDATA[<p>I seems somewhat obligatory to explain why you’re using Jekyll for your blogging platform of choice when you begin using it, so I suppose I should follow suit.</p>

<p>I’ve been using WordPress for years. I’ve never been a prolific blogger at all. I’m not at all sure that anyone cares what I have to say anyway, but it’s been at least a way to get some of what’s inside my head out of it. In every incarnation of my blog, I’ve always used a blogging platform of some type - I started on Mambo (pre-Joomla), moved to Drupal, and from there to WordPress - all self-hosted. I do have accounts at Tumblr, Blogger, and WordPress.com, but I’ve never been a fan of that lack of control over the site.</p>

<p>I suppose that’s the main point of now using Jekyll - I have <strong>total</strong> control. That also means I have total responsibility for everything about the site. I really need to learn how some of this stuff works. Despite my years of development experience, I’ve never gotten into Javascript. I’m in a position where I need to learn Ruby. With Jekyll, I can get some Ruby practice writing the Rakefile that helps me manage the site and the generators, converters, and plugins I use to generate the site.</p>

<p>Really, the big reason I’ve switched to this is because it’s something new to try.</p>
]]></content>
  </entry>
  
</feed>

