Created
January 8, 2014 10:58
-
-
Save june29/8315074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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