lib/sitemap/generator.rb in sitemap-0.3.2 vs lib/sitemap/generator.rb in sitemap-0.3.3

- old
+ new

@@ -8,16 +8,17 @@ :updated_at => "lastmod", :change_frequency => "changefreq", :priority => "priority" } - attr_accessor :store, :host, :routes, :fragments + attr_accessor :store, :protocol, :host, :routes, :fragments # Instantiates a new object. # Should never be called directly. def initialize self.class.send(:include, Rails.application.routes.url_helpers) + self.protocol = "http" self.fragments = [] self.store = Store.new(:max_entries => Sitemap.configuration.max_urls) self.store.before_reset do |entries| self.process_fragment! end @@ -29,10 +30,16 @@ # # Sitemap::Generator.instance.load :host => "mywebsite.com" do # ... # end # + # Literal paths can be added as follows: + # + # Sitemap::Generator.instance.load :host => "mywebsite.com" do + # literal "/some_fancy_url" + # end + # # Simple paths can be added as follows: # # Sitemap::Generator.instance.load :host => "mywebsite.com" do # path :faq # end @@ -56,10 +63,24 @@ self.send("#{k}=", v) end self.routes = block end + # Adds the literal url (for consistency, starting with a "/" as in "/my_url") + # accepts similar options to path and resources + def literal(target_url, options = {}) + search = Sitemap.configuration.search.clone.merge!(options.select { |k, v| SEARCH_ATTRIBUTES.keys.include?(k) }) + search.merge!(search) { |type, value| get_data(nil, value) } + + output_host = options[:host] || host + output_protocol = options[:protocol] || protocol + self.store << { + :url =>"#{output_protocol}://#{output_host}#{target_url}", + :search => search + } + end + # Adds the specified url or object (such as an ActiveRecord model instance). # In either case the data is being looked up in the current application routes. # # Params can be specified as follows: # @@ -71,9 +92,10 @@ # # The resolved url would be <tt>http://mywebsite.com/frequent-questions?filter=recent</tt>. # def path(object, options = {}) params = Sitemap.configuration.params.clone.merge!(options[:params] || {}) + params[:protocol] ||= protocol # Use global protocol if none was specified. params[:host] ||= host # Use global host if none was specified. params.merge!(params) { |type, value| get_data(object, value) } search = Sitemap.configuration.search.clone.merge!(options.select { |k, v| SEARCH_ATTRIBUTES.keys.include?(k) }) search.merge!(search) { |type, value| get_data(object, value) }