Rebase of expansions to per-environment functionality.

This rebases, and adds fixes for [PR 1061](https://github.com/imathis/octopress/pull/1061).