Permalink
Browse files

Builder#add_url! method now accepts options hash instead of many args

  • Loading branch information...
1 parent 7d9aaf2 commit e966e557abe500b4bd0302faf969e59ceb0665c0 @mislav committed Apr 6, 2009
Showing with 18 additions and 17 deletions.
  1. +6 −5 lib/big_sitemap.rb
  2. +5 −5 lib/big_sitemap/builder.rb
  3. +7 −7 spec/builder_spec.rb
View
@@ -58,11 +58,12 @@ def generate
timestamp_column = model.column_names.find { |col| TIMESTAMP_COLUMNS.include? col }
model.find_each(find_options) do |record|
- last_updated = timestamp_column && record.read_attribute(timestamp_column)
- freq = changefreq.is_a?(Proc) ? changefreq.call(record) : changefreq
- pri = priority.is_a?(Proc) ? priority.call(record) : priority
-
- sitemap.add_url!(polymorphic_url(record), last_updated, freq, pri)
+ sitemap.add_url!(
+ polymorphic_url(record),
+ :time => timestamp_column && record.read_attribute(timestamp_column),
+ :frequency => changefreq.is_a?(Proc) ? changefreq.call(record) : changefreq,
+ :priority => priority.is_a?(Proc) ? priority.call(record) : priority
+ )
end
end
end
View
@@ -26,14 +26,14 @@ def index?
@type == 'index'
end
- def add_url!(url, time = nil, frequency = nil, priority = nil)
+ def add_url!(url, options = {})
_rotate if @max_urls == @urls
tag!(index?? 'sitemap' : 'url') do
- loc url
- lastmod(time.to_s(:sitemap)) unless time.nil?
- changefreq(frequency) unless frequency.nil?
- priority(priority) unless priority.nil?
+ loc(url)
+ lastmod(options[:time].to_s(:sitemap)) if options[:time]
+ changefreq(options[:frequency]) if options[:frequency]
+ priority(options[:priority]) if options[:priority]
end
@urls += 1
end
View
@@ -10,7 +10,7 @@
end
it "should add location" do
- @xml.add_url!("http://example.com/mooslav", @time)
+ @xml.add_url!("http://example.com/mooslav", :time => @time)
@xml.close!
result.should == strip(<<-XML)
@@ -25,28 +25,28 @@
end
it "should support frequency" do
- @xml.add_url!("http://example.com/mooslav", nil, "all the f-in time")
+ @xml.add_url!("http://example.com/mooslav", :frequency => "all the f-in time")
@xml.close!
result.should include("<changefreq>all the f-in time</changefreq>")
end
it "should support priority" do
- @xml.add_url!("http://example.com/mooslav", nil, nil, 0.6)
+ @xml.add_url!("http://example.com/mooslav", :priority => 0.6)
@xml.close!
result.should include("<priority>0.6</priority>")
end
it "should rotate files when it reaches maximum number of URLs" do
- @xml.add_url!("http://example.com/loc1", @time)
- @xml.add_url!("http://example.com/loc2", @time)
- @xml.add_url!("http://example.com/loc3", @time)
+ @xml.add_url!("http://example.com/loc1")
+ @xml.add_url!("http://example.com/loc2")
+ @xml.add_url!("http://example.com/loc3")
@xml.close!
result.scan('<urlset').size.should == 2
end
end
it "should have sitemap index mode" do
- @xml = described_class.new(:indent => 2, :index => true)
+ @xml = described_class.new(:indent => 2, :type => 'index')
@xml.add_url!("/sitemap1.xml")
@xml.close!

0 comments on commit e966e55

Please sign in to comment.