sitemap_generator 4.0.alpha → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +1 -3
- data/README.md +197 -111
- data/VERSION +1 -1
- data/lib/sitemap_generator/builder/sitemap_file.rb +12 -12
- data/lib/sitemap_generator/builder/sitemap_index_file.rb +22 -8
- data/lib/sitemap_generator/builder/sitemap_url.rb +4 -2
- data/lib/sitemap_generator/link_set.rb +139 -67
- data/lib/sitemap_generator/sitemap_location.rb +5 -5
- data/lib/sitemap_generator/sitemap_namer.rb +14 -5
- data/spec/files/sitemap.deprecated.rb +2 -0
- data/spec/files/sitemap.groups.rb +14 -2
- data/spec/sitemap_generator/alternate_sitemap_spec.rb +25 -0
- data/spec/sitemap_generator/builder/sitemap_file_spec.rb +78 -25
- data/spec/sitemap_generator/builder/sitemap_index_file_spec.rb +75 -12
- data/spec/sitemap_generator/builder/sitemap_index_url_spec.rb +17 -5
- data/spec/sitemap_generator/link_set_spec.rb +56 -13
- data/spec/sitemap_generator/sitemap_generator_spec.rb +222 -75
- data/spec/sitemap_generator/sitemap_groups_spec.rb +52 -41
- data/spec/sitemap_generator/sitemap_location_spec.rb +46 -44
- data/spec/sitemap_generator/sitemap_namer_spec.rb +14 -0
- data/spec/spec_helper.rb +3 -0
- metadata +17 -14
@@ -10,48 +10,57 @@ def with_max_links(num)
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "Sitemap Groups" do
|
13
|
+
let(:linkset) { ::SitemapGenerator::LinkSet.new(:default_host => 'http://test.com') }
|
14
|
+
|
13
15
|
before :each do
|
14
|
-
@sm = ::SitemapGenerator::LinkSet.new(:default_host => 'http://test.com')
|
15
16
|
FileUtils.rm_rf(SitemapGenerator.app.root + 'public/')
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should not finalize the default sitemap if using groups" do
|
19
|
-
|
20
|
+
linkset.create do
|
20
21
|
group(:filename => :sitemap_en) do
|
21
22
|
add '/en'
|
22
23
|
end
|
23
24
|
end
|
24
|
-
|
25
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
26
|
-
file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en1.xml.gz')
|
25
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
26
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en.xml.gz')
|
27
27
|
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
28
28
|
end
|
29
29
|
|
30
|
+
it "should not write out empty groups" do
|
31
|
+
linkset.create do
|
32
|
+
group(:filename => :sitemap_en) { }
|
33
|
+
end
|
34
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap_en.xml.gz')
|
35
|
+
end
|
36
|
+
|
30
37
|
it "should add default links if no groups are created" do
|
31
|
-
|
38
|
+
linkset.create do
|
32
39
|
end
|
33
|
-
|
34
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
35
|
-
|
40
|
+
linkset.link_count.should == 1
|
41
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
42
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
36
43
|
end
|
37
44
|
|
38
45
|
it "should add links to the default sitemap" do
|
39
|
-
|
46
|
+
linkset.create do
|
40
47
|
add '/before'
|
41
|
-
group(:filename => :sitemap_en)
|
48
|
+
group(:filename => :sitemap_en) do
|
49
|
+
add '/link'
|
50
|
+
end
|
42
51
|
add '/after'
|
43
52
|
end
|
44
|
-
|
45
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
53
|
+
linkset.link_count.should == 4
|
54
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
46
55
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
47
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
56
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en.xml.gz')
|
48
57
|
end
|
49
58
|
|
50
59
|
it "should rollover when sitemaps are full" do
|
51
60
|
with_max_links(1) {
|
52
|
-
|
53
|
-
|
54
|
-
|
61
|
+
linkset.include_index = false
|
62
|
+
linkset.include_root = false
|
63
|
+
linkset.create do
|
55
64
|
add '/before'
|
56
65
|
group(:filename => :sitemap_en, :sitemaps_path => 'en/') do
|
57
66
|
add '/one'
|
@@ -60,18 +69,18 @@ describe "Sitemap Groups" do
|
|
60
69
|
add '/after'
|
61
70
|
end
|
62
71
|
}
|
63
|
-
|
64
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
72
|
+
linkset.link_count.should == 4
|
73
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
65
74
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
66
75
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
|
67
76
|
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap3.xml.gz')
|
77
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en.xml.gz')
|
68
78
|
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en1.xml.gz')
|
69
|
-
|
70
|
-
file_should_not_exist(SitemapGenerator.app.root + 'public/en/sitemap_en3.xml.gz')
|
79
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/en/sitemap_en2.xml.gz')
|
71
80
|
end
|
72
81
|
|
73
82
|
it "should support multiple groups" do
|
74
|
-
|
83
|
+
linkset.create do
|
75
84
|
group(:filename => :sitemap_en, :sitemaps_path => 'en/') do
|
76
85
|
add '/one'
|
77
86
|
end
|
@@ -79,55 +88,57 @@ describe "Sitemap Groups" do
|
|
79
88
|
add '/one'
|
80
89
|
end
|
81
90
|
end
|
82
|
-
|
83
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
84
|
-
file_should_exist(SitemapGenerator.app.root + 'public/en/
|
85
|
-
file_should_exist(SitemapGenerator.app.root + 'public/fr/
|
91
|
+
linkset.link_count.should == 2
|
92
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
93
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en.xml.gz')
|
94
|
+
file_should_exist(SitemapGenerator.app.root + 'public/fr/sitemap_fr.xml.gz')
|
86
95
|
end
|
87
96
|
|
88
|
-
it "the sitemap shouldn't be finalized if the groups don't conflict" do
|
89
|
-
|
97
|
+
it "the sitemap shouldn't be finalized until the end if the groups don't conflict" do
|
98
|
+
linkset.create do
|
90
99
|
add 'one'
|
91
100
|
group(:filename => :first) { add '/two' }
|
92
101
|
add 'three'
|
93
102
|
group(:filename => :second) { add '/four' }
|
94
103
|
add 'five'
|
95
104
|
end
|
96
|
-
|
97
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
105
|
+
linkset.link_count.should == 6
|
106
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
98
107
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
99
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
100
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
108
|
+
file_should_exist(SitemapGenerator.app.root + 'public/first.xml.gz')
|
109
|
+
file_should_exist(SitemapGenerator.app.root + 'public/second.xml.gz')
|
110
|
+
gzipped_xml_file_should_validate_against_schema(SitemapGenerator.app.root + 'public/sitemap.xml.gz', 'siteindex')
|
111
|
+
gzipped_xml_file_should_validate_against_schema(SitemapGenerator.app.root + 'public/sitemap1.xml.gz', 'sitemap')
|
101
112
|
end
|
102
113
|
|
103
114
|
it "groups should share the sitemap if the sitemap location is unchanged" do
|
104
|
-
|
115
|
+
linkset.create do
|
105
116
|
add 'one'
|
106
117
|
group(:default_host => 'http://newhost.com') { add '/two' }
|
107
118
|
add 'three'
|
108
119
|
group(:default_host => 'http://betterhost.com') { add '/four' }
|
109
120
|
add 'five'
|
110
121
|
end
|
111
|
-
|
112
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
113
|
-
|
114
|
-
|
122
|
+
linkset.link_count.should == 6
|
123
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
124
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
125
|
+
gzipped_xml_file_should_validate_against_schema(SitemapGenerator.app.root + 'public/sitemap.xml.gz', 'sitemap')
|
115
126
|
end
|
116
127
|
|
117
128
|
it "sitemaps should be finalized if virtual location settings are changed" do
|
118
|
-
|
129
|
+
linkset.create do
|
119
130
|
add 'one'
|
120
131
|
group(:sitemaps_path => :en) { add '/two' }
|
121
132
|
add 'three'
|
122
133
|
group(:sitemaps_host => 'http://newhost.com') { add '/four' }
|
123
134
|
add 'five'
|
124
135
|
end
|
125
|
-
|
126
|
-
file_should_exist(SitemapGenerator.app.root + 'public/
|
136
|
+
linkset.link_count.should == 6
|
137
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
127
138
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
128
139
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
|
129
140
|
file_should_exist(SitemapGenerator.app.root + 'public/sitemap3.xml.gz')
|
130
141
|
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap4.xml.gz')
|
131
|
-
file_should_exist(SitemapGenerator.app.root + 'public/en/
|
142
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap.xml.gz')
|
132
143
|
end
|
133
144
|
end
|
@@ -1,72 +1,64 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SitemapGenerator::SitemapLocation do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
let(:default_host) { 'http://example.com' }
|
5
|
+
let(:location) { SitemapGenerator::SitemapLocation.new }
|
6
|
+
|
8
7
|
it "public_path should default to the public directory in the application root" do
|
9
|
-
|
10
|
-
@l.public_path.should == SitemapGenerator.app.root + 'public/'
|
8
|
+
location.public_path.should == SitemapGenerator.app.root + 'public/'
|
11
9
|
end
|
12
10
|
|
13
11
|
it "should have a default namer" do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@l.filename.should == 'sitemap1.xml.gz'
|
12
|
+
location[:namer].should_not be_nil
|
13
|
+
location[:filename].should be_nil
|
14
|
+
location.filename.should == 'sitemap1.xml.gz'
|
18
15
|
end
|
19
16
|
|
20
17
|
it "should require a filename" do
|
21
|
-
|
22
|
-
@l[:filename] = nil
|
18
|
+
location[:filename] = nil
|
23
19
|
lambda {
|
24
|
-
|
20
|
+
location.filename.should be_nil
|
25
21
|
}.should raise_error
|
26
22
|
end
|
27
23
|
|
28
24
|
it "should require a namer" do
|
29
|
-
|
30
|
-
@l[:namer] = nil
|
25
|
+
location[:namer] = nil
|
31
26
|
lambda {
|
32
|
-
|
27
|
+
location.filename.should be_nil
|
33
28
|
}.should raise_error
|
34
29
|
end
|
35
|
-
|
30
|
+
|
36
31
|
it "should require a host" do
|
37
|
-
|
32
|
+
location = SitemapGenerator::SitemapLocation.new(:filename => nil, :namer => nil)
|
38
33
|
lambda {
|
39
|
-
|
34
|
+
location.host.should be_nil
|
40
35
|
}.should raise_error
|
41
36
|
end
|
42
37
|
|
43
38
|
it "should accept a Namer option" do
|
44
39
|
@namer = SitemapGenerator::SitemapNamer.new(:xxx)
|
45
|
-
|
46
|
-
|
40
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => @namer)
|
41
|
+
location.filename.should == @namer.to_s
|
47
42
|
end
|
48
43
|
|
49
44
|
it "should protect the filename from further changes in the Namer" do
|
50
45
|
@namer = SitemapGenerator::SitemapNamer.new(:xxx)
|
51
|
-
|
52
|
-
|
46
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => @namer)
|
47
|
+
location.filename.should == @namer.to_s
|
53
48
|
@namer.next
|
54
|
-
|
49
|
+
location.filename.should == @namer.previous.to_s
|
55
50
|
end
|
56
51
|
|
57
52
|
it "should allow changing the namer" do
|
58
53
|
@namer1 = SitemapGenerator::SitemapNamer.new(:xxx)
|
59
|
-
|
60
|
-
|
54
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => @namer1)
|
55
|
+
location.filename.should == @namer1.to_s
|
61
56
|
@namer2 = SitemapGenerator::SitemapNamer.new(:yyy)
|
62
|
-
|
63
|
-
|
57
|
+
location[:namer] = @namer2
|
58
|
+
location.filename.should == @namer2.to_s
|
64
59
|
end
|
65
60
|
|
66
61
|
describe "testing options and #with" do
|
67
|
-
before :all do
|
68
|
-
@l = SitemapGenerator::SitemapLocation.new
|
69
|
-
end
|
70
62
|
|
71
63
|
# Array of tuples with instance options and expected method return values
|
72
64
|
tests = [
|
@@ -94,7 +86,7 @@ describe SitemapGenerator::SitemapLocation do
|
|
94
86
|
tests.each do |opts, returns|
|
95
87
|
returns.each do |method, value|
|
96
88
|
it "#{method} should return #{value}" do
|
97
|
-
|
89
|
+
location.with(opts).send(method).should == value
|
98
90
|
end
|
99
91
|
end
|
100
92
|
end
|
@@ -102,23 +94,33 @@ describe SitemapGenerator::SitemapLocation do
|
|
102
94
|
|
103
95
|
describe "when duplicated" do
|
104
96
|
it "should not inherit some objects" do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
dup =
|
109
|
-
dup.url.should ==
|
110
|
-
dup.url.should_not be(
|
111
|
-
dup.public_path.to_s.should ==
|
112
|
-
dup.public_path.should_not be(
|
97
|
+
location = SitemapGenerator::SitemapLocation.new(:filename => 'xxx', :host => default_host, :public_path => 'public/')
|
98
|
+
location.url.should == default_host+'/xxx'
|
99
|
+
location.public_path.to_s.should == 'public/'
|
100
|
+
dup = location.dup
|
101
|
+
dup.url.should == location.url
|
102
|
+
dup.url.should_not be(location.url)
|
103
|
+
dup.public_path.to_s.should == location.public_path.to_s
|
104
|
+
dup.public_path.should_not be(location.public_path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "filesize" do
|
109
|
+
it "should read the size of the file at path" do
|
110
|
+
location.expects(:path).returns('/somepath')
|
111
|
+
File.expects(:size?).with('/somepath')
|
112
|
+
location.filesize
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
describe SitemapGenerator::SitemapIndexLocation do
|
118
|
+
let(:location) { SitemapGenerator::SitemapIndexLocation.new }
|
119
|
+
|
118
120
|
it "should have a default namer" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
location = SitemapGenerator::SitemapIndexLocation.new
|
122
|
+
location[:namer].should_not be_nil
|
123
|
+
location[:filename].should be_nil
|
124
|
+
location.filename.should == 'sitemap.xml.gz'
|
123
125
|
end
|
124
126
|
end
|
@@ -66,6 +66,7 @@ describe SitemapGenerator::SitemapIndexNamer do
|
|
66
66
|
namer.to_s.should == default
|
67
67
|
namer.next.to_s.should == default
|
68
68
|
namer.previous.to_s.should == default
|
69
|
+
SitemapGenerator::SitemapIndexNamer.new(:sitemap).to_s.should == 'sitemap.xml.gz'
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
@@ -148,5 +149,18 @@ describe SitemapGenerator::SimpleNamer do
|
|
148
149
|
namer.to_s.should == "sitemap_index.xml.gz"
|
149
150
|
namer.next.to_s.should == "sitemap1.xml.gz"
|
150
151
|
end
|
152
|
+
|
153
|
+
it "as a symbol" do
|
154
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => :index)
|
155
|
+
namer.to_s.should == "sitemapindex.xml.gz"
|
156
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "with a starting index" do
|
160
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => 'abc', :start => 10)
|
161
|
+
namer.to_s.should == "sitemapabc.xml.gz"
|
162
|
+
namer.next.to_s.should == "sitemap10.xml.gz"
|
163
|
+
namer.next.to_s.should == "sitemap11.xml.gz"
|
164
|
+
end
|
151
165
|
end
|
152
166
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitemap_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
5
|
-
prerelease:
|
4
|
+
version: '4.0'
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Karl Varga
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-05-02 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mocha
|
17
|
-
requirement: &
|
17
|
+
requirement: &70315214520780 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70315214520780
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: nokogiri
|
28
|
-
requirement: &
|
28
|
+
requirement: &70315214520340 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70315214520340
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70315214519920 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70315214519920
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: builder
|
50
|
-
requirement: &
|
50
|
+
requirement: &70315214519500 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70315214519500
|
59
59
|
description: SitemapGenerator is an XML Sitemap generator written in Ruby with automatic
|
60
60
|
Rails integration. It supports Video, News, Image and Geo sitemaps and includes
|
61
61
|
Rake tasks for managing your sitemaps.
|
@@ -148,13 +148,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash:
|
151
|
+
hash: -1068224574561597238
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
none: false
|
154
154
|
requirements:
|
155
|
-
- - ! '
|
155
|
+
- - ! '>='
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
157
|
+
version: '0'
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
hash: -1068224574561597238
|
158
161
|
requirements: []
|
159
162
|
rubyforge_project:
|
160
163
|
rubygems_version: 1.8.10
|