Module: Snatch::Clean::HTML::HrefFixMethods
- Defined in:
- lib/snatch/clean/html.rb
Instance Method Summary collapse
- #append_index_html(a) ⇒ Object
- #append_slash(a) ⇒ Object
- #encode_mailtos(a) ⇒ Object
- #prepend_slash(a) ⇒ Object
- #replace_absolute(a) ⇒ Object
Instance Method Details
#append_index_html(a) ⇒ Object
def remove_index_html(a)
a['href'] = a['href'].sub(%r{index\.html?$}, '')
end
9 10 11 12 13 |
# File 'lib/snatch/clean/html.rb', line 9 def append_index_html(a) unless File.extname(a['href']).include?('.') a['href'] = a['href'].sub(%r{/?$}, '') + '/index.html' end end |
#append_slash(a) ⇒ Object
32 33 34 |
# File 'lib/snatch/clean/html.rb', line 32 def append_slash(a) a['href'] = a['href'].sub(%r{/?$}, '/') if (%w(# : .) & a['href'].split(//)).empty? end |
#encode_mailtos(a) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/snatch/clean/html.rb', line 19 def encode_mailtos(a) if a['href'] =~ /^mailto:(.*)/ a['href'] = 'mailto:' + HTML.url_encode($1) a.inner_html = HTML.html_encode(a.inner_html) end end |
#prepend_slash(a) ⇒ Object
26 27 28 29 30 |
# File 'lib/snatch/clean/html.rb', line 26 def prepend_slash(a) includes_special_chars = (%w(: .) & a['href'].split(//)).empty? relative_upload = a['href'].match(/^#{UPLOADS_DIR}/) a['href'] = a['href'].sub(%r{^/?}, '/') if includes_special_chars || relative_upload end |
#replace_absolute(a) ⇒ Object
15 16 17 |
# File 'lib/snatch/clean/html.rb', line 15 def replace_absolute(a) a['href'] = a['href'].sub(%r{https?://#{MARKETING_SITE}/}, '/') end |