Module: HTMLProofer::Utils
- Included in:
- Cache, Element, Middleware, Runner, UrlValidator, LinkCheck
- Defined in:
- lib/html-proofer/utils.rb
Instance Method Summary collapse
-
#clean_content(string) ⇒ Object
address a problem with Nokogiri’s parsing URL entities problem from git.io/vBYU1 solution from git.io/vBYUi.
- #create_nokogiri(path) ⇒ Object
- #pluralize(count, single, plural) ⇒ Object
- #swap(href, replacement) ⇒ Object
Instance 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
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 |
#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 |
#swap(href, replacement) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/html-proofer/utils.rb', line 21 def swap(href, replacement) replacement.each do |link, replace| href = href.gsub(link, replace) end href end |