snatch 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{snatch}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Conroy-Finn"]
@@ -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/file.extension"></a>'
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/file.extension"></a>'
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
@@ -13,5 +13,5 @@ end
13
13
  def fix_node(method, xhtml)
14
14
  node = Nokogiri::XML(xhtml).children.first
15
15
  subject.send method, node
16
- yield node
16
+ block_given? ? yield(node) : node
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Conroy-Finn