Parent

Methods

Class/Module Index [+]

Quicksearch

Nanoc3::Extra::Validators::Links

A validator that verifies that all links (`<a href=“…”>…</a>`) point to a location that exists.

Public Class Methods

new(dir, index_filenames, params={}) click to toggle source

@param [String] dir The directory that will be searched for HTML files to validate

@param [Array<String>] index_filenames An array of index filenames that will be appended to URLs by web servers if a directory is requested instead of a file

@option params [Boolean] :internal (false) True if internal links should be checked; false if they should not

@option params [Boolean] :external (false) True if external links should be checked; false if they should not

# File lib/nanoc3/extra/validators/links.rb, line 20
def initialize(dir, index_filenames, params={})
  @dir              = dir
  @index_filenames  = index_filenames
  @include_internal = params.has_key?(:internal) && params[:internal]
  @include_external = params.has_key?(:external) && params[:external]
end

Public Instance Methods

run() click to toggle source

Starts the validator. The results will be printed to stdout.

@return [void]

# File lib/nanoc3/extra/validators/links.rb, line 30
def run
  require 'nokogiri'

  @delegate = self
  links = all_broken_hrefs
  if links.empty?
    puts "No broken links found!"
  else
    links.each_pair do |href, origins|
      puts "Broken link: #{href} -- referenced from:"
      origins.each do |origin|
        puts "    #{origin}"
      end
      puts
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.