Module: SiteMapper::BaseMethods

Included in:
SiteMapper
Defined in:
lib/taq-sitemapper.rb

Instance Method Summary collapse

Instance Method Details

#pingObject



50
51
52
53
54
# File 'lib/taq-sitemapper.rb', line 50

def ping
   url_ref = @url || (@sitemap[:url] rescue nil)
   return if url_ref.nil?
   open("http://www.google.com/webmasters/tools/ping?sitemap=#{url_ref}").read
end

#write_sitemap(collection = nil, extra_collection = nil) ⇒ Object



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,extra_collection=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 extra_collection.nil? && !(@sitemap[:extra] rescue nil).nil?
      extra_collection = send(@sitemap[:extra])
   end

   xml = Builder::XmlMarkup.new(:indent=>2)
   collection = extra_collection + collection if extra_collection

   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