sitemap_generator 7.0.3 → 7.1.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.
- checksums.yaml +4 -4
- data/CHANGES.md +73 -64
- data/README.md +142 -143
- data/VERSION +1 -1
- data/lib/capistrano/sitemap_generator.rb +2 -0
- data/lib/sitemap_generator/adapters/active_storage_adapter.rb +15 -10
- data/lib/sitemap_generator/adapters/aws_sdk_adapter.rb +13 -12
- data/lib/sitemap_generator/adapters/file_adapter.rb +10 -13
- data/lib/sitemap_generator/adapters/fog_adapter.rb +2 -2
- data/lib/sitemap_generator/adapters/google_storage_adapter.rb +5 -4
- data/lib/sitemap_generator/adapters/s3_adapter.rb +15 -14
- data/lib/sitemap_generator/adapters/wave_adapter.rb +5 -5
- data/lib/sitemap_generator/application.rb +5 -3
- data/lib/sitemap_generator/builder/sitemap_file.rb +17 -14
- data/lib/sitemap_generator/builder/sitemap_index_file.rb +20 -18
- data/lib/sitemap_generator/builder/sitemap_index_url.rb +5 -6
- data/lib/sitemap_generator/builder/sitemap_url.rb +58 -34
- data/lib/sitemap_generator/builder.rb +4 -2
- data/lib/sitemap_generator/core_ext/big_decimal.rb +38 -33
- data/lib/sitemap_generator/core_ext/numeric.rb +50 -46
- data/lib/sitemap_generator/helpers/number_helper.rb +52 -46
- data/lib/sitemap_generator/interpreter.rb +11 -15
- data/lib/sitemap_generator/link_set.rb +63 -65
- data/lib/sitemap_generator/railtie.rb +1 -0
- data/lib/sitemap_generator/simple_namer.rb +3 -4
- data/lib/sitemap_generator/sitemap_location.rb +44 -36
- data/lib/sitemap_generator/tasks.rb +1 -1
- data/lib/sitemap_generator/templates.rb +6 -7
- data/lib/sitemap_generator/utilities.rb +25 -17
- data/lib/sitemap_generator.rb +22 -14
- data/lib/tasks/sitemap_generator_tasks.rake +2 -0
- data/rails/install.rb +2 -0
- data/rails/uninstall.rb +2 -0
- data/templates/sitemap.rb +2 -0
- metadata +2 -2
|
@@ -5,53 +5,58 @@ require 'bigdecimal'
|
|
|
5
5
|
begin
|
|
6
6
|
require 'psych'
|
|
7
7
|
rescue LoadError
|
|
8
|
+
# psych is optional; fall back gracefully if unavailable
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
require 'yaml'
|
|
11
12
|
|
|
12
13
|
# Define our own class rather than modify the global class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
module SitemapGenerator
|
|
15
|
+
# Scoped BigDecimal wrapper that serializes to YAML without scientific notation.
|
|
16
|
+
# Defined here rather than reopening the global BigDecimal class.
|
|
17
|
+
class BigDecimal
|
|
18
|
+
YAML_TAG = 'tag:yaml.org,2002:float'
|
|
19
|
+
YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }.freeze
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
yaml_tag YAML_TAG
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
def initialize(num)
|
|
24
|
+
@value = BigDecimal(num)
|
|
25
|
+
end
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
def *(other)
|
|
28
|
+
other * @value
|
|
29
|
+
end
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
def /(other)
|
|
32
|
+
other.is_a?(SitemapGenerator::BigDecimal) ? @value / other.instance_variable_get(:@value) : @value / other
|
|
33
|
+
end
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# This emits the number without any scientific notation.
|
|
36
|
+
# This is better than self.to_f.to_s since it doesn't lose precision.
|
|
37
|
+
#
|
|
38
|
+
# Note that reconstituting YAML floats to native floats may lose precision.
|
|
39
|
+
def to_yaml(opts = {})
|
|
40
|
+
return super unless defined?(YAML::ENGINE) && YAML::ENGINE.syck?
|
|
41
|
+
|
|
42
|
+
YAML.quick_emit(nil, opts) do |out|
|
|
43
|
+
string = to_s
|
|
44
|
+
out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
def encode_with(coder)
|
|
39
49
|
string = to_s
|
|
40
|
-
|
|
50
|
+
coder.represent_scalar(nil, YAML_MAPPING[string] || string)
|
|
41
51
|
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def encode_with(coder)
|
|
45
|
-
string = to_s
|
|
46
|
-
coder.represent_scalar(nil, YAML_MAPPING[string] || string)
|
|
47
|
-
end
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
def to_d
|
|
54
|
+
self
|
|
55
|
+
end
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
DEFAULT_STRING_FORMAT = 'F'
|
|
58
|
+
def to_s(format = DEFAULT_STRING_FORMAT)
|
|
59
|
+
@value.to_s(format)
|
|
60
|
+
end
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -1,50 +1,54 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
module SitemapGenerator
|
|
4
|
+
# Scoped Numeric wrapper providing byte-unit helpers (+kilobytes+, +megabytes+, etc.).
|
|
5
|
+
# Defined here rather than reopening the global Numeric class.
|
|
6
|
+
class Numeric
|
|
7
|
+
KILOBYTE = 1024
|
|
8
|
+
MEGABYTE = KILOBYTE * 1024
|
|
9
|
+
GIGABYTE = MEGABYTE * 1024
|
|
10
|
+
TERABYTE = GIGABYTE * 1024
|
|
11
|
+
PETABYTE = TERABYTE * 1024
|
|
12
|
+
EXABYTE = PETABYTE * 1024
|
|
13
|
+
|
|
14
|
+
def initialize(number)
|
|
15
|
+
@number = number
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
|
|
19
|
+
def bytes
|
|
20
|
+
@number
|
|
21
|
+
end
|
|
22
|
+
alias byte bytes
|
|
23
|
+
|
|
24
|
+
def kilobytes
|
|
25
|
+
@number * KILOBYTE
|
|
26
|
+
end
|
|
27
|
+
alias kilobyte kilobytes
|
|
28
|
+
|
|
29
|
+
def megabytes
|
|
30
|
+
@number * MEGABYTE
|
|
31
|
+
end
|
|
32
|
+
alias megabyte megabytes
|
|
33
|
+
|
|
34
|
+
def gigabytes
|
|
35
|
+
@number * GIGABYTE
|
|
36
|
+
end
|
|
37
|
+
alias gigabyte gigabytes
|
|
38
|
+
|
|
39
|
+
def terabytes
|
|
40
|
+
@number * TERABYTE
|
|
41
|
+
end
|
|
42
|
+
alias terabyte terabytes
|
|
43
|
+
|
|
44
|
+
def petabytes
|
|
45
|
+
@number * PETABYTE
|
|
46
|
+
end
|
|
47
|
+
alias petabyte petabytes
|
|
48
|
+
|
|
49
|
+
def exabytes
|
|
50
|
+
@number * EXABYTE
|
|
51
|
+
end
|
|
52
|
+
alias exabyte exabytes
|
|
13
53
|
end
|
|
14
|
-
|
|
15
|
-
# Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
|
|
16
|
-
def bytes
|
|
17
|
-
@number
|
|
18
|
-
end
|
|
19
|
-
alias :byte :bytes
|
|
20
|
-
|
|
21
|
-
def kilobytes
|
|
22
|
-
@number * KILOBYTE
|
|
23
|
-
end
|
|
24
|
-
alias :kilobyte :kilobytes
|
|
25
|
-
|
|
26
|
-
def megabytes
|
|
27
|
-
@number * MEGABYTE
|
|
28
|
-
end
|
|
29
|
-
alias :megabyte :megabytes
|
|
30
|
-
|
|
31
|
-
def gigabytes
|
|
32
|
-
@number * GIGABYTE
|
|
33
|
-
end
|
|
34
|
-
alias :gigabyte :gigabytes
|
|
35
|
-
|
|
36
|
-
def terabytes
|
|
37
|
-
@number * TERABYTE
|
|
38
|
-
end
|
|
39
|
-
alias :terabyte :terabytes
|
|
40
|
-
|
|
41
|
-
def petabytes
|
|
42
|
-
@number * PETABYTE
|
|
43
|
-
end
|
|
44
|
-
alias :petabyte :petabytes
|
|
45
|
-
|
|
46
|
-
def exabytes
|
|
47
|
-
@number * EXABYTE
|
|
48
|
-
end
|
|
49
|
-
alias :exabyte :exabytes
|
|
50
54
|
end
|
|
@@ -6,20 +6,20 @@ require 'sitemap_generator/utilities'
|
|
|
6
6
|
module SitemapGenerator
|
|
7
7
|
# = SitemapGenerator Number Helpers
|
|
8
8
|
module Helpers # :nodoc:
|
|
9
|
-
|
|
10
9
|
# Provides methods for converting numbers into formatted strings.
|
|
11
10
|
# Methods are provided for precision, positional notation and file size
|
|
12
11
|
# and pretty printing.
|
|
13
12
|
#
|
|
14
13
|
# Most methods expect a +number+ argument, and will return it
|
|
15
14
|
# unchanged if can't be converted into a valid number.
|
|
16
|
-
module NumberHelper
|
|
17
|
-
|
|
15
|
+
module NumberHelper # rubocop:disable Metrics/ModuleLength
|
|
18
16
|
# Raised when argument +number+ param given to the helpers is invalid and
|
|
19
17
|
# the option :raise is set to +true+.
|
|
20
18
|
class InvalidNumberError < StandardError
|
|
21
19
|
attr_accessor :number
|
|
20
|
+
|
|
22
21
|
def initialize(number)
|
|
22
|
+
super(number.to_s)
|
|
23
23
|
@number = number
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -40,17 +40,15 @@ module SitemapGenerator
|
|
|
40
40
|
# number_with_delimiter(12345678.05, :locale => :fr) # => 12 345 678,05
|
|
41
41
|
# number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",")
|
|
42
42
|
# # => 98 765 432,98
|
|
43
|
-
def number_with_delimiter(number, options = {})
|
|
43
|
+
def number_with_delimiter(number, options = {}) # rubocop:disable Metrics/MethodLength
|
|
44
44
|
SitemapGenerator::Utilities.symbolize_keys!(options)
|
|
45
45
|
|
|
46
46
|
begin
|
|
47
47
|
Float(number)
|
|
48
48
|
rescue ArgumentError, TypeError
|
|
49
|
-
if options[:raise]
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return number
|
|
53
|
-
end
|
|
49
|
+
raise InvalidNumberError, number if options[:raise]
|
|
50
|
+
|
|
51
|
+
return number
|
|
54
52
|
end
|
|
55
53
|
|
|
56
54
|
defaults = {
|
|
@@ -74,10 +72,12 @@ module SitemapGenerator
|
|
|
74
72
|
# ==== Options
|
|
75
73
|
# * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
|
|
76
74
|
# * <tt>:precision</tt> - Sets the precision of the number (defaults to 3).
|
|
77
|
-
# * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits.
|
|
75
|
+
# * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits.
|
|
76
|
+
# If +false+, the # of fractional digits (defaults to +false+)
|
|
78
77
|
# * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to ".").
|
|
79
78
|
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
|
|
80
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator
|
|
79
|
+
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator
|
|
80
|
+
# (defaults to +false+)
|
|
81
81
|
#
|
|
82
82
|
# ==== Examples
|
|
83
83
|
# number_with_precision(111.2345) # => 111.235
|
|
@@ -93,17 +93,15 @@ module SitemapGenerator
|
|
|
93
93
|
# number_with_precision(389.32314, :precision => 4, :significant => true) # => 389.3
|
|
94
94
|
# number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.')
|
|
95
95
|
# # => 1.111,23
|
|
96
|
-
def number_with_precision(number, options = {})
|
|
96
|
+
def number_with_precision(number, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
97
97
|
SitemapGenerator::Utilities.symbolize_keys!(options)
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
Float(number)
|
|
99
|
+
begin
|
|
100
|
+
number = Float(number)
|
|
101
101
|
rescue ArgumentError, TypeError
|
|
102
|
-
if options[:raise]
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return number
|
|
106
|
-
end
|
|
102
|
+
raise InvalidNumberError, number if options[:raise]
|
|
103
|
+
|
|
104
|
+
return number
|
|
107
105
|
end
|
|
108
106
|
|
|
109
107
|
defaults = {
|
|
@@ -118,37 +116,45 @@ module SitemapGenerator
|
|
|
118
116
|
}
|
|
119
117
|
defaults = defaults.merge(precision_defaults)
|
|
120
118
|
|
|
121
|
-
|
|
119
|
+
# Allow the user to unset default values: e.g. significant: false
|
|
120
|
+
options = SitemapGenerator::Utilities.reverse_merge(options, defaults)
|
|
122
121
|
precision = options.delete :precision
|
|
123
122
|
significant = options.delete :significant
|
|
124
123
|
strip_insignificant_zeros = options.delete :strip_insignificant_zeros
|
|
125
124
|
|
|
126
|
-
if significant
|
|
127
|
-
if number
|
|
128
|
-
digits
|
|
125
|
+
if significant && precision.positive?
|
|
126
|
+
if number.zero?
|
|
127
|
+
digits = 1
|
|
128
|
+
rounded_number = 0
|
|
129
129
|
else
|
|
130
130
|
digits = (Math.log10(number.abs) + 1).floor
|
|
131
|
-
|
|
131
|
+
step = SitemapGenerator::BigDecimal.new((10**(digits - precision)).to_f.to_s)
|
|
132
|
+
rounded_number = (SitemapGenerator::BigDecimal.new(number.to_s) / step)
|
|
133
|
+
.round.to_f * (10**(digits - precision))
|
|
132
134
|
digits = (Math.log10(rounded_number.abs) + 1).floor # After rounding, the number of digits may have changed
|
|
133
135
|
end
|
|
134
|
-
precision
|
|
135
|
-
precision =
|
|
136
|
+
precision -= digits
|
|
137
|
+
precision = 0 unless precision.positive? # don't let it be negative
|
|
136
138
|
else
|
|
137
|
-
rounded_number = SitemapGenerator::Utilities.round(SitemapGenerator::BigDecimal.new(number.to_s),
|
|
139
|
+
rounded_number = SitemapGenerator::Utilities.round(SitemapGenerator::BigDecimal.new(number.to_s),
|
|
140
|
+
precision).to_f
|
|
138
141
|
end
|
|
139
|
-
formatted_number = number_with_delimiter("%01.#{precision}f"
|
|
142
|
+
formatted_number = number_with_delimiter(format("%01.#{precision}f", rounded_number), options)
|
|
140
143
|
if strip_insignificant_zeros
|
|
141
144
|
escaped_separator = Regexp.escape(options[:separator])
|
|
142
145
|
formatted_number.sub(/(#{escaped_separator})(\d*[1-9])?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '')
|
|
143
146
|
else
|
|
144
147
|
formatted_number
|
|
145
148
|
end
|
|
146
|
-
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
STORAGE_UNITS = [
|
|
150
|
-
DECIMAL_UNITS = {
|
|
151
|
-
|
|
151
|
+
STORAGE_UNITS = %i[byte kb mb gb tb].freeze
|
|
152
|
+
DECIMAL_UNITS = {
|
|
153
|
+
0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand,
|
|
154
|
+
6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion,
|
|
155
|
+
-1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro,
|
|
156
|
+
-9 => :nano, -12 => :pico, -15 => :femto
|
|
157
|
+
}.freeze
|
|
152
158
|
|
|
153
159
|
# Formats the bytes in +number+ into a more understandable representation
|
|
154
160
|
# (e.g., giving it 1500 yields 1.5 KB). This method is useful for
|
|
@@ -160,10 +166,12 @@ module SitemapGenerator
|
|
|
160
166
|
# ==== Options
|
|
161
167
|
# * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
|
|
162
168
|
# * <tt>:precision</tt> - Sets the precision of the number (defaults to 3).
|
|
163
|
-
# * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits.
|
|
169
|
+
# * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits.
|
|
170
|
+
# If +false+, the # of fractional digits (defaults to +true+)
|
|
164
171
|
# * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to ".").
|
|
165
172
|
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
|
|
166
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator
|
|
173
|
+
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator
|
|
174
|
+
# (defaults to +true+)
|
|
167
175
|
# ==== Examples
|
|
168
176
|
# number_to_human_size(123) # => 123 Bytes
|
|
169
177
|
# number_to_human_size(1234) # => 1.21 KB
|
|
@@ -179,17 +187,15 @@ module SitemapGenerator
|
|
|
179
187
|
# <tt>:strip_insignificant_zeros</tt> to +false+ to change that):
|
|
180
188
|
# number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB"
|
|
181
189
|
# number_to_human_size(524288000, :precision=>5) # => "500 MB"
|
|
182
|
-
def number_to_human_size(number, options = {})
|
|
190
|
+
def number_to_human_size(number, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
183
191
|
SitemapGenerator::Utilities.symbolize_keys!(options)
|
|
184
192
|
|
|
185
|
-
|
|
186
|
-
Float(number)
|
|
193
|
+
begin
|
|
194
|
+
number = Float(number)
|
|
187
195
|
rescue ArgumentError, TypeError
|
|
188
|
-
if options[:raise]
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return number
|
|
192
|
-
end
|
|
196
|
+
raise InvalidNumberError, number if options[:raise]
|
|
197
|
+
|
|
198
|
+
return number
|
|
193
199
|
end
|
|
194
200
|
|
|
195
201
|
defaults = {
|
|
@@ -208,13 +214,13 @@ module SitemapGenerator
|
|
|
208
214
|
defaults = defaults.merge(human)
|
|
209
215
|
options = SitemapGenerator::Utilities.reverse_merge(options, defaults)
|
|
210
216
|
# for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
|
|
211
|
-
options[:strip_insignificant_zeros] = true
|
|
217
|
+
options[:strip_insignificant_zeros] = true unless options.key?(:strip_insignificant_zeros)
|
|
212
218
|
|
|
213
219
|
storage_units_format = '%n %u'
|
|
214
220
|
|
|
215
221
|
if number.to_i < 1024
|
|
216
|
-
unit = number.to_i > 1 || number.to_i
|
|
217
|
-
storage_units_format.gsub(
|
|
222
|
+
unit = number.to_i > 1 || number.to_i.zero? ? 'Bytes' : 'Byte'
|
|
223
|
+
storage_units_format.gsub('%n', number.to_i.to_s).gsub('%u', unit)
|
|
218
224
|
else
|
|
219
225
|
max_exp = STORAGE_UNITS.size - 1
|
|
220
226
|
exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024
|
|
@@ -231,7 +237,7 @@ module SitemapGenerator
|
|
|
231
237
|
}
|
|
232
238
|
unit = units[unit_key]
|
|
233
239
|
formatted_number = number_with_precision(number, options)
|
|
234
|
-
storage_units_format.gsub(
|
|
240
|
+
storage_units_format.gsub('%n', formatted_number).gsub('%u', unit)
|
|
235
241
|
end
|
|
236
242
|
end
|
|
237
243
|
end
|
|
@@ -3,15 +3,11 @@
|
|
|
3
3
|
require 'sitemap_generator'
|
|
4
4
|
|
|
5
5
|
module SitemapGenerator
|
|
6
|
-
|
|
7
6
|
# Provide a class for evaluating blocks, making the URL helpers from the framework
|
|
8
7
|
# and API methods available to it.
|
|
9
8
|
class Interpreter
|
|
10
|
-
|
|
11
9
|
if SitemapGenerator.app.is_at_least_rails3?
|
|
12
|
-
|
|
13
|
-
include ::Rails.application.routes.url_helpers
|
|
14
|
-
end
|
|
10
|
+
include ::Rails.application.routes.url_helpers unless ::Rails.application.nil?
|
|
15
11
|
elsif SitemapGenerator.app.is_rails?
|
|
16
12
|
require 'action_controller'
|
|
17
13
|
include ActionController::UrlWriter
|
|
@@ -28,7 +24,7 @@ module SitemapGenerator
|
|
|
28
24
|
opts = SitemapGenerator::Utilities.reverse_merge(opts, link_set: SitemapGenerator::Sitemap)
|
|
29
25
|
@linkset = opts.delete :link_set
|
|
30
26
|
@linkset.send(:set_options, opts)
|
|
31
|
-
eval(&block) if block_given?
|
|
27
|
+
eval(&block) if block_given? # rubocop:disable Security/Eval
|
|
32
28
|
end
|
|
33
29
|
|
|
34
30
|
def add(*args)
|
|
@@ -56,12 +52,12 @@ module SitemapGenerator
|
|
|
56
52
|
# Evaluate the block in the interpreter. Pass :yield_sitemap => true to
|
|
57
53
|
# yield the Interpreter instance to the block...for old-style calling.
|
|
58
54
|
def eval(opts = {}, &block)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
return unless block_given?
|
|
56
|
+
|
|
57
|
+
if opts[:yield_sitemap]
|
|
58
|
+
yield @linkset
|
|
59
|
+
else
|
|
60
|
+
instance_eval(&block)
|
|
65
61
|
end
|
|
66
62
|
end
|
|
67
63
|
|
|
@@ -72,11 +68,11 @@ module SitemapGenerator
|
|
|
72
68
|
# * <tt>:config_file</tt> - full path to the config file to evaluate.
|
|
73
69
|
# Default is config/sitemap.rb in your application's root directory.
|
|
74
70
|
# All other options are passed to +new+.
|
|
75
|
-
def self.run(opts = {}
|
|
71
|
+
def self.run(opts = {})
|
|
76
72
|
opts = opts.dup
|
|
77
73
|
config_file = opts.delete(:config_file)
|
|
78
|
-
config_file ||= SitemapGenerator.app.root + 'config/sitemap.rb'
|
|
79
|
-
interpreter =
|
|
74
|
+
config_file ||= SitemapGenerator.app.root + 'config/sitemap.rb' # rubocop:disable Style/StringConcatenation
|
|
75
|
+
interpreter = new(opts)
|
|
80
76
|
interpreter.instance_eval(File.read(config_file), config_file.to_s)
|
|
81
77
|
interpreter
|
|
82
78
|
end
|