xml-sitemap 1.1.3 → 1.3.3

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.
@@ -0,0 +1,185 @@
1
+ module XmlSitemap
2
+ module RenderEngine
3
+ private
4
+
5
+ # Render with Nokogiri gem
6
+ #
7
+ def render_nokogiri
8
+ unless defined? Nokogiri
9
+ raise ArgumentError, "Nokogiri not found!"
10
+ end
11
+
12
+ builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
13
+ xml.urlset(XmlSitemap::MAP_SCHEMA_OPTIONS) { |s|
14
+ @items.each do |item|
15
+ s.url do |u|
16
+ u.loc item.target
17
+
18
+ # Format and image tag specifications found at http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636
19
+ if item.image_location
20
+ u["image"].image do |a|
21
+ a["image"].loc item.image_location
22
+ a["image"].caption item.image_caption if item.image_caption
23
+ a["image"].title item.image_title if item.image_title
24
+ a["image"].license item.image_license if item.image_license
25
+ a["image"].geo_location item.image_geolocation if item.image_geolocation
26
+ end
27
+ end
28
+
29
+ # Format and video tag specifications found at http://support.google.com/webmasters/bin/answer.py?hl=en&answer=80472&topic=10079&ctx=topic#2
30
+ if item.video_thumbnail_location && item.video_title && item.video_description && (item.video_content_location || item.video_player_location)
31
+ u["video"].video do |a|
32
+ a["video"].thumbnail_loc item.video_thumbnail_location
33
+ a["video"].title item.video_title
34
+ a["video"].description item.video_description
35
+ a["video"].content_loc item.video_content_location if item.video_content_location
36
+ a["video"].player_loc item.video_player_location if item.video_player_location
37
+ a["video"].duration item.video_duration.to_s if item.video_duration
38
+ a["video"].expiration_date item.video_expiration_date_value if item.video_expiration_date
39
+ a["video"].rating item.video_rating.to_s if item.video_rating
40
+ a["video"].view_count item.video_view_count.to_s if item.video_view_count
41
+ a["video"].publication_date item.video_publication_date_value if item.video_publication_date
42
+ a["video"].family_friendly item.video_family_friendly if item.video_family_friendly
43
+ a["video"].category item.video_category if item.video_category
44
+ a["video"].restriction item.video_restriction, :relationship => "allow" if item.video_restriction
45
+ a["video"].gallery_loc item.video_gallery_location if item.video_gallery_location
46
+ a["video"].price item.video_price.to_s, :currency => "USD" if item.video_price
47
+ a["video"].requires_subscription item.video_requires_subscription if item.video_requires_subscription
48
+ a["video"].uploader item.video_uploader if item.video_uploader
49
+ a["video"].platform item.video_platform, :relationship => "allow" if item.video_platform
50
+ a["video"].live item.video_live if item.video_live
51
+ end
52
+ end
53
+
54
+ u.lastmod item.lastmod_value
55
+ u.changefreq item.changefreq.to_s if item.changefreq
56
+ u.priority item.priority.to_s if item.priority
57
+ end
58
+ end
59
+ }
60
+ end
61
+ builder.to_xml
62
+ end
63
+
64
+ # Render with Builder gem
65
+ #
66
+ def render_builder
67
+ xml = Builder::XmlMarkup.new(:indent => 2)
68
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
69
+
70
+ xml.urlset(XmlSitemap::MAP_SCHEMA_OPTIONS) { |s|
71
+ @items.each do |item|
72
+ s.url do |u|
73
+ u.loc item.target
74
+
75
+ # Format and image tag specifications found at http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636
76
+ if item.image_location
77
+ u.image :image do |a|
78
+ a.tag! "image:loc", CGI::escapeHTML(item.image_location)
79
+ a.tag! "image:caption", CGI::escapeHTML(item.image_caption) if item.image_caption
80
+ a.tag! "image:title", CGI::escapeHTML(item.image_title) if item.image_title
81
+ a.tag! "image:license", CGI::escapeHTML(item.image_license) if item.image_license
82
+ a.tag! "image:geo_location", CGI::escapeHTML(item.image_geolocation) if item.image_geolocation
83
+ end
84
+ end
85
+
86
+ # Format and video tag specifications found at http://support.google.com/webmasters/bin/answer.py?hl=en&answer=80472&topic=10079&ctx=topic#2
87
+ if item.video_thumbnail_location && item.video_title && item.video_description && (item.video_content_location || item.video_player_location)
88
+ u.video :video do |a|
89
+ a.tag! "video:thumbnail_loc", CGI::escapeHTML(item.video_thumbnail_location)
90
+ a.tag! "video:title", CGI::escapeHTML(item.video_title)
91
+ a.tag! "video:description", CGI::escapeHTML(item.video_description)
92
+ a.tag! "video:content_loc", CGI::escapeHTML(item.video_content_location) if item.video_content_location
93
+ a.tag! "video:player_loc", CGI::escapeHTML(item.video_player_location) if item.video_player_location
94
+ a.tag! "video:duration", CGI::escapeHTML(item.video_duration.to_s) if item.video_duration
95
+ a.tag! "video:expiration_date", CGI::escapeHTML(item.video_expiration_date_value) if item.video_expiration_date
96
+ a.tag! "video:rating", CGI::escapeHTML(item.video_rating.to_s) if item.video_rating
97
+ a.tag! "video:view_count", CGI::escapeHTML(item.video_view_count.to_s) if item.video_view_count
98
+ a.tag! "video:publication_date", CGI::escapeHTML(item.video_publication_date_value) if item.video_publication_date
99
+ a.tag! "video:family_friendly", CGI::escapeHTML(item.video_family_friendly) if item.video_family_friendly
100
+ a.tag! "video:category", CGI::escapeHTML(item.video_category) if item.video_category
101
+ a.tag! "video:restriction", CGI::escapeHTML(item.video_restriction), :relationship => "allow" if item.video_restriction
102
+ a.tag! "video:gallery_loc", CGI::escapeHTML(item.video_gallery_location) if item.video_gallery_location
103
+ a.tag! "video:price", CGI::escapeHTML(item.video_price.to_s), :currency => "USD" if item.video_price
104
+ a.tag! "video:requires_subscription", CGI::escapeHTML(item.video_requires_subscription) if item.video_requires_subscription
105
+ a.tag! "video:uploader", CGI::escapeHTML(item.video_uploader) if item.video_uploader
106
+ a.tag! "video:platform", CGI::escapeHTML(item.video_platform), :relationship => "allow" if item.video_platform
107
+ a.tag! "video:live", CGI::escapeHTML(item.video_live) if item.video_live
108
+ end
109
+ end
110
+
111
+ u.lastmod item.lastmod_value
112
+ u.changefreq item.changefreq.to_s if item.changefreq
113
+ u.priority item.priority.to_s if item.priority
114
+ end
115
+ end
116
+ }.to_s
117
+ end
118
+
119
+ # Render with plain strings
120
+ #
121
+ def render_string
122
+ result = '<?xml version="1.0" encoding="UTF-8"?>' + "\n<urlset"
123
+
124
+ XmlSitemap::MAP_SCHEMA_OPTIONS.each do |key, val|
125
+ result << ' ' + key + '="' + val + '"'
126
+ end
127
+
128
+ result << ">\n"
129
+
130
+ item_results = []
131
+ @items.each do |item|
132
+ item_string = " <url>\n"
133
+ item_string << " <loc>#{CGI::escapeHTML(item.target)}</loc>\n"
134
+
135
+ # Format and image tag specifications found at http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636
136
+ if item.image_location
137
+ item_string << " <image:image>\n"
138
+ item_string << " <image:loc>#{CGI::escapeHTML(item.image_location)}</image:loc>\n"
139
+ item_string << " <image:caption>#{CGI::escapeHTML(item.image_caption)}</image:caption>\n" if item.image_caption
140
+ item_string << " <image:title>#{CGI::escapeHTML(item.image_title)}</image:title>\n" if item.image_title
141
+ item_string << " <image:license>#{CGI::escapeHTML(item.image_license)}</image:license>\n" if item.image_license
142
+ item_string << " <image:geo_location>#{CGI::escapeHTML(item.image_geolocation)}</image:geo_location>\n" if item.image_geolocation
143
+ item_string << " </image:image>\n"
144
+ end
145
+
146
+ # Format and video tag specifications found at http://support.google.com/webmasters/bin/answer.py?hl=en&answer=80472&topic=10079&ctx=topic#2
147
+ if item.video_thumbnail_location && item.video_title && item.video_description && (item.video_content_location || item.video_player_location)
148
+ item_string << " <video:video>\n"
149
+ item_string << " <video:thumbnail_loc>#{CGI::escapeHTML(item.video_thumbnail_location)}</video:thumbnail_loc>\n"
150
+ item_string << " <video:title>#{CGI::escapeHTML(item.video_title)}</video:title>\n"
151
+ item_string << " <video:description>#{CGI::escapeHTML(item.video_description)}</video:description>\n"
152
+ item_string << " <video:content_loc>#{CGI::escapeHTML(item.video_content_location)}</video:content_loc>\n" if item.video_content_location
153
+ item_string << " <video:player_loc>#{CGI::escapeHTML(item.video_player_location)}</video:player_loc>\n" if item.video_player_location
154
+ item_string << " <video:duration>#{CGI::escapeHTML(item.video_duration.to_s)}</video:duration>\n" if item.video_duration
155
+ item_string << " <video:expiration_date>#{item.video_expiration_date_value}</video:expiration_date>\n" if item.video_expiration_date
156
+ item_string << " <video:rating>#{CGI::escapeHTML(item.video_rating.to_s)}</video:rating>\n" if item.video_rating
157
+ item_string << " <video:view_count>#{CGI::escapeHTML(item.video_view_count.to_s)}</video:view_count>\n" if item.video_view_count
158
+ item_string << " <video:publication_date>#{item.video_publication_date_value}</video:publication_date>\n" if item.video_publication_date
159
+ item_string << " <video:family_friendly>#{CGI::escapeHTML(item.video_family_friendly)}</video:family_friendly>\n" if item.video_family_friendly
160
+ item_string << " <video:category>#{CGI::escapeHTML(item.video_category)}</video:category>\n" if item.video_category
161
+ item_string << " <video:restriction relationship=\"allow\">#{CGI::escapeHTML(item.video_restriction)}</video:restriction>\n" if item.video_restriction
162
+ item_string << " <video:gallery_loc>#{CGI::escapeHTML(item.video_gallery_location)}</video:gallery_loc>\n" if item.video_gallery_location
163
+ item_string << " <video:price currency=\"USD\">#{CGI::escapeHTML(item.video_price.to_s)}</video:price>\n" if item.video_price
164
+ item_string << " <video:requires_subscription>#{CGI::escapeHTML(item.video_requires_subscription)}</video:requires_subscription>\n" if item.video_requires_subscription
165
+ item_string << " <video:uploader>#{CGI::escapeHTML(item.video_uploader)}</video:uploader>\n" if item.video_uploader
166
+ item_string << " <video:platform relationship=\"allow\">#{CGI::escapeHTML(item.video_platform)}</video:platform>\n" if item.video_platform
167
+ item_string << " <video:live>#{CGI::escapeHTML(item.video_live)}</video:live>\n" if item.video_live
168
+ item_string << " </video:video>\n"
169
+ end
170
+
171
+ item_string << " <lastmod>#{item.lastmod_value}</lastmod>\n"
172
+ item_string << " <changefreq>#{item.changefreq}</changefreq>\n" if item.changefreq
173
+ item_string << " <priority>#{item.priority}</priority>\n" if item.priority
174
+ item_string << " </url>\n"
175
+
176
+ item_results << item_string
177
+ end
178
+
179
+ result << item_results.join("")
180
+ result << "</urlset>\n"
181
+
182
+ result
183
+ end
184
+ end
185
+ end
@@ -1,3 +1,9 @@
1
1
  module XmlSitemap
2
- VERSION = '1.1.3'
2
+ unless defined?(::XmlSitemap::VERSION)
3
+ VERSION = "1.3.3"
4
+ end
5
+
6
+ def self.version
7
+ XmlSitemap::VERSION
8
+ end
3
9
  end
data/lib/xml-sitemap.rb CHANGED
@@ -2,8 +2,16 @@ require 'time'
2
2
  require 'date'
3
3
  require 'zlib'
4
4
  require 'builder'
5
+ require 'cgi'
6
+ begin
7
+ require 'nokogiri'
8
+ rescue LoadError
9
+ end
5
10
 
11
+ require 'xml-sitemap/version'
6
12
  require 'xml-sitemap/options'
13
+ require 'xml-sitemap/render_engine'
14
+ require 'xml-sitemap/item'
7
15
  require 'xml-sitemap/map'
8
16
  require 'xml-sitemap/index'
9
17
 
@@ -1,3 +1,3 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
- </urlset>
2
+ <sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ </sitemapindex>
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ <url>
4
+ <loc>http://foobar.com/</loc>
5
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
6
+ <priority>1.0</priority>
7
+ </url>
8
+ <url>
9
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=image support string</loc>
10
+ <image:image>
11
+ <image:loc>http://foobar.com/foo.gif</image:loc>
12
+ </image:image>
13
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
14
+ </url>
15
+ <url>
16
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=image support string</loc>
17
+ <image:image>
18
+ <image:loc>http://foobar.com/foo.gif</image:loc>
19
+ <image:title>Image Title</image:title>
20
+ </image:image>
21
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
22
+ </url>
23
+ <url>
24
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=image support string</loc>
25
+ <image:image>
26
+ <image:loc>http://foobar.com/foo.gif</image:loc>
27
+ <image:caption>Image Caption</image:caption>
28
+ </image:image>
29
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
30
+ </url>
31
+ <url>
32
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=image support string</loc>
33
+ <image:image>
34
+ <image:loc>http://foobar.com/foo.gif</image:loc>
35
+ <image:license>Image License</image:license>
36
+ </image:image>
37
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
38
+ </url>
39
+ <url>
40
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=image support string</loc>
41
+ <image:image>
42
+ <image:loc>http://foobar.com/foo.gif</image:loc>
43
+ <image:geo_location>Image GeoLocation</image:geo_location>
44
+ </image:image>
45
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
46
+ </url>
47
+ <url>
48
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=image support string</loc>
49
+ <image:image>
50
+ <image:loc>http://foobar.com/foo.gif</image:loc>
51
+ <image:caption>Image Caption</image:caption>
52
+ <image:title>Image Title</image:title>
53
+ <image:license>Image License</image:license>
54
+ <image:geo_location>Image GeoLocation</image:geo_location>
55
+ </image:image>
56
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
57
+ </url>
58
+ </urlset>
@@ -3,13 +3,10 @@
3
3
  <url>
4
4
  <loc>http://foobar.com/</loc>
5
5
  <lastmod>2011-06-01T00:00:01Z</lastmod>
6
- <changefreq>weekly</changefreq>
7
6
  <priority>1.0</priority>
8
7
  </url>
9
8
  <url>
10
9
  <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=sample string</loc>
11
10
  <lastmod>2011-06-01T00:00:01Z</lastmod>
12
- <changefreq>weekly</changefreq>
13
- <priority>0.5</priority>
14
11
  </url>
15
12
  </urlset>
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ <url>
4
+ <loc>http://foobar.com/</loc>
5
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
6
+ <priority>1.0</priority>
7
+ </url>
8
+ <url>
9
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=video</loc>
10
+ <video:video>
11
+ <video:thumbnail_loc>http://foobar.com/foo.jpg</video:thumbnail_loc>
12
+ <video:title>Video Title</video:title>
13
+ <video:description>Video Description</video:description>
14
+ <video:content_loc>http://foobar.com/foo.mp4</video:content_loc>
15
+ </video:video>
16
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
17
+ </url>
18
+ <url>
19
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=video</loc>
20
+ <video:video>
21
+ <video:thumbnail_loc>http://foobar.com/foo.jpg</video:thumbnail_loc>
22
+ <video:title>Video Title</video:title>
23
+ <video:description>Video Description</video:description>
24
+ <video:player_loc>http://foobar.com/foo.swf</video:player_loc>
25
+ </video:video>
26
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
27
+ </url>
28
+ <url>
29
+ <loc>http://foobar.com/path?a=b&amp;c=d&amp;e=video</loc>
30
+ <video:video>
31
+ <video:thumbnail_loc>http://foobar.com/foo.jpg</video:thumbnail_loc>
32
+ <video:title>Video Title</video:title>
33
+ <video:description>Video Description</video:description>
34
+ <video:content_loc>http://foobar.com/foo.mp4</video:content_loc>
35
+ <video:player_loc>http://foobar.com/foo.swf</video:player_loc>
36
+ <video:duration>180</video:duration>
37
+ <video:expiration_date>2012-06-01T00:00:01Z</video:expiration_date>
38
+ <video:rating>3.5</video:rating>
39
+ <video:view_count>2500</video:view_count>
40
+ <video:publication_date>2011-06-01T00:00:01Z</video:publication_date>
41
+ <video:family_friendly>no</video:family_friendly>
42
+ <video:category>Video Category</video:category>
43
+ <video:restriction relationship="allow">IT</video:restriction>
44
+ <video:gallery_loc>http://foobar.com/foo.mpu</video:gallery_loc>
45
+ <video:price currency="USD">20</video:price>
46
+ <video:requires_subscription>no</video:requires_subscription>
47
+ <video:uploader>Video Uploader</video:uploader>
48
+ <video:platform relationship="allow">web</video:platform>
49
+ <video:live>no</video:live>
50
+ </video:video>
51
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
52
+ </url>
53
+ </urlset>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
2
+ <sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
3
  <sitemap>
4
4
  <loc>http://foobar.com/first-0.xml</loc>
5
5
  <lastmod>2011-06-01T00:00:01Z</lastmod>
@@ -16,4 +16,4 @@
16
16
  <loc>http://foobar.com/third-0.xml</loc>
17
17
  <lastmod>2011-06-01T00:00:01Z</lastmod>
18
18
  </sitemap>
19
- </urlset>
19
+ </sitemapindex>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
2
+ <sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
3
  <sitemap>
4
4
  <loc>http://foobar.com/sitemap-0.xml</loc>
5
5
  <lastmod>2011-06-01T00:00:01Z</lastmod>
@@ -8,4 +8,4 @@
8
8
  <loc>http://foobar.com/sitemap-1.xml</loc>
9
9
  <lastmod>2011-06-01T00:00:01Z</lastmod>
10
10
  </sitemap>
11
- </urlset>
11
+ </sitemapindex>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ <sitemap>
4
+ <loc>https://foobar.com/sitemap-0.xml</loc>
5
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
6
+ </sitemap>
7
+ <sitemap>
8
+ <loc>https://foobar.com/sitemap-1.xml</loc>
9
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
10
+ </sitemap>
11
+ </sitemapindex>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ <sitemap>
4
+ <loc>http://one.foobar.com/sitemap.xml</loc>
5
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
6
+ </sitemap>
7
+ <sitemap>
8
+ <loc>http://two.foobar.com/sitemap.xml</loc>
9
+ <lastmod>2011-06-01T00:00:01Z</lastmod>
10
+ </sitemap>
11
+ </sitemapindex>
@@ -3,25 +3,18 @@
3
3
  <url>
4
4
  <loc>http://foobar.com/</loc>
5
5
  <lastmod>2011-06-01T00:00:01Z</lastmod>
6
- <changefreq>weekly</changefreq>
7
6
  <priority>1.0</priority>
8
7
  </url>
9
8
  <url>
10
9
  <loc>http://foobar.com/about</loc>
11
10
  <lastmod>2011-06-01T00:00:01Z</lastmod>
12
- <changefreq>weekly</changefreq>
13
- <priority>0.5</priority>
14
11
  </url>
15
12
  <url>
16
13
  <loc>http://foobar.com/terms</loc>
17
14
  <lastmod>2011-06-01T00:00:01Z</lastmod>
18
- <changefreq>weekly</changefreq>
19
- <priority>0.5</priority>
20
15
  </url>
21
16
  <url>
22
17
  <loc>http://foobar.com/privacy</loc>
23
18
  <lastmod>2011-06-01T00:00:01Z</lastmod>
24
- <changefreq>weekly</changefreq>
25
- <priority>0.5</priority>
26
19
  </url>
27
20
  </urlset>
@@ -6,4 +6,4 @@
6
6
  <changefreq>monthly</changefreq>
7
7
  <priority>0.8</priority>
8
8
  </url>
9
- </urlset>
9
+ </urlset>
data/spec/index_spec.rb CHANGED
@@ -1,70 +1,95 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe XmlSitemap::Index do
4
- before :all do
5
- @base_time = Time.gm(2011, 6, 1, 0, 0, 1)
6
- end
7
-
8
- it 'should be valid if no sitemaps were supplied' do
9
- index = XmlSitemap::Index.new
10
- index.render.should == fixture('empty_index.xml')
11
- end
12
-
13
- it 'should raise error if passing a wrong object' do
14
- index = XmlSitemap::Index.new
15
- proc { index.add(nil) }.should raise_error ArgumentError, 'XmlSitemap::Map object requred!'
16
- end
17
-
18
- it 'should raise error if passing an empty sitemap' do
19
- map = XmlSitemap::Map.new('foobar.com', :home => false)
20
- index = XmlSitemap::Index.new
21
- proc { index.add(map) }.should raise_error ArgumentError, 'Map is empty!'
22
- end
23
-
24
- it 'should render a proper index' do
25
- m1 = XmlSitemap::Map.new('foobar.com', :time => @base_time) { |m| m.add('about') }
26
- m2 = XmlSitemap::Map.new('foobar.com', :time => @base_time) { |m| m.add('about') }
27
-
28
- index = XmlSitemap::Index.new do |i|
29
- i.add(m1)
30
- i.add(m2)
4
+ let(:base_time) { Time.gm(2011, 6, 1, 0, 0, 1) }
5
+
6
+ describe '#new' do
7
+ it 'should be valid if no sitemaps were supplied' do
8
+ index = XmlSitemap::Index.new
9
+ index.render.split("\n")[2..-1].join("\n").should == fixture('empty_index.xml').split("\n")[2..-1].join("\n")
10
+ end
11
+
12
+ it 'should raise error if passing a wrong object' do
13
+ index = XmlSitemap::Index.new
14
+ expect { index.add(nil) }.to raise_error ArgumentError, 'XmlSitemap::Map object required!'
15
+ end
16
+
17
+ it 'should raise error if passing an empty sitemap' do
18
+ map = XmlSitemap::Map.new('foobar.com', :home => false)
19
+ index = XmlSitemap::Index.new
20
+ expect { index.add(map) }.to raise_error ArgumentError, 'Map is empty!'
31
21
  end
32
-
33
- index.render.should == fixture('sample_index.xml')
34
22
  end
35
-
36
- it 'should save index contents to the filesystem' do
37
- m1 = XmlSitemap::Map.new('foobar.com', :time => @base_time) { |m| m.add('about') }
38
- m2 = XmlSitemap::Map.new('foobar.com', :time => @base_time) { |m| m.add('about') }
39
-
40
- index = XmlSitemap::Index.new do |i|
41
- i.add(m1)
42
- i.add(m2)
23
+
24
+ describe '#render' do
25
+ it 'renders a proper index' do
26
+ m1 = XmlSitemap::Map.new('foobar.com', :time => base_time) { |m| m.add('about') }
27
+ m2 = XmlSitemap::Map.new('foobar.com', :time => base_time) { |m| m.add('about') }
28
+
29
+ index = XmlSitemap::Index.new do |i|
30
+ i.add(m1)
31
+ i.add(m2)
32
+ end
33
+
34
+ index.render.split("\n")[2..-1].join("\n").should == fixture('sample_index.xml').split("\n")[2..-1].join("\n")
35
+ end
36
+
37
+ it 'renders a proper index with the secure option' do
38
+ m1 = XmlSitemap::Map.new('foobar.com', :time => base_time) { |m| m.add('about') }
39
+ m2 = XmlSitemap::Map.new('foobar.com', :time => base_time) { |m| m.add('about') }
40
+
41
+ index = XmlSitemap::Index.new(:secure => true) do |i|
42
+ i.add(m1)
43
+ i.add(m2)
44
+ end
45
+
46
+ index.render.split("\n")[2..-1].join("\n").should == fixture('sample_index_secure.xml').split("\n")[2..-1].join("\n")
47
+ end
48
+
49
+ it 'renders a proper index for multiple subdomains' do
50
+ m1 = XmlSitemap::Map.new('one.foobar.com', :time => base_time) { |m| m.add('about') }
51
+ m2 = XmlSitemap::Map.new('two.foobar.com', :time => base_time) { |m| m.add('about') }
52
+
53
+ index = XmlSitemap::Index.new do |i|
54
+ i.add(m1, false)
55
+ i.add(m2, false)
56
+ end
57
+
58
+ index.render.split("\n")[2..-1].join("\n").should == fixture('sample_many_subdomains_index.xml').split("\n")[2..-1].join("\n")
43
59
  end
44
-
45
- path = "/tmp/index_#{Time.now.to_i}.xml"
46
- index.render_to(path)
47
- File.read(path).should == fixture('sample_index.xml')
48
- File.delete(path) if File.exists?(path)
49
60
  end
50
-
51
- it 'should have separate running offsets for different map groups' do
52
- m1 = XmlSitemap::Map.new('foobar.com', :time => @base_time, :group => "first") { |m| m.add('about') }
53
- m2 = XmlSitemap::Map.new('foobar.com', :time => @base_time, :group => "second") { |m| m.add('about') }
54
- m3 = XmlSitemap::Map.new('foobar.com', :time => @base_time, :group => "second") { |m| m.add('about') }
55
- m4 = XmlSitemap::Map.new('foobar.com', :time => @base_time, :group => "third") { |m| m.add('about') }
56
-
57
- index = XmlSitemap::Index.new do |i|
58
- i.add(m1)
59
- i.add(m2)
60
- i.add(m3)
61
- i.add(m4)
61
+
62
+ describe '#render_to' do
63
+ let(:index_path) { "/tmp/xml_index.xml" }
64
+
65
+ after :all do
66
+ File.delete_if_exists(index_path)
67
+ end
68
+
69
+ it 'saves index contents to the filesystem' do
70
+ m1 = XmlSitemap::Map.new('foobar.com', :time => base_time) { |m| m.add('about') }
71
+ m2 = XmlSitemap::Map.new('foobar.com', :time => base_time) { |m| m.add('about') }
72
+
73
+ index = XmlSitemap::Index.new do |i|
74
+ i.add(m1)
75
+ i.add(m2)
76
+ end
77
+
78
+ index.render_to(index_path)
79
+ File.read(index_path).split("\n")[2..-1].join("\n").should eq(fixture('sample_index.xml').split("\n")[2..-1].join("\n"))
80
+ end
81
+
82
+ it 'should have separate running offsets for different map groups' do
83
+ maps = %w(first second second third).map do |name|
84
+ XmlSitemap::Map.new('foobar.com', :time => base_time, :group => name) { |m| m.add('about') }
85
+ end
86
+
87
+ index = XmlSitemap::Index.new do |i|
88
+ maps.each { |m| i.add(m) }
89
+ end
90
+
91
+ index.render_to(index_path)
92
+ File.read(index_path).split("\n")[2..-1].join("\n").should eq(fixture('group_index.xml').split("\n")[2..-1].join("\n"))
62
93
  end
63
-
64
- path = "/tmp/index_#{Time.now.to_i}.xml"
65
- index.render_to(path)
66
- File.read(path).should == fixture('group_index.xml')
67
- File.delete(path) if File.exists?(path)
68
94
  end
69
-
70
95
  end
data/spec/item_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'XmlSitemap::Item' do
4
+ describe '#new' do
5
+ it 'raises ArgumentError if invalid :period value was passed' do
6
+ proc { XmlSitemap::Item.new('hello', :period => :foobar) }.
7
+ should raise_error ArgumentError, "Invalid :period value 'foobar'"
8
+ end
9
+ end
10
+ end