Skip to content

Instantly share code, notes, and snippets.

@EtienneLem
Created April 6, 2012 13:26
Show Gist options
  • Save EtienneLem/2319775 to your computer and use it in GitHub Desktop.
Save EtienneLem/2319775 to your computer and use it in GitHub Desktop.
Compile Stylus to CSS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>saveActiveFile</string>
<key>command</key>
<string>#!/usr/bin/env ruby
# encoding: utf-8
in_inclusion = ENV['TM_FILEPATH'].match(/_(.)+\.styl/)
in_assets_folder = ENV['TM_FILEPATH'].match(/assets\//)
# Automagically compile .styl to .css if:
# · Not in `assets/` folder
# · Filname is not `_*.styl`
if !in_inclusion &amp;&amp; !in_assets_folder
result = `stylus #{ENV['TM_FILEPATH']}`
error = /throw\ err/.match(result)
if error == nil
puts "✓ compiled #{ENV['TM_FILEPATH'].sub(/\.(styl|stylus)$/, '.css')}"
else
puts "✗ #{result}"
end
end</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>@s</string>
<key>name</key>
<string>Compile Stylus to CSS</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.stylus</string>
<key>uuid</key>
<string>5538C418-2C8C-410E-A15F-7EFB29EA8F7D</string>
</dict>
</plist>
@EtienneLem
Copy link
Author

CMD + S when editing styles.styl

  • Do not compile when in /assets folder (see connect-assets)
  • Do not compile when filename begins with underscore (i.e. _utils.styl)
  • Otherwise it compiles styles.css beside styles.styl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment