Integrating Compass and Jekyll Without Plugins

I find myself getting closer to the point where I’m done with the scaffolding and can finally start with the design. The more fun stuff I look at the more I realize that integrating Compass is probably a good idea.

I don’t like plugins unless absolutely necessarry so while I’m sure the jekyll-compass plugin is great, I decided to figure out how to add Compass to my Jekyll/Octopress 3 site without any plugins.

Here’s what I did.

desc "build the site"
task :build do
  system "bundle exec compass compile"
  system "bundle exec jekyll build"
  system "bundle exec rake minify_html"
  system "bundle exec rake optimizeimages"
end
##############
#   Develop  #
##############

# Useful for development
# It watches for chagnes and updates when it finds them

desc "Watch the site and regenerate when it changes"
task :watch do
  puts "Starting to watch source with Jekyll and Compass."
  system "compass compile" unless File.exist?("css/main.css")
  system "jekyll build"
  jekyllPid = Process.spawn("jekyll serve --watch")
  compassPid = Process.spawn("compass watch")

  trap("INT") {
    [jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
    exit 0
  }

  [jekyllPid, compassPid].each { |pid| Process.wait(pid) }
end

Now you can use Compass mixins and import partials by adding @import compass/blahblahblah to your _sass/main.scss file.
Running bundle exec rake build will then run compass compile to create your css/main.scss file, followed by jekyll build which will move that css/main.scss to _site/css/main.css

In short: