massive_sitemap 2.0.0.rc4 → 2.0.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -1
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/lib/massive_sitemap/builder/base.rb +21 -14
- data/lib/massive_sitemap/builder/index.rb +4 -2
- data/lib/massive_sitemap/builder/rotating.rb +1 -25
- data/lib/massive_sitemap/writer/base.rb +28 -15
- data/lib/massive_sitemap/writer/file.rb +31 -11
- data/lib/massive_sitemap/writer/gzip_file.rb +0 -4
- data/lib/massive_sitemap.rb +2 -2
- data/spec/builder/base_spec.rb +16 -25
- data/spec/builder/index_spec.rb +1 -1
- data/spec/builder/rotating_spec.rb +7 -69
- data/spec/lock_spec.rb +1 -1
- data/spec/massive_sitemap_spec.rb +16 -14
- data/spec/writer/base_spec.rb +13 -0
- data/spec/writer/file_spec.rb +70 -5
- data/spec/writer/gzip_file_spec.rb +10 -8
- metadata +8 -6
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
* updated Docu
|
8
8
|
* switch to writer chain
|
9
9
|
* add BigSitemap API
|
10
|
-
*
|
10
|
+
* support nested writing
|
11
11
|
|
12
12
|
## v2.0.0 - 13-02-2012
|
13
13
|
_inital release_
|
@@ -28,3 +28,5 @@
|
|
28
28
|
* moved Amazon S3 integration to [massive_sitemap-writer-s3](https://github.com/rngtng/massive_sitemap-writer-s3)
|
29
29
|
* updated/fixed Ping
|
30
30
|
* move LockingFile into MassiveSitemap scope
|
31
|
+
* FileManifest -> read all files into streams take that as reference
|
32
|
+
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.
|
1
|
+
2.0.0.rc5
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# MassiveSitemap Builder
|
2
|
+
# The purpose of a builder is create the XML files: continaing header and all other tag (with attributes).
|
3
|
+
#
|
1
4
|
module MassiveSitemap
|
2
5
|
module Builder
|
3
6
|
|
@@ -19,29 +22,29 @@ module MassiveSitemap
|
|
19
22
|
@options = self.class::OPTS.merge(options)
|
20
23
|
@opened_tags = []
|
21
24
|
|
22
|
-
|
23
|
-
instance_eval(&block)
|
24
|
-
close!
|
25
|
-
end
|
25
|
+
process(&block)
|
26
26
|
end
|
27
27
|
|
28
|
+
# alias for .new
|
28
29
|
def self.generate(writer, options = {}, &block)
|
29
30
|
self.new(writer, options, &block)
|
30
31
|
end
|
31
32
|
|
33
|
+
# add url, prefix with given base_url
|
32
34
|
def add(path, attrs = {})
|
33
35
|
add_url! ::File.join(url, path), attrs
|
34
|
-
rescue MassiveSitemap::Writer::File::FileExistsException => e
|
35
|
-
# don't fail here
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
# implicitly called by add_url!, call explicitly to check if writer can be used
|
39
|
+
def init_writer!(writer_options = {}, &block)
|
39
40
|
unless @writer.inited?
|
40
|
-
@writer.init!
|
41
|
-
header!
|
41
|
+
@writer.init!(writer_options)
|
42
|
+
header!
|
42
43
|
end
|
44
|
+
process(&block)
|
43
45
|
end
|
44
46
|
|
47
|
+
# close a tag, if last one, close writer too
|
45
48
|
def close!(indent = true)
|
46
49
|
if name = @opened_tags.pop
|
47
50
|
@writer.print "\n" + ' ' * @options[:indent_by] * @opened_tags.size if indent
|
@@ -60,7 +63,7 @@ module MassiveSitemap
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def add_url!(location, attrs = {})
|
63
|
-
|
66
|
+
init_writer!
|
64
67
|
|
65
68
|
tag! 'url' do
|
66
69
|
tag! 'loc', location
|
@@ -77,10 +80,7 @@ module MassiveSitemap
|
|
77
80
|
@writer.print content.gsub('&', '&')
|
78
81
|
close!(false)
|
79
82
|
else
|
80
|
-
|
81
|
-
instance_eval(&block)
|
82
|
-
close!
|
83
|
-
end
|
83
|
+
process(&block)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -92,6 +92,13 @@ module MassiveSitemap
|
|
92
92
|
end
|
93
93
|
|
94
94
|
private
|
95
|
+
def process(&block)
|
96
|
+
if block
|
97
|
+
instance_eval(&block)
|
98
|
+
close!
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
95
102
|
def url
|
96
103
|
schema, host = @options[:url].scan(/^(https?:\/\/)?(.+?)\/?$/).flatten
|
97
104
|
"#{schema || 'http://'}#{host}/"
|
@@ -9,8 +9,10 @@ module MassiveSitemap
|
|
9
9
|
}
|
10
10
|
|
11
11
|
def initialize(writer, options = {}, &block)
|
12
|
+
writer.set(:force_overwrite => true)
|
12
13
|
super(writer, options) do
|
13
14
|
writer.each do |path, last_modified|
|
15
|
+
init_writer!
|
14
16
|
next if writer.current && path.include?(writer.current)
|
15
17
|
add path, :last_modified => last_modified
|
16
18
|
end
|
@@ -22,11 +24,11 @@ module MassiveSitemap
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def self.index_url(builder, writer)
|
25
|
-
::File.join(builder.send(:url), writer.current)
|
27
|
+
writer.current && ::File.join(builder.send(:url), writer.current)
|
26
28
|
end
|
27
29
|
|
28
30
|
def add_url!(location, attrs = {})
|
29
|
-
|
31
|
+
init_writer!
|
30
32
|
|
31
33
|
tag! 'sitemap' do
|
32
34
|
tag! 'loc', location
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "massive_sitemap/builder/base"
|
2
|
-
# writer only has print and puts as interface
|
3
2
|
|
4
3
|
module MassiveSitemap
|
5
4
|
module Builder
|
@@ -11,42 +10,19 @@ module MassiveSitemap
|
|
11
10
|
)
|
12
11
|
|
13
12
|
def initialize(writer, options = {}, &block)
|
14
|
-
@rotations = 0
|
15
13
|
@urls = 0
|
16
14
|
|
17
15
|
super
|
18
16
|
end
|
19
17
|
|
20
|
-
# On rotation, close current file, and reopen a new one
|
21
|
-
# with same file name but -<counter> appendend
|
22
|
-
def init!(&block)
|
23
|
-
unless @writer.inited?
|
24
|
-
@urls = 0
|
25
|
-
filename = filename_with_rotation(@writer.options[:filename], @rotations)
|
26
|
-
@rotations += 1
|
27
|
-
@writer.init! :filename => filename
|
28
|
-
header!(&block)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
18
|
def add_url!(location, attrs = {})
|
33
19
|
if @urls >= @options[:max_urls]
|
34
20
|
close!
|
21
|
+
@urls = 0
|
35
22
|
end
|
36
23
|
super
|
37
24
|
@urls += 1
|
38
25
|
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def filename_with_rotation(filename, rotation = nil)
|
42
|
-
filename, _, ext = split_filename(filename)
|
43
|
-
rotation = (rotation.to_i > 0) ? "-#{rotation}" : nil
|
44
|
-
[filename, rotation, ext].join
|
45
|
-
end
|
46
|
-
|
47
|
-
def split_filename(filename)
|
48
|
-
filename.to_s.scan(/^([^.]*?)(-[0-9]+)?(\..+)?$/).flatten
|
49
|
-
end
|
50
26
|
end
|
51
27
|
end
|
52
28
|
end
|
@@ -1,25 +1,35 @@
|
|
1
|
-
|
1
|
+
# MassiveSitemap Writer
|
2
|
+
# The purpose of a writer is to store the written data, and to keep the state of existing data.
|
3
|
+
# It offers an API to which a builder can talk to, and a Interface which other writers have to implement
|
4
|
+
#
|
2
5
|
module MassiveSitemap
|
3
6
|
module Writer
|
4
7
|
class Base
|
5
8
|
OPTS = {}
|
6
9
|
|
7
|
-
attr_reader :options
|
8
|
-
|
9
10
|
def initialize(options = {})
|
10
11
|
@options = self.class::OPTS.merge(options)
|
11
12
|
@stream = nil
|
12
13
|
end
|
13
14
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
15
|
+
#
|
16
|
+
# API to which a builder talks to
|
17
|
+
#
|
18
|
+
# update wirter options, e.g. filename or overwrite behavior
|
19
|
+
def set(options)
|
17
20
|
@options.merge!(options)
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
# init writer: try to open stream (e.g. file)
|
25
|
+
def init!(options = {})
|
26
|
+
set(options)
|
18
27
|
if init?
|
19
28
|
@stream = open_stream
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
32
|
+
# close writer (e.g store file)
|
23
33
|
def close!
|
24
34
|
if inited?
|
25
35
|
close_stream(@stream)
|
@@ -27,27 +37,28 @@ module MassiveSitemap
|
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
40
|
+
# keep status of stream
|
30
41
|
def inited?
|
31
42
|
@stream
|
32
43
|
end
|
33
44
|
|
45
|
+
# write to stream
|
34
46
|
def print(string)
|
35
47
|
@stream.print(string) if inited?
|
36
48
|
end
|
37
49
|
|
38
50
|
def each(&block)
|
39
|
-
|
51
|
+
stream_ids.each(&block)
|
40
52
|
end
|
41
53
|
|
42
54
|
def current
|
43
|
-
|
55
|
+
stream_id
|
44
56
|
end
|
45
57
|
|
46
|
-
# def flush!
|
47
|
-
# @streams = []
|
48
|
-
# end
|
49
58
|
|
50
|
-
#
|
59
|
+
#
|
60
|
+
# Interface which other writers have to implement
|
61
|
+
#
|
51
62
|
protected
|
52
63
|
def open_stream
|
53
64
|
@string ||= StringIO.new
|
@@ -56,15 +67,17 @@ module MassiveSitemap
|
|
56
67
|
def close_stream(stream)
|
57
68
|
end
|
58
69
|
|
70
|
+
# whether if stream can be inited, likely to throw an error
|
71
|
+
# (e.g. on file existence)
|
59
72
|
def init?
|
60
73
|
true
|
61
74
|
end
|
62
75
|
|
63
|
-
def
|
64
|
-
@
|
76
|
+
def stream_ids
|
77
|
+
@stream_ids ||= []
|
65
78
|
end
|
66
79
|
|
67
|
-
def
|
80
|
+
def stream_id
|
68
81
|
nil
|
69
82
|
end
|
70
83
|
end
|
@@ -15,49 +15,69 @@ module MassiveSitemap
|
|
15
15
|
:filename => "sitemap.xml",
|
16
16
|
)
|
17
17
|
|
18
|
+
def initialize(options = {})
|
19
|
+
super
|
20
|
+
@files = Dir[::File.join(@options[:root], "*#{::File.extname(filename)}")]
|
21
|
+
end
|
22
|
+
|
18
23
|
protected
|
19
24
|
def open_stream
|
25
|
+
#create dir if not exists
|
26
|
+
@stream_id = filename
|
20
27
|
::File.dirname(tmp_filename).tap do |dir|
|
21
28
|
FileUtils.mkdir_p(dir) unless ::File.exists?(dir)
|
22
29
|
end
|
23
30
|
::File.open(tmp_filename, 'w:ASCII-8BIT')
|
24
31
|
end
|
25
32
|
|
26
|
-
def close_stream(
|
27
|
-
|
33
|
+
def close_stream(file)
|
34
|
+
file.close
|
28
35
|
# Move from tmp_file into acutal file
|
29
36
|
::File.delete(filename) if ::File.exists?(filename)
|
30
37
|
::File.rename(tmp_filename, filename)
|
38
|
+
@files << filename
|
39
|
+
rotate
|
31
40
|
end
|
32
41
|
|
33
42
|
def init?
|
34
|
-
if
|
35
|
-
|
43
|
+
if !@options[:force_overwrite] && @files.include?(filename)
|
44
|
+
error_message = "Can not create file: #{filename} exits"
|
45
|
+
rotate #push next possible filename
|
46
|
+
raise FileExistsException, error_message
|
36
47
|
end
|
37
48
|
true
|
38
49
|
end
|
39
50
|
|
40
|
-
def
|
41
|
-
files.map do |path|
|
51
|
+
def stream_ids
|
52
|
+
@files.map do |path|
|
42
53
|
[::File.basename(path), ::File.stat(path).mtime]
|
43
54
|
end.compact
|
44
55
|
end
|
45
56
|
|
46
|
-
def
|
47
|
-
|
57
|
+
def stream_id
|
58
|
+
@stream_id && ::File.basename(@stream_id)
|
48
59
|
end
|
49
60
|
|
50
61
|
private
|
51
62
|
def filename
|
52
|
-
::File.join options[:root], options[:filename]
|
63
|
+
::File.join @options[:root], @options[:filename]
|
53
64
|
end
|
54
65
|
|
55
66
|
def tmp_filename
|
56
67
|
filename + ".tmp"
|
57
68
|
end
|
58
69
|
|
59
|
-
def
|
60
|
-
|
70
|
+
def rotate
|
71
|
+
@options[:filename] = with_rotation(@options[:filename])
|
72
|
+
end
|
73
|
+
|
74
|
+
def with_rotation(filename)
|
75
|
+
filename, rotation, ext = split_filename(filename)
|
76
|
+
[filename, "-", rotation.to_i + 1, ext].join
|
77
|
+
end
|
78
|
+
|
79
|
+
def split_filename(filename)
|
80
|
+
filename.to_s.scan(/^([^.]*?)(?:-([0-9]+))?(\..+)?$/).flatten
|
61
81
|
end
|
62
82
|
end
|
63
83
|
|
data/lib/massive_sitemap.rb
CHANGED
@@ -47,10 +47,10 @@ module MassiveSitemap
|
|
47
47
|
|
48
48
|
@options[:writer] = Writer::GzipFile if @options[:gzip]
|
49
49
|
|
50
|
-
@writer = @options
|
50
|
+
@writer = @options.delete(:writer).new @options
|
51
51
|
Builder::Rotating.generate(@writer, @options, &block)
|
52
52
|
|
53
|
-
@writer.
|
53
|
+
@writer.set(:filename => @options[:index_filename])
|
54
54
|
Builder::Index.generate(@writer, @options.merge(:url => @options[:index_url]))
|
55
55
|
end
|
56
56
|
end
|
data/spec/builder/base_spec.rb
CHANGED
@@ -24,13 +24,13 @@ describe MassiveSitemap::Builder::Base do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'generate basic skeleton' do
|
27
|
-
builder.
|
27
|
+
builder.init_writer!
|
28
28
|
writer.should == header
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'generate basic skeleton on double init' do
|
32
|
-
builder.
|
33
|
-
builder.
|
32
|
+
builder.init_writer!
|
33
|
+
builder.init_writer!
|
34
34
|
writer.should == header
|
35
35
|
end
|
36
36
|
|
@@ -45,31 +45,31 @@ describe MassiveSitemap::Builder::Base do
|
|
45
45
|
writer.should == ""
|
46
46
|
end
|
47
47
|
|
48
|
-
it "same result on double close" do
|
49
|
-
builder.
|
48
|
+
it "same result on double close with init" do
|
49
|
+
builder.init_writer!
|
50
50
|
builder.close!
|
51
51
|
builder.close!
|
52
52
|
writer.should == %Q(#{header}\n</urlset>)
|
53
53
|
end
|
54
|
-
|
55
|
-
it "same result on double close" do
|
56
|
-
builder.init! do
|
57
|
-
add "test"
|
58
|
-
end
|
59
|
-
writer.should == %Q(#{header}\n <url>\n <loc>/test</loc>\n </url>\n</urlset>)
|
60
|
-
end
|
61
54
|
end
|
62
55
|
|
63
56
|
context "adding content" do
|
64
|
-
it '
|
57
|
+
it 'generate one url' do
|
65
58
|
builder.add 'test'
|
66
59
|
builder.close!
|
67
60
|
writer.should == %Q(#{header}\n <url>\n <loc>/test</loc>\n </url>\n</urlset>)
|
68
61
|
end
|
62
|
+
|
63
|
+
it "generate one url when block" do
|
64
|
+
builder.init_writer! do
|
65
|
+
add "test"
|
66
|
+
end
|
67
|
+
writer.should == %Q(#{header}\n <url>\n <loc>/test</loc>\n </url>\n</urlset>)
|
68
|
+
end
|
69
69
|
end
|
70
70
|
|
71
71
|
context "as block" do
|
72
|
-
it '
|
72
|
+
it 'empty when nothing given' do
|
73
73
|
MassiveSitemap::Builder.new(writer) {}
|
74
74
|
writer.should == ""
|
75
75
|
end
|
@@ -81,23 +81,14 @@ describe MassiveSitemap::Builder::Base do
|
|
81
81
|
writer.should == %Q(#{header}\n <url>\n <loc>/test</loc>\n </url>\n</urlset>)
|
82
82
|
end
|
83
83
|
|
84
|
-
it 'generate one url with
|
84
|
+
it 'generate one url with explizit init_writer!' do
|
85
85
|
MassiveSitemap::Builder.new(writer) do
|
86
|
-
|
86
|
+
init_writer!
|
87
87
|
add 'test'
|
88
88
|
end
|
89
89
|
writer.should == %Q(#{header}\n <url>\n <loc>/test</loc>\n </url>\n</urlset>)
|
90
90
|
end
|
91
91
|
|
92
|
-
it 'generate one url with init! block' do
|
93
|
-
MassiveSitemap::Builder.new(writer) do
|
94
|
-
init! do
|
95
|
-
add 'test'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
writer.should == %Q(#{header}\n <url>\n <loc>/test</loc>\n </url>\n</urlset>)
|
99
|
-
end
|
100
|
-
|
101
92
|
it 'generate one url with close!' do
|
102
93
|
MassiveSitemap::Builder.new(writer) do
|
103
94
|
add 'test'
|
data/spec/builder/index_spec.rb
CHANGED
@@ -46,82 +46,20 @@ describe MassiveSitemap::Builder::Rotating do
|
|
46
46
|
|
47
47
|
it 'generates two url when file exists' do
|
48
48
|
File.open(filename, 'w') {}
|
49
|
+
urls = ['test', 'test2']
|
49
50
|
expect do
|
50
51
|
expect do
|
51
52
|
MassiveSitemap::Builder::Rotating.new(writer, :max_urls => 1) do
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
urls.each do |path|
|
54
|
+
begin
|
55
|
+
add path
|
56
|
+
rescue MassiveSitemap::Writer::File::FileExistsException => e
|
57
|
+
end
|
55
58
|
end
|
56
|
-
add 'test2'
|
57
59
|
end
|
58
|
-
end.to_not change { File.exists?(filename) }.
|
60
|
+
end.to_not change { File.exists?(filename) }.from(true)
|
59
61
|
end.to change { File.exists?(filename2) }.to(true)
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
describe "#filename_with_rotation" do
|
64
|
-
context "keeps filename" do
|
65
|
-
it "rotation is zero" do
|
66
|
-
builder.send(:filename_with_rotation, "sitemap.xml").should == "sitemap.xml"
|
67
|
-
end
|
68
|
-
|
69
|
-
it "rotation is zero" do
|
70
|
-
builder.send(:filename_with_rotation, "sitemap2.xml").should == "sitemap2.xml"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "rotation is zero" do
|
74
|
-
builder.send(:filename_with_rotation, "sitemap.xml", nil).should == "sitemap.xml"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "rotation is nil" do
|
78
|
-
builder.send(:filename_with_rotation, "sitemap.xml", 0).should == "sitemap.xml"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "rotation is 1" do
|
83
|
-
it "add prefix" do
|
84
|
-
builder.send(:filename_with_rotation, "sitemap.xml", 1).should == "sitemap-1.xml"
|
85
|
-
end
|
86
|
-
|
87
|
-
it "rotation is zero" do
|
88
|
-
builder.send(:filename_with_rotation, "sitemap-1.xml", 1).should == "sitemap-1.xml"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "rotation is zero" do
|
92
|
-
builder.send(:filename_with_rotation, "sitemap-user.xml", 1).should == "sitemap-user-1.xml"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#split_filename" do
|
98
|
-
FILENAMES = {
|
99
|
-
nil => ["", nil, nil],
|
100
|
-
".xml" => ["", nil, ".xml"],
|
101
|
-
".xml.gz" => ["", nil, ".xml.gz"],
|
102
|
-
"sitemap" => ["sitemap", nil, nil],
|
103
|
-
"sitemap.xml" => ["sitemap", nil, ".xml"],
|
104
|
-
"sitemap.xml.gz" => ["sitemap", nil, ".xml.gz"],
|
105
|
-
"-1.xml" => ["", "-1", ".xml"],
|
106
|
-
"-1.xml.gz" => ["", "-1", ".xml.gz"],
|
107
|
-
"sitemap-1" => ["sitemap", "-1", nil],
|
108
|
-
"sitemap-1.xml" => ["sitemap", "-1", ".xml"],
|
109
|
-
"sitemap-1.xml.gz" => ["sitemap", "-1", ".xml.gz"],
|
110
|
-
"-user-1.xml" => ["-user", "-1", ".xml"],
|
111
|
-
"-user-1.xml.gz" => ["-user", "-1", ".xml.gz"],
|
112
|
-
"sitemap-user-1" => ["sitemap-user", "-1", nil],
|
113
|
-
"sitemap-user-1.xml" => ["sitemap-user", "-1", ".xml"],
|
114
|
-
"sitemap-user-1.xml.gz" => ["sitemap-user", "-1", ".xml.gz"],
|
115
|
-
"sitemap1" => ["sitemap1", nil, nil],
|
116
|
-
"sitemap1.xml" => ["sitemap1", nil, ".xml"],
|
117
|
-
"sitemap1.xml.gz" => ["sitemap1", nil, ".xml.gz"],
|
118
|
-
}
|
119
|
-
|
120
|
-
FILENAMES.each do |filename, expected|
|
121
|
-
it "splits filename #{filename} into #{expected.join(' ')}" do
|
122
|
-
builder.send(:split_filename, filename).should == expected
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
65
|
end
|
data/spec/lock_spec.rb
CHANGED
@@ -80,46 +80,48 @@ describe MassiveSitemap do
|
|
80
80
|
output.should include("<loc>http://test.de/track/name</loc>")
|
81
81
|
end
|
82
82
|
|
83
|
-
it "
|
83
|
+
it "to fail for existing file" do
|
84
84
|
File.open(filename, 'w') {}
|
85
85
|
expect do
|
86
86
|
MassiveSitemap.generate(:url => 'test.de/') do
|
87
87
|
add "/track/name"
|
88
88
|
end
|
89
|
-
end.
|
89
|
+
end.to raise_error(MassiveSitemap::Writer::File::FileExistsException)
|
90
90
|
end
|
91
91
|
|
92
92
|
context 'nested generation' do
|
93
|
-
|
93
|
+
let(:generate!) do
|
94
94
|
MassiveSitemap.generate(:url => 'test.de/') do
|
95
|
-
|
96
|
-
MassiveSitemap::Builder::Rotating.
|
95
|
+
@writer.set(:filename => 'sitemap2.xml')
|
96
|
+
MassiveSitemap::Builder::Rotating.generate(@writer, @options) do
|
97
|
+
init_writer!
|
97
98
|
add "/set/name"
|
98
99
|
end
|
99
100
|
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'adds url of nested builder' do
|
104
|
+
generate!
|
105
|
+
|
100
106
|
output(filename2).should include("<loc>http://test.de/set/name</loc>")
|
101
107
|
end
|
102
108
|
|
103
109
|
it 'executes block altough first sitemap exists' do
|
104
110
|
File.open(filename, 'w') {}
|
105
|
-
|
106
|
-
|
107
|
-
MassiveSitemap::Builder::Rotating.new(writer, @options) do
|
108
|
-
add "/set/name"
|
109
|
-
end
|
110
|
-
end
|
111
|
+
generate!
|
112
|
+
|
111
113
|
output(filename2).should include("<loc>http://test.de/set/name</loc>")
|
112
114
|
end
|
113
115
|
end
|
114
|
-
|
115
116
|
end
|
116
117
|
|
117
118
|
context "generate_index" do
|
118
119
|
let(:lastmod) { File.stat(index_filename).mtime.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00') }
|
119
120
|
|
120
121
|
it "does not create empty files" do
|
121
|
-
|
122
|
-
|
122
|
+
expect do
|
123
|
+
MassiveSitemap.generate(:url => 'test.de/')
|
124
|
+
end.to_not change { ::File.exists?(index_filename) }.from(false)
|
123
125
|
end
|
124
126
|
|
125
127
|
it 'includes urls' do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "massive_sitemap/writer/base"
|
4
|
+
|
5
|
+
describe MassiveSitemap::Writer::Base do
|
6
|
+
let(:writer) { MassiveSitemap::Writer::Base.new }
|
7
|
+
|
8
|
+
describe "set" do
|
9
|
+
it "returns itself" do
|
10
|
+
writer.set(:filename => "test").should == writer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/writer/file_spec.rb
CHANGED
@@ -12,11 +12,17 @@ describe MassiveSitemap::Writer::File do
|
|
12
12
|
FileUtils.rm(filename2) rescue nil
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "set" do
|
16
|
+
it "updates filename" do
|
17
|
+
writer.set(:filename => "test").send(:filename).should == "./test"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
describe "root" do
|
16
22
|
let(:root) { "test/test2" }
|
17
23
|
|
18
24
|
after do
|
19
|
-
FileUtils.rm_rf(root) rescue nil
|
25
|
+
FileUtils.rm_rf(File.dirname(root)) rescue nil
|
20
26
|
end
|
21
27
|
|
22
28
|
it 'mkdir_p folder' do
|
@@ -69,10 +75,11 @@ describe MassiveSitemap::Writer::File do
|
|
69
75
|
`cat '#{filename}'`.should == "test"
|
70
76
|
end
|
71
77
|
|
72
|
-
it 'inits new file closes current' do
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
it 'inits new file does not closes current' do
|
79
|
+
expect do
|
80
|
+
writer.print 'test'
|
81
|
+
writer.init!(:filename => filename2)
|
82
|
+
end.to_not change { File.exists?(filename) }
|
76
83
|
end
|
77
84
|
|
78
85
|
it 'writes into second file' do
|
@@ -103,4 +110,62 @@ describe MassiveSitemap::Writer::File do
|
|
103
110
|
end.to_not raise_error(MassiveSitemap::Writer::File::FileExistsException)
|
104
111
|
end
|
105
112
|
end
|
113
|
+
|
114
|
+
describe "#with_rotation" do
|
115
|
+
let(:writer) { MassiveSitemap::Writer::File.new }
|
116
|
+
|
117
|
+
context "keeps filename" do
|
118
|
+
it "rotation is zero" do
|
119
|
+
writer.send(:with_rotation, "sitemap.xml").should == "sitemap-1.xml"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "rotation is zero" do
|
123
|
+
writer.send(:with_rotation, "sitemap2.xml").should == "sitemap2-1.xml"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "rotation is zero" do
|
127
|
+
writer.send(:with_rotation, "sitemap-1.xml").should == "sitemap-2.xml"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "rotation is zero" do
|
131
|
+
writer.send(:with_rotation, "sitemap-1-1.xml").should == "sitemap-1-2.xml"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "rotation is nil" do
|
135
|
+
writer.send(:with_rotation, "sitemap-user.xml").should == "sitemap-user-1.xml"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#split_filename" do
|
141
|
+
let(:writer) { MassiveSitemap::Writer::File.new }
|
142
|
+
|
143
|
+
FILENAMES = {
|
144
|
+
nil => ["", nil, nil],
|
145
|
+
".xml" => ["", nil, ".xml"],
|
146
|
+
".xml.gz" => ["", nil, ".xml.gz"],
|
147
|
+
"sitemap" => ["sitemap", nil, nil],
|
148
|
+
"sitemap.xml" => ["sitemap", nil, ".xml"],
|
149
|
+
"sitemap.xml.gz" => ["sitemap", nil, ".xml.gz"],
|
150
|
+
"-1.xml" => ["", "1", ".xml"],
|
151
|
+
"-1.xml.gz" => ["", "1", ".xml.gz"],
|
152
|
+
"sitemap-1" => ["sitemap", "1", nil],
|
153
|
+
"sitemap-1.xml" => ["sitemap", "1", ".xml"],
|
154
|
+
"sitemap-1.xml.gz" => ["sitemap", "1", ".xml.gz"],
|
155
|
+
"-user-1.xml" => ["-user", "1", ".xml"],
|
156
|
+
"-user-1.xml.gz" => ["-user", "1", ".xml.gz"],
|
157
|
+
"sitemap-user-1" => ["sitemap-user", "1", nil],
|
158
|
+
"sitemap-user-1.xml" => ["sitemap-user", "1", ".xml"],
|
159
|
+
"sitemap-user-1.xml.gz" => ["sitemap-user", "1", ".xml.gz"],
|
160
|
+
"sitemap1" => ["sitemap1", nil, nil],
|
161
|
+
"sitemap1.xml" => ["sitemap1", nil, ".xml"],
|
162
|
+
"sitemap1.xml.gz" => ["sitemap1", nil, ".xml.gz"],
|
163
|
+
}
|
164
|
+
|
165
|
+
FILENAMES.each do |filename, expected|
|
166
|
+
it "splits filename #{filename} into #{expected.join(' ')}" do
|
167
|
+
writer.send(:split_filename, filename).should == expected
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
106
171
|
end
|
@@ -7,14 +7,16 @@ describe MassiveSitemap::Writer::GzipFile do
|
|
7
7
|
|
8
8
|
let(:writer) { MassiveSitemap::Writer::GzipFile.new.tap { |w| w.init! } }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
context "without root" do
|
11
|
+
after do
|
12
|
+
writer.each { |path| FileUtils.rm(path.first) }
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
it 'creates gzip file' do
|
16
|
+
expect do
|
17
|
+
writer.close!
|
18
|
+
end.to change { ::File.exists?(gz_filename) }.to(true)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
context "with root" do
|
@@ -29,7 +31,7 @@ describe MassiveSitemap::Writer::GzipFile do
|
|
29
31
|
it 'creates gzip file in document root' do
|
30
32
|
expect do
|
31
33
|
writer.close!
|
32
|
-
end.to change { File.exists?("sitemap/#{gz_filename}") }.to(true)
|
34
|
+
end.to change { ::File.exists?("sitemap/#{gz_filename}") }.to(true)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: massive_sitemap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70096501425420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70096501425420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70096501424960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70096501424960
|
36
36
|
description: MassiveSitemap - build huge sitemaps painfree. Differential updates keeps
|
37
37
|
generation time short and reduces load on DB. It's heavealy inspired by BigSitemaps
|
38
38
|
and offers compatiable API
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- spec/massive_sitemap_spec.rb
|
70
70
|
- spec/ping_spec.rb
|
71
71
|
- spec/spec_helper.rb
|
72
|
+
- spec/writer/base_spec.rb
|
72
73
|
- spec/writer/file_spec.rb
|
73
74
|
- spec/writer/gzip_file_spec.rb
|
74
75
|
homepage: http://github.com/rngtng/massive_sitemap
|
@@ -103,5 +104,6 @@ test_files:
|
|
103
104
|
- spec/massive_sitemap_spec.rb
|
104
105
|
- spec/ping_spec.rb
|
105
106
|
- spec/spec_helper.rb
|
107
|
+
- spec/writer/base_spec.rb
|
106
108
|
- spec/writer/file_spec.rb
|
107
109
|
- spec/writer/gzip_file_spec.rb
|