Created
February 1, 2016 15:55
-
-
Save gwww/9f2856498114e50785d5 to your computer and use it in GitHub Desktop.
Stylus Jekyll plugin
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
# Optional stylus section | |
# 'command' defaults to 'stylus' if not present | |
# 'options' default to blank if not present | |
# 'options' are a YAML String | |
stylus: | |
command: ./node_modules/stylus/bin/stylus | |
options: | |
--include ./css | |
--include ./node_modules/nib/lib |
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
module Jekyll | |
class StylusConverter < Converter | |
safe true | |
priority :high | |
def matches(ext) | |
ext =~ /^\.styl$/i | |
end | |
def output_ext(ext) | |
".css" | |
end | |
def convert content | |
require 'open3' | |
cmd = 'stylus' | |
if @config['stylus'] | |
cmd = @config['stylus']['command'] if @config['stylus']['command'] | |
cmd = "#{cmd} #{@config['stylus']['options']}" | |
end | |
value = Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| | |
begin | |
stdin.puts content | |
stdin.close | |
err = stderr.read | |
STDERR.puts err if err.length > 0 | |
raise wait_thr.value.exitstatus.to_s if wait_thr.value.exitstatus != 0 | |
stdout.read | |
rescue => e | |
puts "stylus had errors, error number #{e.message}" | |
end | |
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
--- | |
--- | |
// .styl file must start with YAML front matter | |
// @import files must NOT start with YAML front matter | |
p | |
margin: 2px |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment