#!/usr/bin/env ruby STDOUT.sync = true $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib }) require 'html/proofer' require 'mercenary' require "rubygems" Mercenary.program(:htmlproof) do |p| p.version Gem::Specification::load(File.join(File.dirname(__FILE__), "..", "html-proofer.gemspec")).version p.description "Test your rendered HTML files to make sure they're accurate." p.syntax 'htmlproof PATH [options]' p.description "Runs the HTML-Proofer suite on the files in PATH" p.option 'ext', '--ext EXT', 'The extension of your HTML files (default: `.html`)' p.option 'favicon', '--favicon', 'Enables the favicon checker (default: `false`).' p.option 'as-links', '--as-links', 'Assumes that `PATH` is a comma-separated array of links to check.' p.option 'swap', '--swap regex:string,[regex:string,...]', Array, 'Array containing key-value pairs of `RegExp:String`. It transforms links that match `RegExp` into `String`' p.option 'href_ignore', '--href_ignore link1,[link2,...]', Array, 'Array of Strings containing `href`s that are safe to ignore. Certain URIs, like `mailto` and `tel`, are always ignored.' p.option 'alt_ignore', '--alt_ignore image1,[image2,...]', Array, 'Array of Strings containing `img`s whose missing `alt` tags are safe to ignore' p.option 'disable_external', '--disable_external', 'Disables the external link checker (default: `false`)' p.option 'only-4xx', '--only-4xx', 'Only reports errors for links that fall within the 4x status code range.' p.option 'verbose', '--verbose', 'Enables more verbose logging.' p.option 'directory_index_file', '--directory_index_file', 'Sets the file to look for when a link refers to a directory.' p.action do |args, opts| args = ["."] if args.empty? path = args.first options = {} options[:ext] = opts["ext"] unless opts["ext"].nil? unless opts["swap"].nil? options[:href_swap] = {} opts["swap"].each do |s| pair = s.split(":") options[:href_swap][%r{#{pair[0]}}] = pair[1] end end options[:href_ignore] = opts["href_ignore"] unless opts["href_ignore"].nil? options[:alt_ignore] = opts["alt_ignore"] unless opts["alt_ignore"].nil? options[:disable_external] = opts["disable_external"] unless opts["disable_external"].nil? options[:favicon] = opts["favicon"] unless opts["favicon"].nil? options[:verbose] = opts["verbose"] unless opts["verbose"].nil? options[:directory_index_file] = opts["directory_index_file"] unless opts["directory_index_file"].nil? path = path.delete(' ').split(",") if opts["as-links"] HTML::Proofer.new(path, options).run end end