Skip to content

Instantly share code, notes, and snippets.

@june29
Created January 8, 2014 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/8315074 to your computer and use it in GitHub Desktop.
Save june29/8315074 to your computer and use it in GitHub Desktop.
require "pathname"
Dir["app/assets/stylesheets/**/*"].each do |path|
pathname = Pathname.new(path)
basename = pathname.basename
extname = pathname.extname
next if pathname.directory?
next unless extname.to_s == ".scss"
next if basename.to_s.start_with?("_")
count = 0
converted = []
File.open(path).each_with_index do |line, index|
if line =~ /^(\s*)opacity:\s*([0-9.]+);\s*$/
indent = $1
value = $2
converted << "#{indent}@include opacity(#{value});\n"
count += 1
else
converted << line
end
end
if count > 0
puts "%s: %d replaced" % [path, count]
file = File.open(path, "w")
file.write(converted.join)
file.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment