Class: SitemapBuilder::SitemapIndex
- Inherits:
-
Object
- Object
- SitemapBuilder::SitemapIndex
- Defined in:
- lib/sitemap_builder/sitemap_index.rb
Instance Attribute Summary collapse
-
#sitemaps ⇒ Object
Returns the value of attribute sitemaps.
Instance Method Summary collapse
- #fullpath ⇒ Object
- #generate ⇒ Object
-
#initialize(options = {}) ⇒ SitemapIndex
constructor
A new instance of SitemapIndex.
- #save_file(xml) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SitemapIndex
Returns a new instance of SitemapIndex.
5 6 7 8 9 10 11 |
# File 'lib/sitemap_builder/sitemap_index.rb', line 5 def initialize(={}) = { :filename => 'sitemap_index.xml', }.merge @filename = [:filename] @sitemaps = [] end |
Instance Attribute Details
#sitemaps ⇒ Object
Returns the value of attribute sitemaps.
3 4 5 |
# File 'lib/sitemap_builder/sitemap_index.rb', line 3 def sitemaps @sitemaps end |
Instance Method Details
#fullpath ⇒ Object
36 37 38 |
# File 'lib/sitemap_builder/sitemap_index.rb', line 36 def fullpath "/public/" + @filename end |
#generate ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sitemap_builder/sitemap_index.rb', line 13 def generate puts "GENERATING XML INDEX FILE ..." if @debug xml_str = "" xml = Builder::XmlMarkup.new(:target => xml_str, :indent=>2) xml.instruct! xml.sitemapindex "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do @sitemaps.each do |s| xml.sitemap do xml.loc s.loc xml.lastmod w3c_date(Time.now) end end end save_file(xml_str) end |
#save_file(xml) ⇒ Object
30 31 32 33 34 |
# File 'lib/sitemap_builder/sitemap_index.rb', line 30 def save_file(xml) File.open(File.join(Rails.root, fullpath), "w+") do |f| f.write(xml) end end |