Module: HTML::Proofer::Utils
- Included in:
- HTML::Proofer, Cache, Checkable, UrlValidator, LinkCheck
- Defined in:
- lib/html/proofer/utils.rb
Constant Summary collapse
- STORAGE_DIR =
File.join('tmp', '.htmlproofer')
Class 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
- .swap(href, replacement) ⇒ Object
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
34 35 36 37 38 39 40 41 42 |
# File 'lib/html/proofer/utils.rb', line 34 def clean_content(string) matches = string.scan(%r{https?://([^>]+)}i) matches.flatten.each do |url| escaped_url = url.gsub(/&(?!amp;)/, '&') string.gsub!(url, escaped_url) end string end |
.create_nokogiri(path) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/html/proofer/utils.rb', line 12 def create_nokogiri(path) if File.exist? path content = File.open(path).read else content = path end Nokogiri::HTML(clean_content(content)) end |
.swap(href, replacement) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/html/proofer/utils.rb', line 23 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
8 9 10 |
# File 'lib/html/proofer/utils.rb', line 8 def pluralize(count, single, plural) "#{count} " << (count == 1 ? single : plural) end |