Last active
April 10, 2018 01:18
-
-
Save aaronmoodie/f5dc34d425118ca748997609f35f1959 to your computer and use it in GitHub Desktop.
find rem value and replace with modified version
This file contains hidden or 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
# Find and modify all rem values | |
# To use, call file and pass in CSS dir | |
# eg. ruby rem_replace.rb ~/my_css_files | |
dir = ARGV[0] | |
Dir.glob(dir + '/*.css') do |css_file| | |
# do work on files ending in .css in the desired directory | |
puts "working on: #{css_file}..." | |
# read file | |
markup = File.read(css_file) | |
# Find rem values in file | |
# Convert to float and multiply by 0.625 | |
# Return as float, or as int if divisibe by 1 | |
new_contents = markup.gsub(/(?!\s)(\d+\.?\d*)(?=rem)/) do |val| | |
new_val = val.to_f * 0.625 | |
new_val % 1 == 0 ? new_val.to_i : new_val | |
end | |
# Write changes to the file | |
File.open(css_file, "w") { |file| file.puts new_contents } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment