Class: Glue::Template::Sitemap

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSitemap

Returns a new instance of Sitemap.



7
8
9
# File 'lib/glue/template/sitemap.rb', line 7

def initialize
  self.urls = []
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/glue/template/sitemap.rb', line 5

def base_url
  @base_url
end

#urlsObject

Returns the value of attribute urls.



4
5
6
# File 'lib/glue/template/sitemap.rb', line 4

def urls
  @urls
end

Instance Method Details

#<<(options) ⇒ Object



11
12
13
# File 'lib/glue/template/sitemap.rb', line 11

def <<(options)
  self.urls << options
end

#save(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/glue/template/sitemap.rb', line 15

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}"
  
  xml.urlset :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" do
    urls.each do |options|
      xml.url do
        xml.loc         File.join(base_url, options[:path])
        xml.lastmod     options[:changed_at].xmlschema if options[:changed_at]
        xml.changefreq  options[:frequency] if options[:frequency]
        xml.priority    options[:priority] if options[:priority]
      end
    end
  end
  
  file.close
end