Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created June 6, 2009 02:44
Show Gist options
  • Select an option

  • Save jaredatron/124649 to your computer and use it in GitHub Desktop.

Select an option

Save jaredatron/124649 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# gets you ncss files 90% the way to sass
ARGV.each do |path|
next unless File.exists?(path)
sass_path = path.sub(/#{File.extname(path)}$/,'.sass')
File.open(sass_path, 'w').write File.open(path).read.
gsub(/([\w-]+):\s+(.*?);/, ':\1 \2'). # flopping the colon
gsub(/[ ]*(\{|\})[ ]*/, ''). # removing any { }
gsub(/(^[ ]+)\./, '\1&.'). # replacing nested .something selectors with &.something
gsub(/(^[ ]+)\*\./, '\1.') # replacing nested *.something selectors with .something
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment