Class: Glue::Template::Sitemap

Inherits:
Base
  • Object
show all
Defined in:
lib/glue/template/sitemap.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #filters, #items

Instance Method Summary collapse

Methods inherited from Base

#<<, #apply_filters, #initialize

Constructor Details

This class inherits a constructor from Glue::Template::Base

Instance Method Details

#save(path) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/glue/template/sitemap.rb', line 4

def save(path)
  file = File.open(path, "w+")
  xml = Builder::XmlMarkup.new(:target => file, :indent => 2)
  xml.instruct! :xml, :version => "1.1", :encoding => "UTF-8"
  xml.comment! "Generated at #{Time.now.inspect}"
  
  self.filters = config[:sitemap][:filters]
  filtered_items = apply_filters
  
  xml.urlset :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" do
    filtered_items.each do |options|
      xml.url do
        xml.loc         File.join(config[:site][:base_url], options[:path])
        xml.lastmod     options[:updated_at].xmlschema if options[:updated_at]
        xml.changefreq  options[:frequency] if options[:frequency]
        xml.priority    options[:priority] if options[:priority]
      end
    end
  end
  
  file.close
end