6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/taq-sitemapper.rb', line 6
def write_sitemap(collection=nil,=nil)
file_ref = @file || (@sitemap[:file] rescue nil)
loc_ref = @loc || (@sitemap[:loc] rescue nil)
lastmod_ref = @lastmod || (@sitemap[:lastmod] rescue nil)
changefreq_ref = @changefreq || (@sitemap[:changefreq] rescue nil)
priority_ref = @priority || (@sitemap[:priority] rescue nil)
return false if file_ref.nil?
if collection.nil? && !(@sitemap[:collection] rescue nil).nil?
collection = send(@sitemap[:collection])
end
if .nil? && !(@sitemap[:extra] rescue nil).nil?
= send(@sitemap[:extra])
end
xml = Builder::XmlMarkup.new(:indent=>2)
collection = + collection if
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") do
collection.each do |value|
loc = value.respond_to?(loc_ref.to_s.to_sym) ? value.send(loc_ref) : value[loc_ref]
lastmod = value.respond_to?(lastmod_ref.to_s.to_sym) ? value.send(lastmod_ref) : value[lastmod_ref]
change = value.respond_to?(changefreq_ref.to_s.to_sym) ? value.send(changefreq_ref) : value[changefreq_ref]
priority = value.respond_to?(priority_ref.to_s.to_sym) ? value.send(priority_ref) : value[priority_ref]
change = changefreq_ref if !change
priority = priority_ref if !priority
xml.url do
xml.loc loc
xml.lastmod lastmod
xml.changefreq change
xml.priority priority
end
end
end
content = xml.target!
File.open(file_ref,"w") do |file|
file << content
end
content
end
|