Syntax-coloring your code

You can use CodeRay to let nanoc color your code. Create a file, syntax_coloring_plugin.rb or so, and put the following code in it:

require 'coderay'

def code(*args, &block)
  buffer = eval('_buf', block.binding)
  
  lang = args.first || :ruby
  pos = buffer.length
  block.call(*args)
  data = buffer[pos..-1]
  buffer[pos..-1] = codify(data, lang)
end

def codify(str, lang)
  %{<pre><code class="#{lang}">#{CodeRay.scan(str, lang).html}</code></pre>}
end

To use this, put the code you want to color in a Ruby 'code' block, like this:

<% code(:ruby) do %>
  #!/usr/bin/env ruby
  
  def some_function
    x = blah.foo
    x.bar "xyzzy
  end
<% end %>

This will probably be converted into a plugin and moved into nanoc's subversion repository at some point. Many thanks to Mark Chadwick for the tip!