sitemap_generator 5.0.0.beta → 5.0.0.beta1
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/sitemap_file.rb +4 -21
- data/lib/sitemap_generator/builder/sitemap_index_file.rb +2 -2
- data/lib/sitemap_generator/sitemap_location.rb +10 -8
- data/lib/sitemap_generator/utilities.rb +18 -3
- data/spec/sitemap_generator/builder/sitemap_file_spec.rb +0 -22
- data/spec/sitemap_generator/sitemap_location_spec.rb +13 -2
- data/spec/sitemap_generator/utilities_spec.rb +23 -1
- metadata +3 -2
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.0.0.
|
1
|
+
5.0.0.beta1
|
@@ -42,7 +42,7 @@ module SitemapGenerator
|
|
42
42
|
HTML
|
43
43
|
@xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
|
44
44
|
@xml_wrapper_end = %q[</urlset>]
|
45
|
-
@filesize = bytesize(@xml_wrapper_start) + bytesize(@xml_wrapper_end)
|
45
|
+
@filesize = SitemapGenerator::Utilities.bytesize(@xml_wrapper_start) + SitemapGenerator::Utilities.bytesize(@xml_wrapper_end)
|
46
46
|
@written = false
|
47
47
|
@reserved_name = nil # holds the name reserved from the namer
|
48
48
|
@frozen = false # rather than actually freeze, use this boolean
|
@@ -66,7 +66,7 @@ module SitemapGenerator
|
|
66
66
|
# of <tt>bytes</tt> bytes in size. You can also pass a string and the
|
67
67
|
# bytesize will be calculated for you.
|
68
68
|
def file_can_fit?(bytes)
|
69
|
-
bytes = bytes.is_a?(String) ? bytesize(bytes) : bytes
|
69
|
+
bytes = bytes.is_a?(String) ? SitemapGenerator::Utilities.bytesize(bytes) : bytes
|
70
70
|
(@filesize + bytes) < SitemapGenerator::MAX_SITEMAP_FILESIZE && @link_count < SitemapGenerator::MAX_SITEMAP_LINKS && @news_count < SitemapGenerator::MAX_SITEMAP_NEWS
|
71
71
|
end
|
72
72
|
|
@@ -108,7 +108,7 @@ module SitemapGenerator
|
|
108
108
|
|
109
109
|
# Add the XML to the sitemap
|
110
110
|
@xml_content << xml
|
111
|
-
@filesize += bytesize(xml)
|
111
|
+
@filesize += SitemapGenerator::Utilities.bytesize(xml)
|
112
112
|
@link_count += 1
|
113
113
|
end
|
114
114
|
|
@@ -136,7 +136,7 @@ module SitemapGenerator
|
|
136
136
|
raise SitemapGenerator::SitemapError.new("Sitemap already written!") if written?
|
137
137
|
finalize! unless finalized?
|
138
138
|
reserve_name
|
139
|
-
@location.write(@xml_wrapper_start + @xml_content + @xml_wrapper_end)
|
139
|
+
@location.write(@xml_wrapper_start + @xml_content + @xml_wrapper_end, link_count)
|
140
140
|
@xml_content = @xml_wrapper_start = @xml_wrapper_end = ''
|
141
141
|
@written = true
|
142
142
|
end
|
@@ -164,23 +164,6 @@ module SitemapGenerator
|
|
164
164
|
location.delete(:filename) if location.namer
|
165
165
|
self.class.new(location)
|
166
166
|
end
|
167
|
-
|
168
|
-
protected
|
169
|
-
|
170
|
-
# Replace the last 3 characters of string with ... if the string is as big
|
171
|
-
# or bigger than max.
|
172
|
-
def ellipsis(string, max)
|
173
|
-
if string.size > max
|
174
|
-
(string[0, max - 3] || '') + '...'
|
175
|
-
else
|
176
|
-
string
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Return the bytesize length of the string. Ruby 1.8.6 compatible.
|
181
|
-
def bytesize(string)
|
182
|
-
string.respond_to?(:bytesize) ? string.bytesize : string.length
|
183
|
-
end
|
184
167
|
end
|
185
168
|
end
|
186
169
|
end
|
@@ -22,7 +22,7 @@ module SitemapGenerator
|
|
22
22
|
HTML
|
23
23
|
@xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
|
24
24
|
@xml_wrapper_end = %q[</sitemapindex>]
|
25
|
-
@filesize = bytesize(@xml_wrapper_start) + bytesize(@xml_wrapper_end)
|
25
|
+
@filesize = SitemapGenerator::Utilities.bytesize(@xml_wrapper_start) + SitemapGenerator::Utilities.bytesize(@xml_wrapper_end)
|
26
26
|
@written = false
|
27
27
|
@reserved_name = nil # holds the name reserved from the namer
|
28
28
|
@frozen = false # rather than actually freeze, use this boolean
|
@@ -84,7 +84,7 @@ module SitemapGenerator
|
|
84
84
|
# of <tt>bytes</tt> bytes in size. You can also pass a string and the
|
85
85
|
# bytesize will be calculated for you.
|
86
86
|
def file_can_fit?(bytes)
|
87
|
-
bytes = bytes.is_a?(String) ? bytesize(bytes) : bytes
|
87
|
+
bytes = bytes.is_a?(String) ? SitemapGenerator::Utilities.bytesize(bytes) : bytes
|
88
88
|
(@filesize + bytes) < SitemapGenerator::MAX_SITEMAP_FILESIZE && @link_count < SitemapGenerator::MAX_SITEMAP_FILES
|
89
89
|
end
|
90
90
|
|
@@ -150,16 +150,17 @@ module SitemapGenerator
|
|
150
150
|
|
151
151
|
# Write `data` out to a file.
|
152
152
|
# Output a summary line if verbose is true.
|
153
|
-
def write(data)
|
153
|
+
def write(data, link_count)
|
154
154
|
adapter.write(self, data)
|
155
|
-
puts summary if verbose?
|
155
|
+
puts summary(link_count) if verbose?
|
156
156
|
end
|
157
157
|
|
158
158
|
# Return a summary string
|
159
|
-
def summary
|
159
|
+
def summary(link_count)
|
160
160
|
filesize = number_to_human_size(self.filesize)
|
161
|
-
|
162
|
-
|
161
|
+
width = self.class::PATH_OUTPUT_WIDTH
|
162
|
+
path = SitemapGenerator::Utilities.ellipsis(self.path_in_public, width)
|
163
|
+
"+ #{('%-'+width.to_s+'s') % path} #{'%10s' % link_count} links / #{'%10s' % filesize}"
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
@@ -181,10 +182,11 @@ module SitemapGenerator
|
|
181
182
|
end
|
182
183
|
|
183
184
|
# Return a summary string
|
184
|
-
def summary
|
185
|
+
def summary(link_count)
|
185
186
|
filesize = number_to_human_size(self.filesize)
|
186
|
-
|
187
|
-
|
187
|
+
width = self.class::PATH_OUTPUT_WIDTH - 3
|
188
|
+
path = SitemapGenerator::Utilities.ellipsis(self.path_in_public, width)
|
189
|
+
"+ #{('%-'+width.to_s+'s') % path} #{'%10s' % link_count} sitemaps / #{'%10s' % filesize}"
|
188
190
|
end
|
189
191
|
end
|
190
192
|
end
|
@@ -60,7 +60,7 @@ module SitemapGenerator
|
|
60
60
|
[value]
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
# Rounds the float with the specified precision.
|
65
65
|
#
|
66
66
|
# x = 1.337
|
@@ -151,7 +151,7 @@ module SitemapGenerator
|
|
151
151
|
def falsy?(value)
|
152
152
|
['0', 0, 'f', 'false', false].include?(value)
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
# Append a slash to `path` if it does not already end in a slash.
|
156
156
|
# Returns a string. Expects a string or Pathname object.
|
157
157
|
def append_slash(path)
|
@@ -159,8 +159,23 @@ module SitemapGenerator
|
|
159
159
|
if strpath[-1] != nil && strpath[-1].chr != '/'
|
160
160
|
strpath + '/'
|
161
161
|
else
|
162
|
-
strpath
|
162
|
+
strpath
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Replace the last 3 characters of string with ... if the string is as big
|
167
|
+
# or bigger than max.
|
168
|
+
def ellipsis(string, max)
|
169
|
+
if string.size > max
|
170
|
+
(string[0, max - 3] || '') + '...'
|
171
|
+
else
|
172
|
+
string
|
163
173
|
end
|
164
174
|
end
|
175
|
+
|
176
|
+
# Return the bytesize length of the string. Ruby 1.8.6 compatible.
|
177
|
+
def bytesize(string)
|
178
|
+
string.respond_to?(:bytesize) ? string.bytesize : string.length
|
179
|
+
end
|
165
180
|
end
|
166
181
|
end
|
@@ -107,26 +107,4 @@ describe 'SitemapGenerator::Builder::SitemapFile' do
|
|
107
107
|
sitemap.add '/one'
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
111
|
-
describe "ellipsis" do
|
112
|
-
it "should not modify when less than or equal to max" do
|
113
|
-
(1..10).each do |i|
|
114
|
-
string = 'a'*i
|
115
|
-
sitemap.send(:ellipsis, string, 10).should == string
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should replace last 3 characters with ellipsis when greater than max" do
|
120
|
-
(1..5).each do |i|
|
121
|
-
string = 'aaaaa' + 'a'*i
|
122
|
-
sitemap.send(:ellipsis, string, 5).should == 'aa...'
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should not freak out when string too small" do
|
127
|
-
sitemap.send(:ellipsis, 'a', 1).should == 'a'
|
128
|
-
sitemap.send(:ellipsis, 'aa', 1).should == '...'
|
129
|
-
sitemap.send(:ellipsis, 'aaa', 1).should == '...'
|
130
|
-
end
|
131
|
-
end
|
132
110
|
end
|
@@ -149,14 +149,14 @@ describe SitemapGenerator::SitemapLocation do
|
|
149
149
|
location = SitemapGenerator::SitemapLocation.new(:public_path => 'public/', :verbose => true)
|
150
150
|
location.adapter.stubs(:write)
|
151
151
|
location.expects(:summary)
|
152
|
-
location.write('data')
|
152
|
+
location.write('data', 1)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should not output summary line when not verbose" do
|
156
156
|
location = SitemapGenerator::SitemapLocation.new(:public_path => 'public/', :verbose => false)
|
157
157
|
location.adapter.stubs(:write)
|
158
158
|
location.expects(:summary).never
|
159
|
-
location.write('data')
|
159
|
+
location.write('data', 1)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -185,6 +185,17 @@ describe SitemapGenerator::SitemapLocation do
|
|
185
185
|
location.filename.should == 'sitemap.xml.gz'
|
186
186
|
end
|
187
187
|
end
|
188
|
+
|
189
|
+
describe "when not compressing" do
|
190
|
+
it "the URL should point to the uncompressed file" do
|
191
|
+
location = SitemapGenerator::SitemapLocation.new(
|
192
|
+
:namer => SitemapGenerator::SimpleNamer.new(:sitemap),
|
193
|
+
:host => 'http://example.com',
|
194
|
+
:compress => false
|
195
|
+
)
|
196
|
+
location.url.should == 'http://example.com/sitemap.xml'
|
197
|
+
end
|
198
|
+
end
|
188
199
|
end
|
189
200
|
|
190
201
|
describe SitemapGenerator::SitemapIndexLocation do
|
@@ -66,7 +66,7 @@ describe SitemapGenerator::Utilities do
|
|
66
66
|
SitemapGenerator::Utilities.as_array({}).should == [{}]
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
describe "append_slash" do
|
71
71
|
SitemapGenerator::Utilities.append_slash('').should == ''
|
72
72
|
SitemapGenerator::Utilities.append_slash(nil).should == ''
|
@@ -76,4 +76,26 @@ describe SitemapGenerator::Utilities do
|
|
76
76
|
SitemapGenerator::Utilities.append_slash('tmp/').should == 'tmp/'
|
77
77
|
SitemapGenerator::Utilities.append_slash(Pathname.new('tmp/')).should == 'tmp/'
|
78
78
|
end
|
79
|
+
|
80
|
+
describe "ellipsis" do
|
81
|
+
it "should not modify when less than or equal to max" do
|
82
|
+
(1..10).each do |i|
|
83
|
+
string = 'a'*i
|
84
|
+
SitemapGenerator::Utilities.ellipsis(string, 10).should == string
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should replace last 3 characters with ellipsis when greater than max" do
|
89
|
+
(1..5).each do |i|
|
90
|
+
string = 'aaaaa' + 'a'*i
|
91
|
+
SitemapGenerator::Utilities.ellipsis(string, 5).should == 'aa...'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not freak out when string too small" do
|
96
|
+
SitemapGenerator::Utilities.ellipsis('a', 1).should == 'a'
|
97
|
+
SitemapGenerator::Utilities.ellipsis('aa', 1).should == '...'
|
98
|
+
SitemapGenerator::Utilities.ellipsis('aaa', 1).should == '...'
|
99
|
+
end
|
100
|
+
end
|
79
101
|
end
|
metadata
CHANGED
@@ -7,7 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 5.0.0.beta1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Karl Varga
|
@@ -175,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
176
|
requirements:
|
176
177
|
- - ">="
|
177
178
|
- !ruby/object:Gem::Version
|
178
|
-
hash: -
|
179
|
+
hash: -4596845010722426093
|
179
180
|
segments:
|
180
181
|
- 0
|
181
182
|
version: "0"
|