Skip to content

Instantly share code, notes, and snippets.

@aaronmoodie
Last active April 10, 2018 01:18
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 aaronmoodie/f5dc34d425118ca748997609f35f1959 to your computer and use it in GitHub Desktop.
Save aaronmoodie/f5dc34d425118ca748997609f35f1959 to your computer and use it in GitHub Desktop.
find rem value and replace with modified version
# 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