mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 15:43:58 +00:00
Use charlock_holmes to do encoding detection. In my tests it has properly identified incorrect encodings that used to be present on older commits. This will help ensure this won't happen again, giving people instant feedback and allowing all pull requests to be checked
This commit is contained in:
parent
58ffb4057f
commit
70d6977ccc
1
Gemfile
1
Gemfile
@ -1,3 +1,4 @@
|
|||||||
group :test do
|
group :test do
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
|
gem 'charlock_holmes'
|
||||||
end
|
end
|
||||||
|
4
Rakefile
4
Rakefile
@ -2,6 +2,10 @@ task default: %w[test]
|
|||||||
|
|
||||||
task :test do
|
task :test do
|
||||||
Dir["./tests/*.rb"].each do |test_file|
|
Dir["./tests/*.rb"].each do |test_file|
|
||||||
|
begin
|
||||||
ruby test_file
|
ruby test_file
|
||||||
|
rescue
|
||||||
|
puts "FAILED #{test_file}!"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
require 'charlock_holmes'
|
||||||
$file_count = 0;
|
$file_count = 0;
|
||||||
markdown_files = Dir["./**/*.html.markdown"]
|
markdown_files = Dir["./**/*.html.markdown"]
|
||||||
markdown_files.each do |file|
|
markdown_files.each do |file|
|
||||||
begin
|
begin
|
||||||
file_bin = File.open(file, "rb")
|
contents = File.read(file)
|
||||||
contents = file_bin.read
|
detection = CharlockHolmes::EncodingDetector.detect(contents)
|
||||||
if ! contents.valid_encoding?
|
case detection[:encoding]
|
||||||
puts "#{file} has an invalid encoding! Please save the file in UTF-8!"
|
when 'UTF-8'
|
||||||
else
|
|
||||||
$file_count = $file_count + 1
|
$file_count = $file_count + 1
|
||||||
|
when 'ISO-8859-1'
|
||||||
|
$file_count = $file_count + 1
|
||||||
|
else
|
||||||
|
puts "#{file} was detected as #{detection[:encoding]} encoding! Please save the file in UTF-8!"
|
||||||
end
|
end
|
||||||
rescue Exception => msg
|
rescue Exception => msg
|
||||||
puts msg
|
puts msg
|
||||||
@ -20,6 +24,6 @@ if files_failed != 0
|
|||||||
puts "Please resave the file as UTF-8."
|
puts "Please resave the file as UTF-8."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
puts "Success. All #{$file_count} files passed UTF-8 validity checks"
|
puts "Success. All #{$file_count} files Ruby's UTF-8 validity checks. This won't catch most problems."
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user