Module: DynamicSitemaps

Defined in:
lib/dynamic_sitemaps/sitemap_result.rb,
lib/dynamic_sitemaps.rb,
lib/dynamic_sitemaps/logger.rb,
lib/dynamic_sitemaps/pinger.rb,
lib/dynamic_sitemaps/sitemap.rb,
lib/dynamic_sitemaps/version.rb,
lib/dynamic_sitemaps/generator.rb,
lib/dynamic_sitemaps/rails/engine.rb,
lib/dynamic_sitemaps/index_generator.rb,
lib/dynamic_sitemaps/sitemap_generator.rb,
lib/generators/dynamic_sitemaps/install_generator.rb

Overview

Contains the result of a sitemap generation

Defined Under Namespace

Classes: Engine, Generator, IndexGenerator, InstallGenerator, Logger, Pinger, Sitemap, SitemapGenerator, SitemapResult

Constant Summary collapse

DEFAULT_PER_PAGE =
50000
DEFAULT_FOLDER =
"sitemaps"
DEFAULT_INDEX_FILE_NAME =
"sitemap.xml"
DEFAULT_ALWAYS_GENERATE_INDEX =
false
SEARCH_ENGINE_PING_URLS =
[
  "http://www.google.com/webmasters/sitemaps/ping?sitemap=%s",
  "http://www.bing.com/webmaster/ping.aspx?siteMap=%s"
]
DEFAULT_PING_ENVIRONMENTS =
["production"]
VERSION =
"2.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.always_generate_indexObject



74
75
76
77
# File 'lib/dynamic_sitemaps.rb', line 74

def always_generate_index
  return @always_generate_index if instance_variable_defined?(:@always_generate_index)
  @always_generate_index = DEFAULT_ALWAYS_GENERATE_INDEX
end

.index_file_nameObject



70
71
72
# File 'lib/dynamic_sitemaps.rb', line 70

def index_file_name
  @index_file_name ||= DEFAULT_INDEX_FILE_NAME
end

.per_pageObject



88
89
90
# File 'lib/dynamic_sitemaps.rb', line 88

def per_page
  @per_page ||= DEFAULT_PER_PAGE
end

.ping_environmentsObject



96
97
98
# File 'lib/dynamic_sitemaps.rb', line 96

def ping_environments
  @ping_environments ||= DEFAULT_PING_ENVIRONMENTS.dup
end

.search_engine_ping_urlsObject



92
93
94
# File 'lib/dynamic_sitemaps.rb', line 92

def search_engine_ping_urls
  @search_engine_ping_urls ||= SEARCH_ENGINE_PING_URLS.dup
end

Class Method Details

.config_pathObject



79
80
81
# File 'lib/dynamic_sitemaps.rb', line 79

def config_path
  @config_path ||= Rails.root.join("config", "sitemap.rb").to_s
end

.config_path=(new_path) ⇒ Object

Raises:

  • (ArgumentError)


83
84
85
86
# File 'lib/dynamic_sitemaps.rb', line 83

def config_path=(new_path)
  raise ArgumentError, "DynamicSitemaps.config_path can't be blank." if new_path.blank?
  @config_path = new_path.to_s
end

.configure {|_self| ... } ⇒ Object

Configure DynamicSitemaps. Defaults:

DynamicSitemaps.configure do |config|
  config.path = Rails.root.join("public")
  config.folder = "sitemaps"
  config.index_file_name = "sitemap.xml"
  config.always_generate_index = false
  config.config_path = Rails.root.join("config", "sitemap.rb")
  config.per_page = 50_000
end

To ping search engines after generating the sitemap:

DynamicSitemaps.configure do |config|
  config.search_engine_ping_urls << "http://customsearchengine.com/ping?url=%s" # Default is Google and Bing
  config.ping_environments << "staging" # Default is production
end

Yields:

  • (_self)

Yield Parameters:



48
49
50
# File 'lib/dynamic_sitemaps.rb', line 48

def configure
  yield self
end

.folderObject



52
53
54
# File 'lib/dynamic_sitemaps.rb', line 52

def folder
  @folder ||= DEFAULT_FOLDER
end

.folder=(new_folder) ⇒ Object

Raises:

  • (ArgumentError)


56
57
58
59
# File 'lib/dynamic_sitemaps.rb', line 56

def folder=(new_folder)
  raise ArgumentError, "DynamicSitemaps.folder can't be blank." if new_folder.blank?
  @folder = new_folder
end

.generate_sitemap(&block) ⇒ Object

Generates the sitemap(s) and index based on the configuration file specified in DynamicSitemaps.config_path. If you supply a block, that block is evaluated instead of the configuration file.



26
27
28
# File 'lib/dynamic_sitemaps.rb', line 26

def generate_sitemap(&block)
  DynamicSitemaps::Generator.new.generate(&block)
end

.pathObject



61
62
63
# File 'lib/dynamic_sitemaps.rb', line 61

def path
  @path ||= Rails.root.join("public").to_s
end

.path=(new_path) ⇒ Object

Raises:

  • (ArgumentError)


65
66
67
68
# File 'lib/dynamic_sitemaps.rb', line 65

def path=(new_path)
  raise ArgumentError, "DynamicSitemaps.path can't be blank." if new_path.blank?
  @path = new_path.to_s
end

.reset!Object

Resets all instance variables. Used for testing.



110
111
112
# File 'lib/dynamic_sitemaps.rb', line 110

def reset!
  instance_variables.each { |var| remove_instance_variable var }
end

.sitemap_ping_urls=(array_or_proc) ⇒ Object

Removed in version 2.0.0.beta2



101
102
103
# File 'lib/dynamic_sitemaps.rb', line 101

def sitemap_ping_urls=(array_or_proc)
  raise "sitemap_ping_urls has been removed. Please use `ping \"http://example.com/sitemap.xml\"` in config/sitemap.rb instead."
end

.temp_pathObject



105
106
107
# File 'lib/dynamic_sitemaps.rb', line 105

def temp_path
  @temp_path ||= Rails.root.join("tmp", "dynamic_sitemaps").to_s
end