sitemap_generator 3.4 → 4.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/sitemap_generator/builder.rb +4 -0
- data/lib/sitemap_generator/builder/sitemap_file.rb +46 -14
- data/lib/sitemap_generator/builder/sitemap_index_file.rb +62 -1
- data/lib/sitemap_generator/link_set.rb +10 -8
- data/lib/sitemap_generator/sitemap_location.rb +31 -1
- data/lib/sitemap_generator/sitemap_namer.rb +64 -1
- data/spec/sitemap_generator/builder/sitemap_file_spec.rb +8 -6
- data/spec/sitemap_generator/link_set_spec.rb +8 -10
- data/spec/sitemap_generator/sitemap_namer_spec.rb +91 -0
- metadata +14 -17
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4.0.alpha
|
@@ -2,3 +2,7 @@ require 'sitemap_generator/builder/sitemap_file'
|
|
2
2
|
require 'sitemap_generator/builder/sitemap_index_file'
|
3
3
|
require 'sitemap_generator/builder/sitemap_url'
|
4
4
|
require 'sitemap_generator/builder/sitemap_index_url'
|
5
|
+
|
6
|
+
module SitemapGenerator::Builder
|
7
|
+
LinkHolder = Struct.new(:link, :options)
|
8
|
+
end
|
@@ -42,10 +42,19 @@ module SitemapGenerator
|
|
42
42
|
@xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
|
43
43
|
@xml_wrapper_end = %q[</urlset>]
|
44
44
|
@filesize = bytesize(@xml_wrapper_start) + bytesize(@xml_wrapper_end)
|
45
|
+
@written = false
|
46
|
+
@reserved_name = nil # holds the name reserved from the namer
|
47
|
+
@frozen = false # rather than actually freeze, use this boolean
|
45
48
|
end
|
46
49
|
|
50
|
+
# If a name has been reserved, use the last modified time from the file.
|
51
|
+
# Otherwise return nil. We don't want to prematurely assign a name
|
52
|
+
# for this sitemap if one has not yet been reserved, because we may
|
53
|
+
# mess up the name-assignment sequence.
|
47
54
|
def lastmod
|
48
|
-
File.mtime(location.path)
|
55
|
+
File.mtime(location.path) if location.reserved_name?
|
56
|
+
rescue
|
57
|
+
nil
|
49
58
|
end
|
50
59
|
|
51
60
|
def empty?
|
@@ -102,31 +111,54 @@ module SitemapGenerator
|
|
102
111
|
@link_count += 1
|
103
112
|
end
|
104
113
|
|
105
|
-
#
|
106
|
-
#
|
107
|
-
# All the xml content in the instance is cleared, but attributes like
|
108
|
-
# <tt>filesize</tt> are still available.
|
114
|
+
# "Freeze" this object. Actually just flags it as frozen.
|
109
115
|
#
|
110
116
|
# A SitemapGenerator::SitemapFinalizedError exception is raised if the Sitemap
|
111
|
-
# has already been finalized
|
117
|
+
# has already been finalized.
|
112
118
|
def finalize!
|
113
119
|
raise SitemapGenerator::SitemapFinalizedError if finalized?
|
120
|
+
@frozen = true
|
121
|
+
end
|
114
122
|
|
123
|
+
def finalized?
|
124
|
+
@frozen
|
125
|
+
end
|
126
|
+
|
127
|
+
# Write out the sitemap and free up memory.
|
128
|
+
#
|
129
|
+
# All the xml content in the instance is cleared, but attributes like
|
130
|
+
# <tt>filesize</tt> are still available.
|
131
|
+
#
|
132
|
+
# A SitemapGenerator::SitemapError exception is raised if the file has
|
133
|
+
# already been written.
|
134
|
+
def write
|
135
|
+
raise SitemapGenerator::SitemapError.new("Sitemap already written!") if written?
|
136
|
+
finalize! unless finalized?
|
137
|
+
reserve_name
|
115
138
|
@location.write(@xml_wrapper_start + @xml_content + @xml_wrapper_end)
|
139
|
+
@xml_content = @xml_wrapper_start = @xml_wrapper_end = ''
|
140
|
+
puts summary if @location.verbose?
|
141
|
+
@written = true
|
142
|
+
end
|
116
143
|
|
117
|
-
|
118
|
-
|
144
|
+
# Return true if this file has been written out to disk
|
145
|
+
def written?
|
146
|
+
@written
|
147
|
+
end
|
119
148
|
|
120
|
-
|
121
|
-
|
122
|
-
|
149
|
+
# Reserve a name from the namer unless one has already been reserved.
|
150
|
+
# Safe to call more than once.
|
151
|
+
def reserve_name
|
152
|
+
@reserved_name ||= @location.reserve_name
|
123
153
|
end
|
124
154
|
|
125
|
-
|
126
|
-
|
155
|
+
# Return a boolean indicating whether a name has been reserved
|
156
|
+
def reserved_name?
|
157
|
+
!!@reserved_name
|
127
158
|
end
|
128
159
|
|
129
|
-
# Return a new instance of the sitemap file with the same options,
|
160
|
+
# Return a new instance of the sitemap file with the same options,
|
161
|
+
# and the next name in the sequence.
|
130
162
|
def new
|
131
163
|
location = @location.dup
|
132
164
|
location.delete(:filename) if location.namer
|
@@ -23,15 +23,47 @@ module SitemapGenerator
|
|
23
23
|
@xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
|
24
24
|
@xml_wrapper_end = %q[</sitemapindex>]
|
25
25
|
@filesize = bytesize(@xml_wrapper_start) + bytesize(@xml_wrapper_end)
|
26
|
+
@written = false
|
27
|
+
@reserved_name = nil # holds the name reserved from the namer
|
28
|
+
@frozen = false # rather than actually freeze, use this boolean
|
29
|
+
@first_sitemap = nil # reference to the first thing added to this index
|
26
30
|
end
|
27
31
|
|
28
32
|
# Finalize sitemaps as they are added to the index.
|
33
|
+
# If it's the first sitemap, finalize it but don't
|
34
|
+
# write it out, because we don't yet know if we need an index. If it's
|
35
|
+
# the second sitemap, we know we need an index, so reserve a name for the
|
36
|
+
# index, and go and write out the first sitemap. If it's the third or
|
37
|
+
# greater sitemap, just finalize and write it out as usual, nothing more
|
38
|
+
# needs to be done.
|
39
|
+
alias_method :super_add, :add
|
29
40
|
def add(link, options={})
|
30
41
|
if file = link.is_a?(SitemapFile) && link
|
31
42
|
@sitemaps_link_count += file.link_count
|
32
43
|
file.finalize! unless file.finalized?
|
44
|
+
|
45
|
+
# First link. If it's a SitemapFile store a reference to it and the options
|
46
|
+
# so that we can create a URL from it later. We can't create the URL yet
|
47
|
+
# because doing so fixes the sitemap file's name, and we have to wait to see
|
48
|
+
# if we have more than one link in the index before we can know who gets the
|
49
|
+
# first name (the index, or the sitemap). If the item is not a SitemapFile,
|
50
|
+
# then it has been manually added and we can be sure that the user intends
|
51
|
+
# for there to be an index.
|
52
|
+
if @link_count == 0
|
53
|
+
@first_sitemap = SitemapGenerator::Builder::LinkHolder.new(file, options)
|
54
|
+
@link_count += 1 # pretend it's added
|
55
|
+
elsif @link_count == 1 # adding second link, need an index so reserve names & write out first sitemap
|
56
|
+
reserve_name unless @location.create_index == false # index gets first name
|
57
|
+
write_first_sitemap
|
58
|
+
file.write
|
59
|
+
super(SitemapGenerator::Builder::SitemapIndexUrl.new(file, options))
|
60
|
+
else
|
61
|
+
file.write
|
62
|
+
super(SitemapGenerator::Builder::SitemapIndexUrl.new(file, options))
|
63
|
+
end
|
64
|
+
else
|
65
|
+
super(SitemapGenerator::Builder::SitemapIndexUrl.new(link, options))
|
33
66
|
end
|
34
|
-
super(SitemapGenerator::Builder::SitemapIndexUrl.new(link, options))
|
35
67
|
end
|
36
68
|
|
37
69
|
# Return a boolean indicating whether the sitemap file can fit another link
|
@@ -59,6 +91,35 @@ module SitemapGenerator
|
|
59
91
|
str = "Sitemap stats: #{number_with_delimiter(@sitemaps_link_count)} links / #{@link_count} sitemaps"
|
60
92
|
str += " / %dm%02ds" % opts[:time_taken].divmod(60) if opts[:time_taken]
|
61
93
|
end
|
94
|
+
|
95
|
+
def finalize!
|
96
|
+
raise SitemapGenerator::SitemapFinalizedError if finalized?
|
97
|
+
reserve_name if create_index?
|
98
|
+
write_first_sitemap
|
99
|
+
@frozen = true
|
100
|
+
end
|
101
|
+
|
102
|
+
# Write out the index if an index is needed
|
103
|
+
def write
|
104
|
+
super if create_index?
|
105
|
+
end
|
106
|
+
|
107
|
+
# Whether or not we need to create an index file.
|
108
|
+
def create_index?
|
109
|
+
@location.create_index == true || @location.create_index == :auto && @link_count > 1
|
110
|
+
end
|
111
|
+
|
112
|
+
protected
|
113
|
+
|
114
|
+
# Make sure the first sitemap has been written out and added to the index
|
115
|
+
def write_first_sitemap
|
116
|
+
if @first_sitemap
|
117
|
+
@first_sitemap.link.write unless @first_sitemap.link.written?
|
118
|
+
super_add(SitemapGenerator::Builder::SitemapIndexUrl.new(@first_sitemap.link, @first_sitemap.options))
|
119
|
+
@link_count -= 1 # we already counted it, don't count it twice
|
120
|
+
@first_sitemap = nil
|
121
|
+
end
|
122
|
+
end
|
62
123
|
end
|
63
124
|
end
|
64
125
|
end
|
@@ -297,6 +297,7 @@ module SitemapGenerator
|
|
297
297
|
sitemap_index.location.url
|
298
298
|
end
|
299
299
|
|
300
|
+
# All done. Write out remaining files.
|
300
301
|
def finalize!
|
301
302
|
finalize_sitemap!
|
302
303
|
finalize_sitemap_index!
|
@@ -417,19 +418,17 @@ module SitemapGenerator
|
|
417
418
|
add_default_links if !@added_default_links && !@created_group
|
418
419
|
# This will finalize it. We add to the index even if not creating an index because
|
419
420
|
# the index keeps track of how many links are in our sitemaps and we need this info
|
420
|
-
# for the summary line.
|
421
|
-
#
|
421
|
+
# for the summary line. Also the index determines which file gets the first name
|
422
|
+
# so everything has to go via the index.
|
422
423
|
add_to_index(sitemap)
|
423
|
-
output(sitemap.summary)
|
424
424
|
end
|
425
425
|
|
426
426
|
# Finalize a sitemap index and output a summary line. Do nothing if it has already
|
427
427
|
# been finalized.
|
428
428
|
def finalize_sitemap_index!
|
429
|
-
return if @protect_index ||
|
430
|
-
return if @create_index == :auto && sitemap_index.link_count <= 1
|
429
|
+
return if @protect_index || sitemap_index.finalized?
|
431
430
|
sitemap_index.finalize!
|
432
|
-
|
431
|
+
sitemap_index.write
|
433
432
|
end
|
434
433
|
|
435
434
|
# Return the interpreter linked to this instance.
|
@@ -559,7 +558,8 @@ module SitemapGenerator
|
|
559
558
|
:namer => sitemaps_namer,
|
560
559
|
:public_path => public_path,
|
561
560
|
:sitemaps_path => @sitemaps_path,
|
562
|
-
:adapter => @adapter
|
561
|
+
:adapter => @adapter,
|
562
|
+
:verbose => verbose
|
563
563
|
)
|
564
564
|
end
|
565
565
|
|
@@ -570,7 +570,9 @@ module SitemapGenerator
|
|
570
570
|
:namer => sitemap_index_namer,
|
571
571
|
:public_path => public_path,
|
572
572
|
:sitemaps_path => @sitemaps_path,
|
573
|
-
:adapter => @adapter
|
573
|
+
:adapter => @adapter,
|
574
|
+
:verbose => verbose,
|
575
|
+
:create_index => @create_index
|
574
576
|
)
|
575
577
|
end
|
576
578
|
|
@@ -29,11 +29,15 @@ module SitemapGenerator
|
|
29
29
|
# directory if running under Rails.
|
30
30
|
# * <tt>sitemaps_path</tt> - gives the path relative to the <tt>public_path</tt> in which to
|
31
31
|
# write sitemaps e.g. <tt>sitemaps/</tt>.
|
32
|
+
# * <tt>verbose</tt> - whether to output summary into to STDOUT. Default +false+.
|
33
|
+
# * <tt>create_index</tt> - whether to create a sitemap index. Default +true+. See LinkSet.
|
34
|
+
# Only applies to the SitemapIndexLocation object.
|
32
35
|
def initialize(opts={})
|
33
|
-
SitemapGenerator::Utilities.assert_valid_keys(opts, [:adapter, :public_path, :sitemaps_path, :host, :filename, :namer])
|
36
|
+
SitemapGenerator::Utilities.assert_valid_keys(opts, [:adapter, :public_path, :sitemaps_path, :host, :filename, :namer, :verbose, :create_index])
|
34
37
|
opts[:adapter] ||= SitemapGenerator::FileAdapter.new
|
35
38
|
opts[:public_path] ||= SitemapGenerator.app.root + 'public/'
|
36
39
|
opts[:namer] = SitemapGenerator::SitemapNamer.new(:sitemap) if !opts[:filename] && !opts[:namer]
|
40
|
+
opts[:verbose] = !!opts[:verbose]
|
37
41
|
self.merge!(opts)
|
38
42
|
end
|
39
43
|
|
@@ -78,10 +82,30 @@ module SitemapGenerator
|
|
78
82
|
self[:filename]
|
79
83
|
end
|
80
84
|
|
85
|
+
# If a namer is set, reserve the filename and increment the namer.
|
86
|
+
# Returns the reserved name.
|
87
|
+
def reserve_name
|
88
|
+
if self[:namer]
|
89
|
+
filename
|
90
|
+
self[:namer].next
|
91
|
+
end
|
92
|
+
self[:filename]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Return true if this location has a fixed filename. If no name has been
|
96
|
+
# reserved from the namer, for instance, returns false.
|
97
|
+
def reserved_name?
|
98
|
+
!!self[:filename]
|
99
|
+
end
|
100
|
+
|
81
101
|
def namer
|
82
102
|
self[:namer]
|
83
103
|
end
|
84
104
|
|
105
|
+
def verbose?
|
106
|
+
self[:verbose]
|
107
|
+
end
|
108
|
+
|
85
109
|
# If you set the filename, clear the namer and vice versa.
|
86
110
|
def []=(key, value, opts={})
|
87
111
|
if !opts[:super]
|
@@ -107,5 +131,11 @@ module SitemapGenerator
|
|
107
131
|
end
|
108
132
|
super(opts)
|
109
133
|
end
|
134
|
+
|
135
|
+
# Really just a placeholder for an option which should really go into some
|
136
|
+
# kind of options class.
|
137
|
+
def create_index
|
138
|
+
self[:create_index]
|
139
|
+
end
|
110
140
|
end
|
111
141
|
end
|
@@ -13,7 +13,7 @@ module SitemapGenerator
|
|
13
13
|
#
|
14
14
|
# Options include:
|
15
15
|
# :extension - Default: '.xml.gz'. File extension to append.
|
16
|
-
# :start - Default: 1.
|
16
|
+
# :start - Default: 1. Numerical index at which to start counting.
|
17
17
|
def initialize(base, options={});
|
18
18
|
@options = SitemapGenerator::Utilities.reverse_merge(options,
|
19
19
|
:extension => '.xml.gz',
|
@@ -56,4 +56,67 @@ module SitemapGenerator
|
|
56
56
|
"#{@base}#{@options[:extension]}"
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
# The SimpleNamer uses the same namer instance for the sitemap index and the sitemaps.
|
61
|
+
# If no index is needed, the first sitemap gets the first name. However, if
|
62
|
+
# an index is needed, the index gets the first name.
|
63
|
+
#
|
64
|
+
# A typical sequence would looks like this:
|
65
|
+
# * sitemap.xml.gz
|
66
|
+
# * sitemap1.xml.gz
|
67
|
+
# * sitemap2.xml.gz
|
68
|
+
# * sitemap3.xml.gz
|
69
|
+
# * ...
|
70
|
+
#
|
71
|
+
# Options:
|
72
|
+
# :extension - Default: '.xml.gz'. File extension to append.
|
73
|
+
# :start - Default: 1. Numerical index at which to start counting.
|
74
|
+
# :zero - Default: nil. Could be a string or number that gives part
|
75
|
+
# of the first name in the sequence. So in the old naming scheme
|
76
|
+
# setting this to '_index' would produce 'sitemap_index.xml.gz' as
|
77
|
+
# the first name. Thereafter, the numerical index defined by +start+
|
78
|
+
# is used.
|
79
|
+
class SimpleNamer < SitemapNamer
|
80
|
+
def initialize(base, options={})
|
81
|
+
super_options = SitemapGenerator::Utilities.reverse_merge(options,
|
82
|
+
:zero => nil # identifies the marker for the start of the series
|
83
|
+
)
|
84
|
+
super(base, super_options)
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_s
|
88
|
+
"#{@base}#{@count}#{@options[:extension]}"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Reset to the first name
|
92
|
+
def reset
|
93
|
+
@count = @options[:zero]
|
94
|
+
end
|
95
|
+
|
96
|
+
# True if on the first name
|
97
|
+
def start?
|
98
|
+
@count == @options[:zero]
|
99
|
+
end
|
100
|
+
|
101
|
+
# Return this instance set to the next name
|
102
|
+
def next
|
103
|
+
if start?
|
104
|
+
@count = @options[:start]
|
105
|
+
else
|
106
|
+
@count += 1
|
107
|
+
end
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
# Return this instance set to the previous name
|
112
|
+
def previous
|
113
|
+
raise NameError, "Already at the start of the series" if start?
|
114
|
+
if @count <= @options[:start]
|
115
|
+
@count = @options[:zero]
|
116
|
+
else
|
117
|
+
@count -= 1
|
118
|
+
end
|
119
|
+
self
|
120
|
+
end
|
121
|
+
end
|
59
122
|
end
|
@@ -32,11 +32,6 @@ describe 'SitemapGenerator::Builder::SitemapFile' do
|
|
32
32
|
@s.finalized?.should be_false
|
33
33
|
end
|
34
34
|
|
35
|
-
it "should increment the namer after finalizing" do
|
36
|
-
@s.finalize!
|
37
|
-
@s.location.filename.should_not == @s.location.namer.to_s
|
38
|
-
end
|
39
|
-
|
40
35
|
it "should raise if no default host is set" do
|
41
36
|
lambda { SitemapGenerator::Builder::SitemapFile.new.location.url }.should raise_error(SitemapGenerator::SitemapError)
|
42
37
|
end
|
@@ -44,11 +39,18 @@ describe 'SitemapGenerator::Builder::SitemapFile' do
|
|
44
39
|
describe "lastmod" do
|
45
40
|
it "should be the file last modified time" do
|
46
41
|
lastmod = (Time.now - 1209600)
|
42
|
+
@s.location.reserve_name
|
47
43
|
File.expects(:mtime).with(@s.location.path).returns(lastmod)
|
48
44
|
@s.lastmod.should == lastmod
|
49
45
|
end
|
50
46
|
|
51
|
-
it "should be nil if the
|
47
|
+
it "should be nil if the location has not reserved a name" do
|
48
|
+
File.expects(:mtime).never
|
49
|
+
@s.lastmod.should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be nil if location has reserved a name and the file DNE" do
|
53
|
+
@s.location.reserve_name
|
52
54
|
File.expects(:mtime).raises(Errno::ENOENT)
|
53
55
|
@s.lastmod.should be_nil
|
54
56
|
end
|
@@ -190,9 +190,7 @@ describe SitemapGenerator::LinkSet do
|
|
190
190
|
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true) }
|
191
191
|
|
192
192
|
it "should output summary lines" do
|
193
|
-
ls.sitemap.expects(:finalize!)
|
194
193
|
ls.sitemap.expects(:summary)
|
195
|
-
ls.sitemap_index.expects(:finalize!)
|
196
194
|
ls.sitemap_index.expects(:summary)
|
197
195
|
ls.finalize!
|
198
196
|
end
|
@@ -725,9 +723,9 @@ describe SitemapGenerator::LinkSet do
|
|
725
723
|
describe "when false" do
|
726
724
|
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => false) }
|
727
725
|
|
728
|
-
it "should not
|
726
|
+
it "should not write the index" do
|
729
727
|
ls.send(:finalize_sitemap_index!)
|
730
|
-
ls.sitemap_index.
|
728
|
+
ls.sitemap_index.written?.should be_false
|
731
729
|
end
|
732
730
|
|
733
731
|
it "should still add finalized sitemaps to the index (but the index is never finalized)" do
|
@@ -753,10 +751,10 @@ describe SitemapGenerator::LinkSet do
|
|
753
751
|
describe "when :auto" do
|
754
752
|
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => :auto) }
|
755
753
|
|
756
|
-
it "should not
|
754
|
+
it "should not write the index when it is empty" do
|
757
755
|
ls.sitemap_index.empty?.should be_true
|
758
756
|
ls.send(:finalize_sitemap_index!)
|
759
|
-
ls.sitemap_index.
|
757
|
+
ls.sitemap_index.written?.should be_false
|
760
758
|
end
|
761
759
|
|
762
760
|
it "should add finalized sitemaps to the index" do
|
@@ -764,18 +762,18 @@ describe SitemapGenerator::LinkSet do
|
|
764
762
|
ls.send(:finalize_sitemap!)
|
765
763
|
end
|
766
764
|
|
767
|
-
it "should not
|
765
|
+
it "should not write the index when it has only one link" do
|
768
766
|
ls.sitemap_index.add '/test', :host => default_host
|
769
767
|
ls.sitemap_index.empty?.should be_false
|
770
768
|
ls.send(:finalize_sitemap_index!)
|
771
|
-
ls.sitemap_index.
|
769
|
+
ls.sitemap_index.written?.should be_false
|
772
770
|
end
|
773
771
|
|
774
|
-
it "should
|
772
|
+
it "should write the index when it has more than one link" do
|
775
773
|
ls.sitemap_index.add '/test1', :host => default_host
|
776
774
|
ls.sitemap_index.add '/test2', :host => default_host
|
777
775
|
ls.send(:finalize_sitemap_index!)
|
778
|
-
ls.sitemap_index.
|
776
|
+
ls.sitemap_index.written?.should be_true
|
779
777
|
end
|
780
778
|
end
|
781
779
|
end
|
@@ -48,6 +48,15 @@ describe 'SitemapGenerator::SitemapNamer' do
|
|
48
48
|
namer = SitemapGenerator::SitemapNamer.new("sitemap1_")
|
49
49
|
namer.to_s.should == "sitemap1_1.xml.gz"
|
50
50
|
end
|
51
|
+
|
52
|
+
it "should reset the namer" do
|
53
|
+
namer = SitemapGenerator::SitemapNamer.new(:sitemap)
|
54
|
+
namer.to_s.should == "sitemap1.xml.gz"
|
55
|
+
namer.next.to_s.should == "sitemap2.xml.gz"
|
56
|
+
namer.reset
|
57
|
+
namer.to_s.should == "sitemap1.xml.gz"
|
58
|
+
namer.next.to_s.should == "sitemap2.xml.gz"
|
59
|
+
end
|
51
60
|
end
|
52
61
|
|
53
62
|
describe SitemapGenerator::SitemapIndexNamer do
|
@@ -59,3 +68,85 @@ describe SitemapGenerator::SitemapIndexNamer do
|
|
59
68
|
namer.previous.to_s.should == default
|
60
69
|
end
|
61
70
|
end
|
71
|
+
|
72
|
+
describe SitemapGenerator::SimpleNamer do
|
73
|
+
it "should generate file names" do
|
74
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
75
|
+
namer.to_s.should == "sitemap.xml.gz"
|
76
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
77
|
+
namer.next.to_s.should == "sitemap2.xml.gz"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set the file extension" do
|
81
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :extension => '.xyz')
|
82
|
+
namer.to_s.should == "sitemap.xyz"
|
83
|
+
namer.next.to_s.should == "sitemap1.xyz"
|
84
|
+
namer.next.to_s.should == "sitemap2.xyz"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should set the starting index" do
|
88
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :start => 10)
|
89
|
+
namer.to_s.should == "sitemap.xml.gz"
|
90
|
+
namer.next.to_s.should == "sitemap10.xml.gz"
|
91
|
+
namer.next.to_s.should == "sitemap11.xml.gz"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should accept a string name" do
|
95
|
+
namer = SitemapGenerator::SimpleNamer.new('abc-def')
|
96
|
+
namer.to_s.should == "abc-def.xml.gz"
|
97
|
+
namer.next.to_s.should == "abc-def1.xml.gz"
|
98
|
+
namer.next.to_s.should == "abc-def2.xml.gz"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return previous name" do
|
102
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
103
|
+
namer.to_s.should == "sitemap.xml.gz"
|
104
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
105
|
+
namer.previous.to_s.should == "sitemap.xml.gz"
|
106
|
+
namer.next.next.to_s.should == "sitemap2.xml.gz"
|
107
|
+
namer.previous.to_s.should == "sitemap1.xml.gz"
|
108
|
+
namer.next.next.to_s.should == "sitemap3.xml.gz"
|
109
|
+
namer.previous.to_s.should == "sitemap2.xml.gz"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should raise if already at the start" do
|
113
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
114
|
+
namer.to_s.should == "sitemap.xml.gz"
|
115
|
+
lambda { namer.previous }.should raise_error
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should handle names with underscores" do
|
119
|
+
namer = SitemapGenerator::SimpleNamer.new("sitemap1_")
|
120
|
+
namer.to_s.should == "sitemap1_.xml.gz"
|
121
|
+
namer.next.to_s.should == "sitemap1_1.xml.gz"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should reset the namer" do
|
125
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
126
|
+
namer.to_s.should == "sitemap.xml.gz"
|
127
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
128
|
+
namer.reset
|
129
|
+
namer.to_s.should == "sitemap.xml.gz"
|
130
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "should handle the zero option" do
|
134
|
+
it "as a string" do
|
135
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => "string")
|
136
|
+
namer.to_s.should == "sitemapstring.xml.gz"
|
137
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "as an integer" do
|
141
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => 0)
|
142
|
+
namer.to_s.should == "sitemap0.xml.gz"
|
143
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "as a string" do
|
147
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => "_index")
|
148
|
+
namer.to_s.should == "sitemap_index.xml.gz"
|
149
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
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:
|
5
|
-
prerelease:
|
4
|
+
version: 4.0.alpha
|
5
|
+
prerelease: 4
|
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: 2012-10-
|
13
|
+
date: 2012-10-16 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mocha
|
17
|
-
requirement: &
|
17
|
+
requirement: &70243003001900 !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: *70243003001900
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: nokogiri
|
28
|
-
requirement: &
|
28
|
+
requirement: &70243003001480 !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: *70243003001480
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70243003001060 !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: *70243003001060
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: builder
|
50
|
-
requirement: &
|
50
|
+
requirement: &70243003000640 !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: *70243003000640
|
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,16 +148,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash:
|
151
|
+
hash: 1078666966814794365
|
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:
|
158
|
-
segments:
|
159
|
-
- 0
|
160
|
-
hash: -4570809208005834438
|
157
|
+
version: 1.3.1
|
161
158
|
requirements: []
|
162
159
|
rubyforge_project:
|
163
160
|
rubygems_version: 1.8.10
|