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


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

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

.create_nokogiri(path) ⇒ Object


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

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


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

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


7
8
9
# File 'lib/html-proofer/utils.rb', line 7

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