Permalink
Browse files

Add in my validate script for posterity

If you can figure out how to use it, good for you!
  • Loading branch information...
1 parent 04a2ad0 commit cefb84f294eb97d5939a284791880a038c32b82e @sophiebits sophiebits committed Feb 7, 2012
Showing with 27 additions and 0 deletions.
  1. +27 −0 build/validate.rb
View
@@ -0,0 +1,27 @@
+require 'rubygems'
+require 'validator.nu'
+require 'json'
+require 'pp'
+
+files = Dir[File.join(File.dirname(__FILE__), '../exercises/*.html')]
+
+files.each do |file|
+ name = File.basename(file, ".html")
+ if name =~ /^khan-(?:exercise|site)$/
+ puts "skipping #{name}"
+ next
+ end
+
+ doc = File.read(file)
+ doc.gsub!(/<(?!(?:\/?[a-z]+|!DOCTYPE|!--))/, '&lt;')
+ # doc.gsub!(/< /, '&lt;')
+ doc.gsub!(/&(?![a-z])/, '&amp;')
+ doc.gsub!(/ id=".+?"/, "")
+
+ output = JSON.parse(Validator.nu(doc, :host => '127.0.0.1', :port => 8888))
+
+ puts "#{name}" if output["messages"].length > 2
+ output["messages"][2..-1].each do |message|
+ puts "#{message["type"]} on line #{message["lastLine"]}: #{message["message"]}"[0..79]
+ end
+end

0 comments on commit cefb84f

Please sign in to comment.