Sha256: ea9ecd6e12e9fa80233599d03e7d09c75941623165e72e5d10cd50447075d29e
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
class SitemapsController < ApplicationController def sitemap new_page! instance_eval &DynamicSitemaps::Sitemap.draw_block if params[:page] if pages.count > 1 page = pages[params[:page].to_i - 1] if page @urls = page.urls else @urls = [] end else @urls = [] end elsif pages.count > 1 @pages = pages render :index else @urls = pages.last.urls end end protected def pages @pages ||= [] end def new_page! pages << DynamicSitemaps::Page.new end def current_page pages.last end def per_page(size = nil) @per_page ||= size || 50000 end def url(loc, options = {}) if current_page.urls.count >= per_page new_page! end loc = polymorphic_url(loc) unless loc.is_a?(String) current_page.urls << DynamicSitemaps::Url.new(loc, options) end def autogenerate(*args) options = args.extract_options! args.flatten.each do |sym| sym.to_s.singularize.camelize.constantize.send(:all).each do |obj| url obj, convert_options(options, obj) end end end def convert_options(options, obj) options.each do |key, value| if value.is_a?(Symbol) value = obj.send(value) elsif value.is_a?(Proc) value = value.call(obj) end options[key] = value end options end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dynamic_sitemaps-1.0.2 | app/controllers/sitemaps_controller.rb |
dynamic_sitemaps-1.0.1 | app/controllers/sitemaps_controller.rb |