Class: Glue::Template::Sitemap
- Inherits:
-
Object
- Object
- Glue::Template::Sitemap
- Defined in:
- lib/glue/template/sitemap.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
- #<<(options) ⇒ Object
-
#initialize ⇒ Sitemap
constructor
A new instance of Sitemap.
- #save(path) ⇒ Object
Constructor Details
#initialize ⇒ Sitemap
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_url ⇒ Object
Returns the value of attribute base_url.
5 6 7 |
# File 'lib/glue/template/sitemap.rb', line 5 def base_url @base_url end |
#urls ⇒ Object
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 <<() self.urls << 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 || xml.url do xml.loc File.join(base_url, [:path]) xml.lastmod [:changed_at].xmlschema if [:changed_at] xml.changefreq [:frequency] if [:frequency] xml.priority [:priority] if [:priority] end end end file.close end |