Created
December 13, 2009 01:16
-
-
Save brucespang/255189 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
#!/usr/bin/env ruby | |
if ARGV.length < 1 | |
puts "Usage: ruby fixed2fluid.rb FIXED_CSS_FILE [NEW_FLUID_CSS_FILE]" | |
else | |
if File.file?(ARGV[0]) | |
if ARGV.length == 1 | |
fixed = File.open(ARGV[0], "r") | |
else | |
fixed = File.open(ARGV[0], "r") | |
fluid = File.open(ARGV[1], "w+") | |
end | |
contents = '' | |
fixed.each_line do |line| | |
contents += line | |
end | |
new_contents = contents.gsub(/(\d+)px/i) do |match| | |
(match.to_f/16).to_s+'em' | |
end | |
if ARGV.length != 1 | |
fluid.write(new_contents) | |
else | |
fluid = File.open(ARGV[0], "w+") | |
fluid.write(new_contents) | |
end | |
fixed.close | |
fluid.close | |
else | |
puts "Fixed CSS File doesn't exist." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment