aboutsummaryrefslogtreecommitdiffstats
path: root/guides/w3c_validator.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-03-17 08:32:49 -0700
committerXavier Noria <fxn@hashref.com>2012-03-17 08:32:49 -0700
commit6d87cd028b32570973450424db164e5405a0ee13 (patch)
tree38008699f54532c6ba446ec806ccc33ad26b10fd /guides/w3c_validator.rb
parent9d06b49913dd2a2254d87c7af1af9f1e4d7f64ec (diff)
downloadrails-6d87cd028b32570973450424db164e5405a0ee13.tar.gz
rails-6d87cd028b32570973450424db164e5405a0ee13.tar.bz2
rails-6d87cd028b32570973450424db164e5405a0ee13.zip
moves the guides up to the root directory
Diffstat (limited to 'guides/w3c_validator.rb')
-rw-r--r--guides/w3c_validator.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/guides/w3c_validator.rb b/guides/w3c_validator.rb
new file mode 100644
index 0000000000..f1fe1e0f33
--- /dev/null
+++ b/guides/w3c_validator.rb
@@ -0,0 +1,91 @@
+# ---------------------------------------------------------------------------
+#
+# This script validates the generated guides against the W3C Validator.
+#
+# Guides are taken from the output directory, from where all .html files are
+# submitted to the validator.
+#
+# This script is prepared to be launched from the railties directory as a rake task:
+#
+# rake validate_guides
+#
+# If nothing is specified, all files will be validated, but you can check just
+# some of them using this environment variable:
+#
+# ONLY
+# Use ONLY if you want to validate only one or a set of guides. Prefixes are
+# enough:
+#
+# # validates only association_basics.html
+# ONLY=assoc rake validate_guides
+#
+# Separate many using commas:
+#
+# # validates only association_basics.html and migrations.html
+# ONLY=assoc,migrations rake validate_guides
+#
+# ---------------------------------------------------------------------------
+
+require 'rubygems'
+require 'w3c_validators'
+include W3CValidators
+
+module RailsGuides
+ class Validator
+
+ def validate
+ validator = MarkupValidator.new
+ STDOUT.sync = true
+ errors_on_guides = {}
+
+ guides_to_validate.each do |f|
+ results = validator.validate_file(f)
+
+ if results.validity
+ print "."
+ else
+ print "E"
+ errors_on_guides[f] = results.errors
+ end
+ end
+
+ show_results(errors_on_guides)
+ end
+
+ private
+ def guides_to_validate
+ guides = Dir["./guides/output/*.html"]
+ guides.delete("./guides/output/layout.html")
+ ENV.key?('ONLY') ? select_only(guides) : guides
+ end
+
+ def select_only(guides)
+ prefixes = ENV['ONLY'].split(",").map(&:strip)
+ guides.select do |guide|
+ prefixes.any? {|p| guide.start_with?("./guides/output/#{p}")}
+ end
+ end
+
+ def show_results(error_list)
+ if error_list.size == 0
+ puts "\n\nAll checked guides validate OK!"
+ else
+ error_summary = error_detail = ""
+
+ error_list.each_pair do |name, errors|
+ error_summary += "\n #{name}"
+ error_detail += "\n\n #{name} has #{errors.size} validation error(s):\n"
+ errors.each do |error|
+ error_detail += "\n "+error.to_s.gsub("\n", "")
+ end
+ end
+
+ puts "\n\nThere are #{error_list.size} guides with validation errors:\n" + error_summary
+ puts "\nHere are the detailed errors for each guide:" + error_detail
+ end
+ end
+
+ end
+end
+
+RailsGuides::Validator.new.validate