snatch 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/snatch/clean/html.rb +8 -0
- data/snatch.gemspec +1 -1
- data/spec/snatch/clean/html_spec.rb +19 -2
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/lib/snatch/clean/html.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
class Snatch
|
2
2
|
class Clean
|
3
3
|
class HTML
|
4
|
+
require 'uri'
|
5
|
+
|
4
6
|
module HrefFixMethods
|
5
7
|
# def remove_index_html(a)
|
6
8
|
# a['href'] = a['href'].sub(%r{index\.html?$}, '')
|
7
9
|
# end
|
8
10
|
|
11
|
+
def append_index_html(a)
|
12
|
+
unless File.extname(a['href']).include?('.')
|
13
|
+
a['href'] = a['href'].sub(%r{/?$}, '') + '/index.html'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
9
17
|
def replace_absolute(a)
|
10
18
|
a['href'] = a['href'].sub(%r{(https?)://#{MARKETING_SITE}/}, '/')
|
11
19
|
end
|
data/snatch.gemspec
CHANGED
@@ -40,11 +40,11 @@ describe Snatch::Clean::HTML do
|
|
40
40
|
# end
|
41
41
|
|
42
42
|
it 'should preserve parent directories within a URL' do
|
43
|
-
anchor = '<a href="/folder/child/
|
43
|
+
anchor = '<a href="/folder/child/index.html"></a>'
|
44
44
|
doc = Nokogiri::XML(anchor)
|
45
45
|
@html.doc = doc
|
46
46
|
@html.send(:update)
|
47
|
-
@html.doc.to_xhtml.strip.should == '<a href="/folder/child/
|
47
|
+
@html.doc.to_xhtml.strip.should == '<a href="/folder/child/index.html"></a>'
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should replace an absolute CMS URL with a domainless absolute URL' do
|
@@ -54,6 +54,23 @@ describe Snatch::Clean::HTML do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
describe 'appending index.html' do
|
58
|
+
it 'without an extension' do
|
59
|
+
node = fix_node(:append_index_html, '<a href="/folder"></a>')
|
60
|
+
node.should have_href('/folder/index.html')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'with an extension' do
|
64
|
+
node = fix_node(:append_index_html, '<a href="folder/file.txt"></a>"')
|
65
|
+
node.should have_href('folder/file.txt')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'with an absolute URL including a domain name' do
|
69
|
+
node = fix_node(:append_index_html, '<a href="http://domain.com/"></a>')
|
70
|
+
node.should have_href('http://domain.com/index.html')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
57
74
|
it 'should encode email addresses' do
|
58
75
|
anchor = %Q{<a href="mailto:blah@exåmplé.cøm">blah@exåmplé.cøm</a>}
|
59
76
|
@html.class.should_receive(:url_encode).and_return('url_encode')
|
data/spec/spec_helper.rb
CHANGED