Created
April 8, 2013 03:16
-
-
Save zerowidth/5334001 to your computer and use it in GitHub Desktop.
Jekyll plugins for rendering compass stylesheets and auto-converting coffeescript files without requiring YAML front-matter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "coffee-script" | |
module Jekyll | |
# Automatically force coffeescript files to be compiled, even if they don't | |
# have the YAML front-matter. | |
class CoffeeConvertor < Generator | |
def generate(site) | |
converted = [] | |
site.static_files.each do |sf| | |
if sf.path =~ /\.coffee\Z/ | |
converted << sf | |
path = sf.path.sub site.source, "" | |
dir = File.dirname path | |
filename = File.basename path | |
# force jekyll to consider this a renderable page | |
site.pages << Page.new(site, site.source, dir, filename) | |
end | |
end | |
# don't preserve the coffeescript version | |
converted.each { |c| site.static_files.delete c } | |
end | |
end | |
# from https://gist.github.com/phaer/959938 | |
class CoffeeScriptConverter < Converter | |
safe true | |
priority :normal | |
def matches(ext) | |
ext =~ /coffee/i | |
end | |
def output_ext(ext) | |
".js" | |
end | |
def convert(content) | |
begin | |
CoffeeScript.compile content | |
rescue StandardError => e | |
puts "CoffeeScript error:" + e.message | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "compass" | |
require "compass/exec" | |
module Jekyll | |
class NoopFile < StaticFile | |
def write(dest) | |
# nothing, the file's already there | |
end | |
end | |
# Adapted from https://gist.github.com/parkr/2874934 | |
# Expects the destination directory as configured in _stylesheets/config.rb to | |
# be "../_site/stylesheets". | |
class CompassGenerator < Generator | |
def generate(site) | |
dir = "_stylesheets" | |
compile = Compass::Commands["compile"].new(dir, {}) | |
puts | |
compile.execute | |
Dir.glob(File.join(dir, "*.scss")).each do |scss| | |
filename = File.basename(scss).sub(".scss", ".css") | |
# make sure the newly-generated file doesn't get cleaned: | |
site.static_files << NoopFile.new(site, site.source, "stylesheets", filename) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment