Skip to content

Instantly share code, notes, and snippets.

@ckraybill
Forked from thermistor/assets.rake
Last active December 13, 2015 23:19
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 ckraybill/4991338 to your computer and use it in GitHub Desktop.
Save ckraybill/4991338 to your computer and use it in GitHub Desktop.
namespace :assets do
desc "Check that all assets have valid encoding"
task :check => :environment do
paths = ["public/javascripts", "public/stylesheets"]
extensions = ["js", "coffee", "css", "scss"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")
Dir.glob(dir_files + "/**.{#{extensions.join(',')}}").each do |file|
# make sure we're not trying to process a directory
unless File.directory?(file)
# read the file and check its encoding
data = File.read(file)
unless data.valid_encoding?
puts "Invalid encoding: #{ file }"
end
end
end # end Dir.glob
end #end File.exists
end # end paths.each
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment