Class: SimpleSitemap::Generators::Sitemap
- Defined in:
- lib/simple_sitemap/generators/sitemap.rb
Instance Attribute Summary collapse
-
#sitemap_data ⇒ Object
Returns the value of attribute sitemap_data.
-
#sitemap_name ⇒ Object
Returns the value of attribute sitemap_name.
Attributes inherited from Base
Instance Method Summary collapse
- #add_path(path, opts = {}) ⇒ Object
- #add_url(url, opts = {}) ⇒ Object
-
#initialize(config, hooks) ⇒ Sitemap
constructor
A new instance of Sitemap.
- #sitemap(name, &block) ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(config, hooks) ⇒ Sitemap
Returns a new instance of Sitemap.
12 13 14 15 16 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 12 def initialize(config, hooks) super @sitemap_data = {} enter_sitemap nil end |
Instance Attribute Details
#sitemap_data ⇒ Object
Returns the value of attribute sitemap_data.
10 11 12 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 10 def sitemap_data @sitemap_data end |
#sitemap_name ⇒ Object
Returns the value of attribute sitemap_name.
10 11 12 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 10 def sitemap_name @sitemap_name end |
Instance Method Details
#add_path(path, opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 33 def add_path(path, opts={}) if @config.default_path if @config.default_path[-1,1] != '/' && path[0] != '/' path = "/#{path}" end add_url "#{@config.default_path}#{path}", opts else raise "Can't add a path without configuring default_path" end end |
#add_url(url, opts = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 18 def add_url(url, opts={}) link = { url: url } link.merge! opts @sitemap_data[@sitemap_name][:links] << link @sitemap_data[@sitemap_name][:size] += 1 ## TODO, add correct bytesize (this is an overestimate) @sitemap_data[@sitemap_name][:bytesize] += 200 if @sitemap_data[@sitemap_name][:size] >= SimpleSitemap::MAX_LINKS_PER_FILE write @sitemap_name end if @sitemap_data[@sitemap_name][:bytesize] >= SimpleSitemap::MAX_FILE_SIZE write @sitemap_name end end |
#sitemap(name, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 44 def sitemap(name, &block) enter_sitemap name yield exit_sitemap end |
#write! ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/simple_sitemap/generators/sitemap.rb', line 50 def write! @sitemap_data.keys.each do |name| if @sitemap_data[name][:links].size > 0 write name end end write_index end |