Module: AegisNet::Sitemapper::ActiveRecord::Builder::SingletonMethods
- Defined in:
- lib/sitemapper/active_record/builder.rb
Instance Method Summary collapse
-
#build_sitemap(scope, options = {}) ⇒ Object
Adds sitemap building functionality to ActiveRecord models.
Instance Method Details
#build_sitemap(scope, options = {}) ⇒ Object
Adds sitemap building functionality to ActiveRecord models.
The option :filename
is derived from the model name and will be set to Rails.root/public/sitemap_modelnames.xml.gz by default. Set :filename
to nil
or false
explicitely if you don’t want the filename to be guessed (ie. if you want output to stdout).
Parameters
-
scope
: :all, :first, :last or a named scope -
options
: a Hash with options to pass to ActiveRecord::Base.find and AegisNet::Sitemapper::Generator
Supported Options
-
see AegisNet::Sitemapper::Generator::VALID_GENERATOR_OPTIONS
Example
Content.build_sitemap :all, :file => "sitemap_content.xml" do |content, xml|
xml.loc content_path(content)
xml.changefreq "weekly"
xml.priority 0.5
end
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sitemapper/active_record/builder.rb', line 33 def build_sitemap scope, = {} scope = scope.to_sym raise(ArgumentError, "Unknown ActiveRecord finder: #{scope}") unless self.respond_to?(scope) = [ :conditions, :include, :joins, :limit, :offset, :order, :select, :group, :having, :from ] = .symbolize_keys! .assert_valid_keys(Generator::VALID_GENERATOR_OPTIONS, ) = .select{|option, value| .include?(option) } sitemap_opts = .delete_if{|k, v| .keys.include?(k)} # Extra treatment for the filename option sitemap_opts[:file] = sitemap_opts.keys.include?(:file) ? sitemap_opts[:file] : AegisNet::Sitemapper::Generator.default_filename(self.class) entries = self.send(scope, ).to_a # get an array for :first and :last, too AegisNet::Sitemapper::Generator.create(entries, sitemap_opts) { |entry, xml| yield entry, xml } end |