Skip to content

Instantly share code, notes, and snippets.

@gwww
Created February 1, 2016 15:55
Show Gist options
  • Save gwww/9f2856498114e50785d5 to your computer and use it in GitHub Desktop.
Save gwww/9f2856498114e50785d5 to your computer and use it in GitHub Desktop.
Stylus Jekyll plugin
# 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
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
---
---
// .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