Module: HTMLProofer::Utils

Included in:
Cache, Element, Runner, UrlValidator, LinkCheck
Defined in:
lib/html-proofer/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clean_content(string) ⇒ Object

address a problem with Nokogiri's parsing URL entities problem from git.io/vBYU1 solution from git.io/vBYUi



31
32
33
34
35
# File 'lib/html-proofer/utils.rb', line 31

def clean_content(string)
  string.gsub(%r{(?:https?:)?//([^>]+)}i) do |url|
    url.gsub(/&(?!amp;)/, '&')
  end
end

.create_nokogiri(path) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/html-proofer/utils.rb', line 9

def create_nokogiri(path)
  content = if File.exist?(path) && !File.directory?(path)
              File.open(path).read
            else
              path
            end

  Nokogiri::HTML(clean_content(content))
end

.swap(href, replacement) ⇒ Object



20
21
22
23
24
25
# File 'lib/html-proofer/utils.rb', line 20

def swap(href, replacement)
  replacement.each do |link, replace|
    href = href.gsub(link, replace)
  end
  href
end

Instance Method Details

#pluralize(count, single, plural) ⇒ Object



5
6
7
# File 'lib/html-proofer/utils.rb', line 5

def pluralize(count, single, plural)
  "#{count} " << (count == 1 ? single : plural)
end