Skip to content

Instantly share code, notes, and snippets.

@RedHatter
Forked from sentientwaffle/stylus_converter.rb
Last active May 22, 2016 03:19
Show Gist options
  • Save RedHatter/54d4b2fa0a1c14c253846f2d3867683a to your computer and use it in GitHub Desktop.
Save RedHatter/54d4b2fa0a1c14c253846f2d3867683a to your computer and use it in GitHub Desktop.
Stylus plugin for Jekyll
require 'shellwords'
module Jekyll
class StylusConverter < Converter
safe true
def matches(ext)
ext =~ /\.styl/i
end
def output_ext(ext)
'.css'
end
def convert(content)
begin
command = Shellwords.escape content
`echo #{command} | stylus`
rescue => e
puts "Stylus Exception: #{e.message}"
end
end
end
class StylusBlock < Liquid::Block
def initialize(tag_name, text, tokens)
super
end
def render(context)
content = super
begin
command = Shellwords.escape content
`echo #{command} | stylus -p`
rescue => e
puts "Stylus Exception: #{e.message}"
end
end
end
end
Liquid::Template.register_tag('stylus', Jekyll::StylusBlock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment