diff options
author | Jaime Iniesta <jaimeiniesta@gmail.com> | 2010-05-24 18:07:48 +0200 |
---|---|---|
committer | Jaime Iniesta <jaimeiniesta@gmail.com> | 2010-05-24 18:07:48 +0200 |
commit | 3391cb903ed5fbed8e899113126612a86f68b858 (patch) | |
tree | 444915658f13a611627379675398136ac40734ef /railties | |
parent | c36374e7688fb0d316e0b6e59515e05a1761bebe (diff) | |
parent | 7db557f1520b2c2c60958e67c049ff424f61cbf1 (diff) | |
download | rails-3391cb903ed5fbed8e899113126612a86f68b858.tar.gz rails-3391cb903ed5fbed8e899113126612a86f68b858.tar.bz2 rails-3391cb903ed5fbed8e899113126612a86f68b858.zip |
Merge branch 'w3c_validator'
Diffstat (limited to 'railties')
-rw-r--r-- | railties/Rakefile | 6 | ||||
-rw-r--r-- | railties/guides/w3c_validator.rb | 67 |
2 files changed, 73 insertions, 0 deletions
diff --git a/railties/Rakefile b/railties/Rakefile index daffd8ce30..efdb31cbd8 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -50,6 +50,12 @@ task :update_prototype_ujs do system "curl http://github.com/rails/prototype-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/rails.js" end +# Validate guides ------------------------------------------------------------------------- +desc 'Validate guides, use ONLY=foo to process just "foo.html"' +task :validate_guides do + ruby "guides/w3c_validator.rb" +end + # Generate documentation ------------------------------------------------------------------ Rake::RDocTask.new { |rdoc| diff --git a/railties/guides/w3c_validator.rb b/railties/guides/w3c_validator.rb new file mode 100644 index 0000000000..b55645a7a9 --- /dev/null +++ b/railties/guides/w3c_validator.rb @@ -0,0 +1,67 @@ +# --------------------------------------------------------------------------- +# +# 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 +# ONLY=assoc,migrations rake validate_guides +# +# --------------------------------------------------------------------------- + +require 'rubygems' +require 'w3c_validators' +include W3CValidators + +module RailsGuides + class Validator + + def validate + validator = MarkupValidator.new + + guides_to_validate.each do |f| + puts "Validating #{f}" + results = validator.validate_file(f) + + if !results.validity + puts "#{f} FAILED W3C validation with #{results.errors.size} error(s):" + results.errors.each do |error| + puts error.to_s + end + end + end + end + + private + def guides_to_validate + guides = Dir["./guides/output/*.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 + end +end + +RailsGuides::Validator.new.validate
\ No newline at end of file |