sitemap_generator 5.0.3 → 5.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c25bfb211e9b5d5f074e7565bb9d58fea0c7400
4
- data.tar.gz: 005d8b22093bff792bbeed376ac1c0652c077464
3
+ metadata.gz: 1f409e2e176959553327858497c6817be5f3ceaf
4
+ data.tar.gz: f2d0c65be82f2c8c5a6dd9277903b74a2057a533
5
5
  SHA512:
6
- metadata.gz: 4a13b82ea72040baeb1581c415034786c7687d6fe41893225492af6443a4141747b2b24d8714743e7b3fa8a2e31648788fca8815a9e3c9889dab26068b0a0644
7
- data.tar.gz: 3ae6b41f3b000363c4e47d50fdaed0019585cf2f0800aef83d5503bbbd0ad253532351390297a6f09cabc5e978163190d5ca2142e223e3b5b497b1c47e62d5c4
6
+ metadata.gz: 37b97c0e1b85707fdf4b663f5369017160543687d6d0800d96da7a3071ac749a743ebe58480ceb4f1fc5dfdbb8aa92473af43fc880e325a83a3d244df27fcc92
7
+ data.tar.gz: b2b2899c879a19620c1f7a9bb19e33855234c7c6157e8d13bc3a9468a5b06a74b86d04e09c1a6eac0425d05bcefe918ece2dd7bab37163fd99989baf3103c674
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- sitemap_generator (5.0.3)
4
+ sitemap_generator (5.0.4)
5
5
  builder
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -117,6 +117,7 @@ That's it! Welcome to the future!
117
117
 
118
118
  ## Changelog
119
119
 
120
+ * v5.0.4: Don't include the `media` attribute on alternate links unless it's given
120
121
  * v5.0.3: Add support for Video sitemaps options `:live` and ':requires_subscription'
121
122
  * v5.0.2: Set maximum filesize to 10,000,000 bytes rather than 10,485,760 bytes.
122
123
  * v5.0.1: Include new `SitemapGenerator::FogAdapter` ([#138](https://github.com/kjvarga/sitemap_generator/pull/138)). Fix usage of attr_* methods in LinkSet; don't override custom getters/setters ([#144](https://github.com/kjvarga/sitemap_generator/pull/144)). Fix breaking spec in Ruby 2 ([#142](https://github.com/kjvarga/sitemap_generator/pull/142)). Include Capistrano 3.x tasks ([#141](https://github.com/kjvarga/sitemap_generator/pull/141)).
@@ -1044,7 +1045,7 @@ end
1044
1045
  * `:href` - Required, string.
1045
1046
  * `:lang` - Required, string.
1046
1047
  * `:nofollow` - Optional, boolean. Used to mark link as "nofollow".
1047
- * `:media` - Optional, string. Specify [media][media targets for responsive design pages].
1048
+ * `:media` - Optional, string. Specify [media targets for responsive design pages][media].
1048
1049
 
1049
1050
  ## Raison d'être
1050
1051
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.3
1
+ 5.0.4
@@ -37,8 +37,8 @@ module SitemapGenerator
37
37
  path = sitemap.location.path_in_public
38
38
  end
39
39
 
40
- SitemapGenerator::Utilities.assert_valid_keys(options, :priority, :changefreq, :lastmod, :expires, :host, :images, :video, :geo, :news, :videos, :mobile, :alternate, :alternates, :pagemap)
41
- SitemapGenerator::Utilities.reverse_merge!(options, :priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :images => [], :news => {}, :videos => [], :mobile => false, :alternates => [])
40
+ SitemapGenerator::Utilities.assert_valid_keys(options, :priority, :changefreq, :lastmod, :expires, :host, :images, :video, :geo, :news, :videos, :mobile, :alternate, :alternates, :pagemap, :data)
41
+ SitemapGenerator::Utilities.reverse_merge!(options, :priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :images => [], :news => {}, :videos => [], :mobile => false, :alternates => [], :data => false)
42
42
  raise "Cannot generate a url without a host" unless SitemapGenerator::Utilities.present?(options[:host])
43
43
 
44
44
  if video = options.delete(:video)
@@ -63,7 +63,8 @@ module SitemapGenerator
63
63
  :geo => options[:geo],
64
64
  :mobile => options[:mobile],
65
65
  :alternates => options[:alternates],
66
- :pagemap => options[:pagemap]
66
+ :pagemap => options[:pagemap],
67
+ :data => options[:data]
67
68
  )
68
69
  end
69
70
 
@@ -136,7 +137,9 @@ module SitemapGenerator
136
137
 
137
138
  self[:alternates].each do |alternate|
138
139
  rel = alternate[:nofollow] ? 'alternate nofollow' : 'alternate'
139
- builder.xhtml :link, :rel => rel, :hreflang => alternate[:lang].to_s, :href => alternate[:href].to_s, :media => alternate[:media].to_s
140
+ attributes = { :rel => rel, :hreflang => alternate[:lang].to_s, :href => alternate[:href].to_s }
141
+ attributes[:media] = alternate[:media].to_s if SitemapGenerator::Utilities.present?(alternate[:media])
142
+ builder.xhtml :link, attributes
140
143
  end
141
144
 
142
145
  unless SitemapGenerator::Utilities.blank?(self[:geo])
@@ -161,6 +164,12 @@ module SitemapGenerator
161
164
  end
162
165
  end
163
166
  end
167
+
168
+ unless SitemapGenerator::Utilities.blank?(self[:data])
169
+ builder.data {
170
+ builder.display
171
+ }
172
+ end
164
173
  end
165
174
  builder << '' # Force to string
166
175
  end
@@ -1,6 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "SitemapGenerator" do
4
+ it "should not include media element unless provided" do
5
+ xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html',
6
+ :host => 'http://www.example.com',
7
+ :alternates => [
8
+ {
9
+ :lang => 'de',
10
+ :href => 'http://www.example.de/link_with_alternate.html'
11
+ }
12
+ ]
13
+ ).to_xml
14
+
15
+ doc = Nokogiri::XML.parse("<root xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' xmlns:xhtml='http://www.w3.org/1999/xhtml'>#{xml_fragment}</root>")
16
+ url = doc.css('url')
17
+ url.should_not be_nil
18
+ url.css('loc').text.should == 'http://www.example.com/link_with_alternates.html'
19
+
20
+ alternate = url.at_xpath('xhtml:link')
21
+ alternate.should_not be_nil
22
+ alternate.attribute('rel').value.should == 'alternate'
23
+ alternate.attribute('hreflang').value.should == 'de'
24
+ alternate.attribute('media').should be_nil
25
+ end
4
26
 
5
27
  it "should add alternate links to sitemap" do
6
28
  xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitemap_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3
4
+ version: 5.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Varga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mocha
@@ -93,7 +93,6 @@ files:
93
93
  - lib/sitemap_generator/builder/sitemap_index_file.rb
94
94
  - lib/sitemap_generator/builder/sitemap_index_url.rb
95
95
  - lib/sitemap_generator/builder/sitemap_url.rb
96
- - lib/sitemap_generator/builder/sitemap_url.rb.orig
97
96
  - lib/sitemap_generator/builder.rb
98
97
  - lib/sitemap_generator/core_ext/big_decimal.rb
99
98
  - lib/sitemap_generator/core_ext/numeric.rb
@@ -1,248 +0,0 @@
1
- require 'builder'
2
- require 'uri'
3
- require 'time'
4
- require 'date'
5
-
6
- module SitemapGenerator
7
- module Builder
8
- # A Hash-like class for holding information about a sitemap URL and
9
- # generating an XML <url> element suitable for sitemaps.
10
- class SitemapUrl < Hash
11
-
12
- # Return a new instance with options configured on it.
13
- #
14
- # == Arguments
15
- # * sitemap - a Sitemap instance, or
16
- # * path, options - a path string and options hash
17
- #
18
- # == Options
19
- # Requires a host to be set. If passing a sitemap, the sitemap must have a +default_host+
20
- # configured. If calling with a path and options, you must include the <tt>:host</tt> option.
21
- #
22
- # * +host+
23
- # * +priority+
24
- # * +changefreq+
25
- # * +lastmod+
26
- # * +images+
27
- # * +video+/+videos+
28
- # * +geo+
29
- # * +news+
30
- # * +mobile+
31
- # * +alternate+/+alternates+
32
- # * +pagemap+
33
- def initialize(path, options={})
34
- options = options.dup
35
- if sitemap = path.is_a?(SitemapGenerator::Builder::SitemapFile) && path
36
- SitemapGenerator::Utilities.reverse_merge!(options, :host => sitemap.location.host, :lastmod => sitemap.lastmod)
37
- path = sitemap.location.path_in_public
38
- end
39
-
40
- SitemapGenerator::Utilities.assert_valid_keys(options, :priority, :changefreq, :lastmod, :expires, :host, :images, :video, :geo, :news, :videos, :mobile, :alternate, :alternates, :pagemap)
41
- SitemapGenerator::Utilities.reverse_merge!(options, :priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :images => [], :news => {}, :videos => [], :mobile => false, :alternates => [])
42
- raise "Cannot generate a url without a host" unless SitemapGenerator::Utilities.present?(options[:host])
43
-
44
- if video = options.delete(:video)
45
- options[:videos] = video.is_a?(Array) ? options[:videos].concat(video) : options[:videos] << video
46
- end
47
- if alternate = options.delete(:alternate)
48
- options[:alternates] = alternate.is_a?(Array) ? options[:alternates].concat(alternate) : options[:alternates] << alternate
49
- end
50
-
51
- path = path.to_s.sub(/^\//, '')
52
- loc = path.empty? ? options[:host] : (options[:host].to_s.sub(/\/$/, '') + '/' + path)
53
- self.merge!(
54
- :priority => options[:priority],
55
- :changefreq => options[:changefreq],
56
- :lastmod => options[:lastmod],
57
- :expires => options[:expires],
58
- :host => options[:host],
59
- :loc => loc,
60
- :images => prepare_images(options[:images], options[:host]),
61
- :news => prepare_news(options[:news]),
62
- :videos => options[:videos],
63
- :geo => options[:geo],
64
- :mobile => options[:mobile],
65
- :alternates => options[:alternates],
66
- :pagemap => options[:pagemap]
67
- )
68
- end
69
-
70
- # Return the URL as XML
71
- def to_xml(builder=nil)
72
- builder = ::Builder::XmlMarkup.new if builder.nil?
73
- builder.url do
74
- builder.loc self[:loc]
75
- builder.lastmod w3c_date(self[:lastmod]) if self[:lastmod]
76
- builder.expires w3c_date(self[:expires]) if self[:expires]
77
- builder.changefreq self[:changefreq].to_s if self[:changefreq]
78
- builder.priority format_float(self[:priority]) if self[:priority]
79
-
80
- unless SitemapGenerator::Utilities.blank?(self[:news])
81
- news_data = self[:news]
82
- builder.news:news do
83
- builder.news:publication do
84
- builder.news :name, news_data[:publication_name].to_s if news_data[:publication_name]
85
- builder.news :language, news_data[:publication_language].to_s if news_data[:publication_language]
86
- end
87
-
88
- builder.news :access, news_data[:access].to_s if news_data[:access]
89
- builder.news :genres, news_data[:genres].to_s if news_data[:genres]
90
- builder.news :publication_date, w3c_date(news_data[:publication_date]) if news_data[:publication_date]
91
- builder.news :title, news_data[:title].to_s if news_data[:title]
92
- builder.news :keywords, news_data[:keywords].to_s if news_data[:keywords]
93
- builder.news :stock_tickers, news_data[:stock_tickers].to_s if news_data[:stock_tickers]
94
- end
95
- end
96
-
97
- self[:images].each do |image|
98
- builder.image:image do
99
- builder.image :loc, image[:loc]
100
- builder.image :caption, image[:caption].to_s if image[:caption]
101
- builder.image :geo_location, image[:geo_location].to_s if image[:geo_location]
102
- builder.image :title, image[:title].to_s if image[:title]
103
- builder.image :license, image[:license].to_s if image[:license]
104
- end
105
- end
106
-
107
- self[:videos].each do |video|
108
- builder.video :video do
109
- builder.video :thumbnail_loc, video[:thumbnail_loc].to_s
110
- builder.video :title, video[:title].to_s
111
- builder.video :description, video[:description].to_s
112
- builder.video :content_loc, video[:content_loc].to_s if video[:content_loc]
113
- if video[:player_loc]
114
- loc_attributes = { :allow_embed => yes_or_no_with_default(video[:allow_embed], true) }
115
- loc_attributes[:autoplay] = video[:autoplay].to_s if SitemapGenerator::Utilities.present?(video[:autoplay])
116
- builder.video :player_loc, video[:player_loc].to_s, loc_attributes
117
- end
118
- builder.video :duration, video[:duration].to_s if video[:duration]
119
- builder.video :expiration_date, w3c_date(video[:expiration_date]) if video[:expiration_date]
120
- builder.video :rating, format_float(video[:rating]) if video[:rating]
121
- builder.video :view_count, video[:view_count].to_s if video[:view_count]
122
- builder.video :publication_date, w3c_date(video[:publication_date]) if video[:publication_date]
123
- video[:tags].each {|tag| builder.video :tag, tag.to_s } if video[:tags]
124
- builder.video :tag, video[:tag].to_s if video[:tag]
125
- builder.video :category, video[:category].to_s if video[:category]
126
- builder.video :family_friendly, yes_or_no_with_default(video[:family_friendly], true) if video.has_key?(:family_friendly)
127
- builder.video :gallery_loc, video[:gallery_loc].to_s, :title => video[:gallery_title].to_s if video[:gallery_loc]
128
- builder.video :price, video[:price].to_s, prepare_video_price_attribs(video) if SitemapGenerator::Utilities.present?(video[:price])
129
- if video[:uploader]
130
- builder.video :uploader, video[:uploader].to_s, video[:uploader_info] ? { :info => video[:uploader_info].to_s } : {}
131
- end
132
- end
133
- end
134
-
135
- self[:alternates].each do |alternate|
136
- rel = alternate[:nofollow] ? 'alternate nofollow' : 'alternate'
137
- <<<<<<< HEAD
138
- builder.xhtml :link, :rel => rel, :hreflang => alternate[:lang].to_s, :href => alternate[:href].to_s
139
- =======
140
- builder.xhtml :link, :rel => rel, :hreflang => alternate[:lang], :href => alternate[:href], :media => alternate[:media]
141
- >>>>>>> ddeebe0aa558b4ecc08c7e8d5324842205d20b79
142
- end
143
-
144
- unless SitemapGenerator::Utilities.blank?(self[:geo])
145
- geo = self[:geo]
146
- builder.geo :geo do
147
- builder.geo :format, geo[:format].to_s if geo[:format]
148
- end
149
- end
150
-
151
- unless SitemapGenerator::Utilities.blank?(self[:mobile])
152
- builder.mobile :mobile
153
- end
154
-
155
- unless SitemapGenerator::Utilities.blank?(self[:pagemap])
156
- builder.pagemap :PageMap do
157
- SitemapGenerator::Utilities.as_array(self[:pagemap][:dataobjects]).each do |dataobject|
158
- builder.pagemap :DataObject, :type => dataobject[:type].to_s, :id => dataobject[:id].to_s do
159
- SitemapGenerator::Utilities.as_array(dataobject[:attributes]).each do |attribute|
160
- builder.pagemap :Attribute, attribute[:value].to_s, :name => attribute[:name].to_s
161
- end
162
- end
163
- end
164
- end
165
- end
166
- end
167
- builder << '' # Force to string
168
- end
169
-
170
- def news?
171
- SitemapGenerator::Utilities.present?(self[:news])
172
- end
173
-
174
- protected
175
-
176
- def prepare_video_price_attribs(video)
177
- attribs = {}
178
- attribs[:currency] = video[:price_currency].to_s # required
179
- attribs[:type] = video[:price_type] if SitemapGenerator::Utilities.present?(video[:price_type])
180
- attribs[:resolution] = video[:price_resolution] if SitemapGenerator::Utilities.present?(video[:price_resolution])
181
- attribs
182
- end
183
-
184
- def prepare_news(news)
185
- SitemapGenerator::Utilities.assert_valid_keys(news, :publication_name, :publication_language, :publication_date, :genres, :access, :title, :keywords, :stock_tickers) unless news.empty?
186
- news
187
- end
188
-
189
- # Return an Array of image option Hashes suitable to be parsed by SitemapGenerator::Builder::SitemapFile
190
- def prepare_images(images, host)
191
- images.delete_if { |key,value| key[:loc] == nil }
192
- images.each do |r|
193
- SitemapGenerator::Utilities.assert_valid_keys(r, :loc, :caption, :geo_location, :title, :license)
194
- r[:loc] = URI.join(host, r[:loc]).to_s
195
- end
196
- images[0..(SitemapGenerator::MAX_SITEMAP_IMAGES-1)]
197
- end
198
-
199
- def w3c_date(date)
200
- if date.is_a?(String)
201
- date
202
- elsif date.respond_to?(:iso8601)
203
- date.iso8601.sub(/Z$/i, '+00:00')
204
- elsif date.is_a?(Date) && !date.is_a?(DateTime)
205
- date.strftime("%Y-%m-%d")
206
- else
207
- zulutime = if date.is_a?(DateTime)
208
- date.new_offset(0)
209
- elsif date.respond_to?(:utc)
210
- date.utc
211
- else
212
- nil
213
- end
214
-
215
- if zulutime
216
- zulutime.strftime("%Y-%m-%dT%H:%M:%S+00:00")
217
- else
218
- zone = date.strftime('%z').insert(-3, ':')
219
- date.strftime("%Y-%m-%dT%H:%M:%S") + zone
220
- end
221
- end
222
- end
223
-
224
- # Accept a string or boolean and return 'yes' or 'no'. If a string, the
225
- # value must be 'yes' or 'no'. Pass the default value as a boolean using `default`.
226
- def yes_or_no(value)
227
- if value.is_a?(String)
228
- raise ArgumentError.new("Unrecognized value for yes/no field: #{value.inspect}") unless value =~ /^(yes|no)$/i
229
- value.downcase
230
- else
231
- value ? 'yes' : 'no'
232
- end
233
- end
234
-
235
- # If the value is nil, return `default` converted to either 'yes' or 'no'.
236
- # If the value is set, return its value converted to 'yes' or 'no'.
237
- def yes_or_no_with_default(value, default)
238
- yes_or_no(value.nil? ? default : value)
239
- end
240
-
241
- # Format a float to to one decimal precision.
242
- # TODO: Use rounding with precision once merged with framework_agnostic.
243
- def format_float(value)
244
- value.is_a?(String) ? value : ('%0.1f' % value)
245
- end
246
- end
247
- end
248
- end