Tuesday, March 29, 2011

Nanoc and No Compiling or Routing

Here's a short post on using nanoc with files that you just want copied from the content directory to the output directory unchanged. For these types of files, it's best if you have them in their own subdirectory (say images or css). Let's say we have some images (.jpg, .png, etc.). First just put them in an images directory under content. Then we need to add a couple of rules to our Rules files ...

compile '/images/*/' do
# Leave everything in the images directory as is.

and then a bit later on in the routing section ...

route '/images/*/' do
# Make sure that /images/some_image/ is routed to
# /images/some_image.jpg or /images/some_image.png or so
item.identifier.chop + '.' + item[:extension]

I didn't do an actual project and put it up on GitHub for this one, but if this isn't clear, then let me know and I can do that too.

Friday, March 25, 2011

Nanoc and Multiple Layout Templates

A while back we took a quick look at nanoc for generating static web sites. I've been using it a bit both experimenting and for a simple web site for an author friend of mine. I'm going to do a few short articles on using it, documenting what I've learned in much the same way I've tried to do with Ramaze.

Let's start with some simple code that uses multiple layout templates. You have this often with web sites where there's a home page that uses a different layout than the rest of the pages of the site. Let's start with creating a new site. We do that the same way we did last time with ...

nanoc create_site multiple_templates

and let's add a couple of pages to go along with them ...

nanoc create_item page1
nanoc create_item page2

We didn't really talk about the Rules in the last post and I'm only going to touch on them now. You should take a few minutes and read a bit about them here. We'll discuss them a bit more as we go through future posts.

Now, we need to modify the Rules file to tell it to use an alternate layout for the content/page[12].html files. I'm not going to show the entire file, just the compile rule for these ...

compile '/page*/' do
filter :erb
layout 'page'

What this rule says is that when we "compile" files in our content/ directory, we should first run them through the erb (embedded ruby) and then use the page template in the layouts directory.

Here's the default which will get use by everything else (essentially our main page at content/index.html).

compile '*' do
filter :erb
layout 'default'

This along with the code for all of this up on github should be enough to get you started. As always though, let me know if you have questions or comments.

Tuesday, March 1, 2011


This one is going to be short since I'm not a designer. I've been reading "Web Design for Developers" by Brian P. Hogan and he recommends using Illustrator for parts of his book. Since the cost was a bit umm... prohibitive for learning purposes, I started looking around for a suitable alternative. What I found was Inkscape. This is a nice little program for generating SVG (Scalable Vector Graphics) files. You can use it for generating files for say logos or banners on websites. While I won't say it's simple to use (and this probably says more about me than the program), with the tutorials available, you shouldn't have too much problem getting it to work. Additionally, there's a book on it that's reviewed on Slashdot. I haven't read the book yet but do have it on order and if it seems worthwhile, I'll post here about it.

To install ...

sudo apt-get install inkscape

and you should have an inkscape selection Applications/Graphics or at least on Ubuntu.

Once again, I'm not sure how much I'll be able to help, but if you have questions, be sure and let me know.