sitemap_generator 5.2.0 → 5.3.0

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.
Files changed (58) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGES.md +250 -0
  3. data/README.md +156 -125
  4. data/VERSION +1 -1
  5. data/lib/capistrano/tasks/sitemap_generator.cap +21 -23
  6. data/lib/sitemap_generator.rb +1 -2
  7. data/lib/sitemap_generator/adapters/s3_adapter.rb +5 -0
  8. data/lib/sitemap_generator/application.rb +1 -1
  9. data/lib/sitemap_generator/builder/sitemap_file.rb +7 -3
  10. data/lib/sitemap_generator/builder/sitemap_url.rb +1 -10
  11. data/lib/sitemap_generator/link_set.rb +16 -10
  12. data/lib/sitemap_generator/{sitemap_namer.rb → simple_namer.rb} +1 -1
  13. data/lib/sitemap_generator/sitemap_location.rb +13 -1
  14. data/lib/sitemap_generator/tasks.rb +2 -2
  15. metadata +51 -123
  16. data/Gemfile +0 -13
  17. data/Gemfile.lock +0 -38
  18. data/Rakefile +0 -43
  19. data/spec/blueprint.rb +0 -15
  20. data/spec/files/sitemap.create.rb +0 -12
  21. data/spec/files/sitemap.groups.rb +0 -49
  22. data/spec/sitemap_generator/adapters/s3_adapter_spec.rb +0 -23
  23. data/spec/sitemap_generator/alternate_sitemap_spec.rb +0 -100
  24. data/spec/sitemap_generator/application_spec.rb +0 -69
  25. data/spec/sitemap_generator/builder/sitemap_file_spec.rb +0 -110
  26. data/spec/sitemap_generator/builder/sitemap_index_file_spec.rb +0 -124
  27. data/spec/sitemap_generator/builder/sitemap_index_url_spec.rb +0 -28
  28. data/spec/sitemap_generator/builder/sitemap_url_spec.rb +0 -192
  29. data/spec/sitemap_generator/core_ext/bigdecimal_spec.rb +0 -20
  30. data/spec/sitemap_generator/core_ext/numeric_spec.rb +0 -43
  31. data/spec/sitemap_generator/file_adaptor_spec.rb +0 -20
  32. data/spec/sitemap_generator/geo_sitemap_spec.rb +0 -30
  33. data/spec/sitemap_generator/helpers/number_helper_spec.rb +0 -196
  34. data/spec/sitemap_generator/interpreter_spec.rb +0 -90
  35. data/spec/sitemap_generator/link_set_spec.rb +0 -864
  36. data/spec/sitemap_generator/mobile_sitemap_spec.rb +0 -27
  37. data/spec/sitemap_generator/news_sitemap_spec.rb +0 -42
  38. data/spec/sitemap_generator/pagemap_sitemap_spec.rb +0 -57
  39. data/spec/sitemap_generator/sitemap_generator_spec.rb +0 -591
  40. data/spec/sitemap_generator/sitemap_groups_spec.rb +0 -144
  41. data/spec/sitemap_generator/sitemap_location_spec.rb +0 -210
  42. data/spec/sitemap_generator/sitemap_namer_spec.rb +0 -96
  43. data/spec/sitemap_generator/templates_spec.rb +0 -24
  44. data/spec/sitemap_generator/utilities/existence_spec.rb +0 -26
  45. data/spec/sitemap_generator/utilities/hash_spec.rb +0 -57
  46. data/spec/sitemap_generator/utilities/rounding_spec.rb +0 -31
  47. data/spec/sitemap_generator/utilities_spec.rb +0 -101
  48. data/spec/sitemap_generator/video_sitemap_spec.rb +0 -117
  49. data/spec/spec_helper.rb +0 -24
  50. data/spec/support/file_macros.rb +0 -39
  51. data/spec/support/schemas/siteindex.xsd +0 -73
  52. data/spec/support/schemas/sitemap-geo.xsd +0 -41
  53. data/spec/support/schemas/sitemap-mobile.xsd +0 -32
  54. data/spec/support/schemas/sitemap-news.xsd +0 -159
  55. data/spec/support/schemas/sitemap-pagemap.xsd +0 -97
  56. data/spec/support/schemas/sitemap-video.xsd +0 -643
  57. data/spec/support/schemas/sitemap.xsd +0 -115
  58. data/spec/support/xml_macros.rb +0 -67
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'SitemapGenerator::Builder::SitemapIndexFile' do
4
- let(:location) { SitemapGenerator::SitemapLocation.new(:filename => 'sitemap.xml.gz', :public_path => '/public/', :host => 'http://example.com/') }
5
- let(:index) { SitemapGenerator::Builder::SitemapIndexFile.new(location) }
6
-
7
- before :each do
8
- index.location[:sitemaps_path] = 'test/'
9
- end
10
-
11
- it "should return the URL" do
12
- index.location.url.should == 'http://example.com/test/sitemap.xml.gz'
13
- end
14
-
15
- it "should return the path" do
16
- index.location.path.should == '/public/test/sitemap.xml.gz'
17
- end
18
-
19
- it "should be empty" do
20
- index.empty?.should be_true
21
- index.link_count.should == 0
22
- end
23
-
24
- it "should not have a last modification data" do
25
- index.lastmod.should be_nil
26
- end
27
-
28
- it "should not be finalized" do
29
- index.finalized?.should be_false
30
- end
31
-
32
- it "filename should be set" do
33
- index.location.filename.should == 'sitemap.xml.gz'
34
- end
35
-
36
- it "should have a default namer" do
37
- index = SitemapGenerator::Builder::SitemapIndexFile.new
38
- index.location.filename.should == 'sitemap.xml.gz'
39
- end
40
-
41
- describe "link_count" do
42
- it "should return the link count" do
43
- index.instance_variable_set(:@link_count, 10)
44
- index.link_count.should == 10
45
- end
46
- end
47
-
48
- describe "create_index?" do
49
- it "should return false" do
50
- index.location[:create_index] = false
51
- index.create_index?.should be_false
52
-
53
- index.instance_variable_set(:@link_count, 10)
54
- index.create_index?.should be_false
55
- end
56
-
57
- it "should return true" do
58
- index.location[:create_index] = true
59
- index.create_index?.should be_true
60
-
61
- index.instance_variable_set(:@link_count, 1)
62
- index.create_index?.should be_true
63
- end
64
-
65
- it "when :auto, should be true if more than one link" do
66
- index.instance_variable_set(:@link_count, 1)
67
- index.location[:create_index] = :auto
68
- index.create_index?.should be_false
69
-
70
- index.instance_variable_set(:@link_count, 2)
71
- index.create_index?.should be_true
72
- end
73
- end
74
-
75
- describe "add" do
76
- it "should use the host provided" do
77
- url = SitemapGenerator::Builder::SitemapIndexUrl.new('/one', :host => 'http://newhost.com/')
78
- SitemapGenerator::Builder::SitemapIndexUrl.expects(:new).with('/one', :host => 'http://newhost.com').returns(url)
79
- index.add '/one', :host => 'http://newhost.com'
80
- end
81
-
82
- it "should use the host from the location" do
83
- url = SitemapGenerator::Builder::SitemapIndexUrl.new('/one', :host => 'http://example.com/')
84
- SitemapGenerator::Builder::SitemapIndexUrl.expects(:new).with('/one', :host => 'http://example.com/').returns(url)
85
- index.add '/one'
86
- end
87
-
88
- describe "when adding manually" do
89
- it "should reserve a name" do
90
- index.expects(:reserve_name)
91
- index.add '/link'
92
- end
93
-
94
- it "should create index" do
95
- index.create_index?.should be_false
96
- index.add '/one'
97
- index.create_index?.should be_true
98
- end
99
- end
100
- end
101
-
102
- describe "index_url" do
103
- it "when not creating an index, should be the first sitemap url" do
104
- index.instance_variable_set(:@create_index, false)
105
- index.instance_variable_set(:@first_sitemap_url, 'http://test.com/index.xml')
106
- index.create_index?.should be_false
107
- index.index_url.should == 'http://test.com/index.xml'
108
- end
109
-
110
- it "if there's no first sitemap url, should default to the index location url" do
111
- index.instance_variable_set(:@create_index, false)
112
- index.instance_variable_set(:@first_sitemap_url, nil)
113
- index.create_index?.should be_false
114
- index.index_url.should == index.location.url
115
- index.index_url.should == 'http://example.com/test/sitemap.xml.gz'
116
- end
117
-
118
- it "when creating an index, should be the index location url" do
119
- index.instance_variable_set(:@create_index, true)
120
- index.index_url.should == index.location.url
121
- index.index_url.should == 'http://example.com/test/sitemap.xml.gz'
122
- end
123
- end
124
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SitemapGenerator::Builder::SitemapIndexUrl do
4
- let(:index) {
5
- SitemapGenerator::Builder::SitemapIndexFile.new(
6
- :sitemaps_path => 'sitemaps/',
7
- :host => 'http://test.com',
8
- :filename => 'sitemap_index.xml.gz'
9
- )
10
- }
11
- let(:url) { SitemapGenerator::Builder::SitemapUrl.new(index) }
12
-
13
- it "should return the correct url" do
14
- url[:loc].should == 'http://test.com/sitemaps/sitemap_index.xml.gz'
15
- end
16
-
17
- it "should use the host from the index" do
18
- host = 'http://myexample.com'
19
- index.location.expects(:host).returns(host)
20
- url[:host].should == host
21
- end
22
-
23
- it "should use the public path for the link" do
24
- path = '/path'
25
- index.location.expects(:path_in_public).returns(path)
26
- url[:loc].should == 'http://test.com/path'
27
- end
28
- end
@@ -1,192 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SitemapGenerator::Builder::SitemapUrl do
4
- let(:loc) {
5
- SitemapGenerator::SitemapLocation.new(
6
- :sitemaps_path => 'sitemaps/',
7
- :public_path => '/public',
8
- :host => 'http://test.com',
9
- :namer => SitemapGenerator::SimpleNamer.new(:sitemap)
10
- )}
11
- let(:sitemap_file) { SitemapGenerator::Builder::SitemapFile.new(loc) }
12
-
13
- def new_url(*args)
14
- if args.empty?
15
- args = ['/home', { :host => 'http://example.com' }]
16
- end
17
- SitemapGenerator::Builder::SitemapUrl.new(*args)
18
- end
19
-
20
- it "should build urls for sitemap files" do
21
- url = SitemapGenerator::Builder::SitemapUrl.new(sitemap_file)
22
- url[:loc].should == 'http://test.com/sitemaps/sitemap.xml.gz'
23
- end
24
-
25
- it "lastmod should default to the last modified date for sitemap files" do
26
- lastmod = (Time.now - 1209600)
27
- sitemap_file.expects(:lastmod).returns(lastmod)
28
- url = SitemapGenerator::Builder::SitemapUrl.new(sitemap_file)
29
- url[:lastmod].should == lastmod
30
- end
31
-
32
- it "should support string option keys" do
33
- url = new_url('/home', 'host' => 'http://string.com', 'priority' => 1)
34
- url[:priority].should == 1
35
- url[:host].should == 'http://string.com'
36
- end
37
-
38
- it "should support subdirectory routing" do
39
- url = SitemapGenerator::Builder::SitemapUrl.new('/profile', :host => 'http://example.com/subdir/')
40
- url[:loc].should == 'http://example.com/subdir/profile'
41
- url = SitemapGenerator::Builder::SitemapUrl.new('profile', :host => 'http://example.com/subdir/')
42
- url[:loc].should == 'http://example.com/subdir/profile'
43
- url = SitemapGenerator::Builder::SitemapUrl.new('/deep/profile/', :host => 'http://example.com/subdir/')
44
- url[:loc].should == 'http://example.com/subdir/deep/profile/'
45
- url = SitemapGenerator::Builder::SitemapUrl.new('/deep/profile', :host => 'http://example.com/subdir')
46
- url[:loc].should == 'http://example.com/subdir/deep/profile'
47
- url = SitemapGenerator::Builder::SitemapUrl.new('deep/profile', :host => 'http://example.com/subdir')
48
- url[:loc].should == 'http://example.com/subdir/deep/profile'
49
- url = SitemapGenerator::Builder::SitemapUrl.new('deep/profile/', :host => 'http://example.com/subdir/')
50
- url[:loc].should == 'http://example.com/subdir/deep/profile/'
51
- url = SitemapGenerator::Builder::SitemapUrl.new('/', :host => 'http://example.com/subdir/')
52
- url[:loc].should == 'http://example.com/subdir/'
53
- end
54
-
55
- it "should not fail on a nil path segment" do
56
- lambda do
57
- SitemapGenerator::Builder::SitemapUrl.new(nil, :host => 'http://example.com')[:loc].should == 'http://example.com'
58
- end.should_not raise_error
59
- end
60
-
61
- it "should support a :videos option" do
62
- loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :videos => [1,2,3])
63
- loc[:videos].should == [1,2,3]
64
- end
65
-
66
- it "should support a singular :video option" do
67
- loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :video => 1)
68
- loc[:videos].should == [1]
69
- end
70
-
71
- it "should support an array :video option" do
72
- loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :video => [1,2], :videos => [3,4])
73
- loc[:videos].should == [3,4,1,2]
74
- end
75
-
76
- it "should support a :alternates option" do
77
- loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :alternates => [1,2,3])
78
- loc[:alternates].should == [1,2,3]
79
- end
80
-
81
- it "should support a singular :alternate option" do
82
- loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :alternate => 1)
83
- loc[:alternates].should == [1]
84
- end
85
-
86
- it "should support an array :alternate option" do
87
- loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :alternate => [1,2], :alternates => [3,4])
88
- loc[:alternates].should == [3,4,1,2]
89
- end
90
-
91
- it "should not fail if invalid characters are used in the URL" do
92
- special = ':$&+,;:=?@'
93
- url = SitemapGenerator::Builder::SitemapUrl.new("/#{special}", :host => "http://example.com/#{special}/")
94
- url[:loc].should == "http://example.com/#{special}/#{special}"
95
- end
96
-
97
- describe "w3c_date" do
98
- it "should convert dates and times to W3C format" do
99
- url = new_url
100
- url.send(:w3c_date, Date.new(0)).should == '0000-01-01'
101
- url.send(:w3c_date, Time.at(0).utc).should == '1970-01-01T00:00:00+00:00'
102
- url.send(:w3c_date, DateTime.new(0)).should == '0000-01-01T00:00:00+00:00'
103
- end
104
-
105
- it "should return strings unmodified" do
106
- new_url.send(:w3c_date, '2010-01-01').should == '2010-01-01'
107
- end
108
-
109
- it "should try to convert to utc" do
110
- time = Time.at(0)
111
- time.expects(:respond_to?).times(2).returns(false, true) # iso8601, utc
112
- new_url.send(:w3c_date, time).should == '1970-01-01T00:00:00+00:00'
113
- end
114
-
115
- it "should include timezone for objects which do not respond to iso8601 or utc" do
116
- time = Time.at(0)
117
- time.expects(:respond_to?).times(2).returns(false, false) # iso8601, utc
118
- time.expects(:strftime).times(2).returns('+0800', '1970-01-01T00:00:00')
119
- new_url.send(:w3c_date, time).should == '1970-01-01T00:00:00+08:00'
120
- end
121
-
122
- it "should support integers" do
123
- new_url.send(:w3c_date, Time.at(0).to_i).should == '1970-01-01T00:00:00+00:00'
124
- end
125
- end
126
-
127
- describe "yes_or_no" do
128
- it "should recognize truthy values" do
129
- new_url.send(:yes_or_no, 1).should == 'yes'
130
- new_url.send(:yes_or_no, 0).should == 'yes'
131
- new_url.send(:yes_or_no, 'yes').should == 'yes'
132
- new_url.send(:yes_or_no, 'Yes').should == 'yes'
133
- new_url.send(:yes_or_no, 'YES').should == 'yes'
134
- new_url.send(:yes_or_no, true).should == 'yes'
135
- new_url.send(:yes_or_no, Object.new).should == 'yes'
136
- end
137
-
138
- it "should recognize falsy values" do
139
- new_url.send(:yes_or_no, nil).should == 'no'
140
- new_url.send(:yes_or_no, 'no').should == 'no'
141
- new_url.send(:yes_or_no, 'No').should == 'no'
142
- new_url.send(:yes_or_no, 'NO').should == 'no'
143
- new_url.send(:yes_or_no, false).should == 'no'
144
- end
145
-
146
- it "should raise on unrecognized strings" do
147
- lambda { new_url.send(:yes_or_no, 'dunno') }.should raise_error(ArgumentError)
148
- lambda { new_url.send(:yes_or_no, 'yessir') }.should raise_error(ArgumentError)
149
- end
150
- end
151
-
152
- describe "yes_or_no_with_default" do
153
- it "should use the default if the value is nil" do
154
- url = new_url
155
- url.expects(:yes_or_no).with(true).returns('surely')
156
- url.send(:yes_or_no_with_default, nil, true).should == 'surely'
157
- end
158
-
159
- it "should use the value if it is not nil" do
160
- url = new_url
161
- url.expects(:yes_or_no).with('surely').returns('absolutely')
162
- url.send(:yes_or_no_with_default, 'surely', true).should == 'absolutely'
163
- end
164
- end
165
-
166
- describe "format_float" do
167
- it "should not modify if a string" do
168
- new_url.send(:format_float, '0.4').should == '0.4'
169
- end
170
-
171
- it "should round to one decimal place" do
172
- url = new_url
173
- url.send(:format_float, 0.499999).should == '0.5'
174
- url.send(:format_float, 3.444444).should == '3.4'
175
- end
176
- end
177
-
178
- describe "expires" do
179
- let(:url) { SitemapGenerator::Builder::SitemapUrl.new('/path', :host => 'http://example.com', :expires => time) }
180
- let(:time) { Time.at(0).utc }
181
-
182
- it "should include the option" do
183
- url[:expires].should == time
184
- end
185
-
186
- it "should format it and include it in the XML" do
187
- xml = url.to_xml
188
- doc = Nokogiri::XML("<root xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' xmlns:xhtml='http://www.w3.org/1999/xhtml'>#{xml}</root>")
189
- doc.css('url expires').text.should == url.send(:w3c_date, time)
190
- end
191
- end
192
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'bigdecimal'
3
-
4
- describe SitemapGenerator::BigDecimal do
5
- describe "to_yaml" do
6
- it "should serialize correctly" do
7
- SitemapGenerator::BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml.should =~ /^--- 100000\.30020320320000000000000000000000000000001\n/
8
- SitemapGenerator::BigDecimal.new('Infinity').to_yaml.should =~ /^--- \.Inf\n/
9
- SitemapGenerator::BigDecimal.new('NaN').to_yaml.should =~ /^--- \.NaN\n/
10
- SitemapGenerator::BigDecimal.new('-Infinity').to_yaml.should =~ /^--- -\.Inf\n/
11
- end
12
- end
13
-
14
- describe "to_d" do
15
- it "should convert correctly" do
16
- bd = SitemapGenerator::BigDecimal.new '10'
17
- bd.to_d.should == bd
18
- end
19
- end
20
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SitemapGenerator::Numeric do
4
- def numeric(size)
5
- SitemapGenerator::Numeric.new(size)
6
- end
7
-
8
- describe "bytes" do
9
- it "should define equality of different units" do
10
- relationships = {
11
- numeric( 1024).bytes => numeric( 1).kilobyte,
12
- numeric( 1024).kilobytes => numeric( 1).megabyte,
13
- numeric(3584.0).kilobytes => numeric(3.5).megabytes,
14
- numeric(3584.0).megabytes => numeric(3.5).gigabytes,
15
- numeric(1).kilobyte ** 4 => numeric( 1).terabyte,
16
- numeric(1024).kilobytes + numeric(2).megabytes => numeric(3).megabytes,
17
- numeric( 2).gigabytes / 4 => numeric(512).megabytes,
18
- numeric(256).megabytes * 20 +numeric( 5).gigabytes => numeric(10).gigabytes,
19
- numeric(1).kilobyte ** 5 => numeric(1).petabyte,
20
- numeric(1).kilobyte ** 6 => numeric(1).exabyte
21
- }
22
-
23
- relationships.each do |left, right|
24
- left.should == right
25
- end
26
- end
27
-
28
- it "should represent units as bytes" do
29
- numeric(3).megabytes.should == 3145728
30
- numeric(3).megabyte .should == 3145728
31
- numeric(3).kilobytes.should == 3072
32
- numeric(3).kilobyte .should == 3072
33
- numeric(3).gigabytes.should == 3221225472
34
- numeric(3).gigabyte .should == 3221225472
35
- numeric(3).terabytes.should == 3298534883328
36
- numeric(3).terabyte .should == 3298534883328
37
- numeric(3).petabytes.should == 3377699720527872
38
- numeric(3).petabyte .should == 3377699720527872
39
- numeric(3).exabytes .should == 3458764513820540928
40
- numeric(3).exabyte .should == 3458764513820540928
41
- end
42
- end
43
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "SitemapGenerator::FileAdapter" do
4
- let(:location) { SitemapGenerator::SitemapLocation.new }
5
- let(:adapter) { SitemapGenerator::FileAdapter.new }
6
-
7
- describe "write" do
8
- it "should gzip contents if filename ends in .gz" do
9
- adapter.expects(:gzip).once
10
- location.stubs(:filename).returns('sitemap.xml.gz')
11
- adapter.write(location, 'data')
12
- end
13
-
14
- it "should not gzip contents if filename does not end in .gz" do
15
- adapter.expects(:plain).once
16
- location.stubs(:filename).returns('sitemap.xml')
17
- adapter.write(location, 'data')
18
- end
19
- end
20
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "SitemapGenerator" do
4
-
5
- it "should add the geo sitemap element" do
6
- loc = 'http://www.example.com/geo_page.kml'
7
- format = 'kml'
8
-
9
- geo_xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('geo_page.kml',
10
- :host => 'http://www.example.com',
11
- :geo => {
12
- :format => format
13
- }
14
- ).to_xml
15
-
16
- # Check that the options were parsed correctly
17
- doc = Nokogiri::XML.parse("<root xmlns:geo='#{SitemapGenerator::SCHEMAS['geo']}'>#{geo_xml_fragment}</root>")
18
- url = doc.at_xpath("//url")
19
- url.should_not be_nil
20
- url.at_xpath("loc").text.should == loc
21
-
22
- geo = url.at_xpath("geo:geo")
23
- geo.should_not be_nil
24
- geo.at_xpath("geo:format").text.should == format
25
-
26
- # Google's documentation and published schema don't match some valid elements may
27
- # not validate.
28
- xml_fragment_should_validate_against_schema(geo, 'sitemap-geo', 'xmlns:geo' => SitemapGenerator::SCHEMAS['geo'])
29
- end
30
- end