Class: Nanoc::Checking::LinkCollector Private

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/checking/link_collector.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

URI_ATTRS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

HTML5 element attributes

{
  'a' => i[href ping],
  'area' => i[href ping],
  'audio' => i[src],
  'base' => i[href],
  'blockquote' => i[cite],
  'form' => i[action],
  'iframe' => i[src],
  'img' => i[src srcset],
  'link' => i[href],
  'object' => i[data],
  'script' => i[src],
  'source' => i[src srcset],
  'video' => i[poster src],
}.freeze
GLOBAL_ATTRS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

HTML+RDFa global URI attributes

i[about resource].freeze

Instance Method Summary collapse

Constructor Details

#initialize(filenames, mode = nil) ⇒ LinkCollector

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LinkCollector.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nanoc/checking/link_collector.rb', line 25

def initialize(filenames, mode = nil)
  @filenames = filenames
  @filter =
    case mode
    when nil
      ->(_h) { true }
    when :external
      ->(h) { external_href?(h) }
    when :internal
      ->(h) { internal_href?(h) }
    else
      raise ArgumentError, 'Expected mode argument to be :internal, :external or nil'
    end
end

Instance Method Details

#external_href?(href) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/nanoc/checking/link_collector.rb', line 48

def external_href?(href)
  return false if internal_href?(href)

  href =~ %r{^(//|[a-z-]+:)}
end

#filenames_per_hrefObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nanoc/checking/link_collector.rb', line 40

def filenames_per_href
  grouped_filenames { |filename| hrefs_in_file(filename) }
end

#filenames_per_resource_uriObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/nanoc/checking/link_collector.rb', line 44

def filenames_per_resource_uri
  grouped_filenames { |filename| resource_uris_in_file(filename) }
end

#hrefs_in_file(filename) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

all links



61
62
63
# File 'lib/nanoc/checking/link_collector.rb', line 61

def hrefs_in_file(filename)
  uris_in_file filename, nil
end

#internal_href?(href) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/nanoc/checking/link_collector.rb', line 54

def internal_href?(href)
  return false if href.nil?

  href.start_with?('file:/')
end

#resource_uris_in_file(filename) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

embedded resources, used by the mixed-content checker



66
67
68
# File 'lib/nanoc/checking/link_collector.rb', line 66

def resource_uris_in_file(filename)
  uris_in_file filename, %w[audio base form iframe img link object script source video]
end