Class: SitemapGenerator::SitemapLocation
- Inherits:
-
Hash
- Object
- Hash
- SitemapGenerator::SitemapLocation
- Defined in:
- lib/sitemap_generator/sitemap_location.rb
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (Object) []=(key, value, opts = {})
If you set the filename, clear the namer and vice versa.
-
- (Object) directory
Full path to the directory of the file.
-
- (Object) filename
Return the filename.
-
- (Object) filesize
Return the size of the file at path.
-
- (SitemapLocation) initialize(opts = {})
constructor
If no filename or namer is provided, the default namer is used, which generates names like sitemap.xml.gz, sitemap1.xml.gz, sitemap2.xml.gz and so on.
- - (Object) namer
-
- (Object) path
Full path of the file including the filename.
-
- (Object) path_in_public
Relative path of the file (including the filename) relative to public_path.
-
- (Object) reserve_name
If a namer is set, reserve the filename and increment the namer.
-
- (Boolean) reserved_name?
Return true if this location has a fixed filename.
-
- (Object) url
Full URL of the file.
- - (Boolean) verbose?
-
- (Object) with(opts = {})
Return a new Location instance with the given options merged in.
- - (Object) write(data)
Constructor Details
- (SitemapLocation) initialize(opts = {})
If no filename or namer is provided, the default namer is used, which generates names like sitemap.xml.gz, sitemap1.xml.gz, sitemap2.xml.gz and so on.
Options
-
adapter - SitemapGenerator::Adapter subclass
-
filename - full name of the file e.g. <tt>'sitemap1.xml.gz'<tt>
-
host - host name for URLs. The full URL to the file is then constructed from the host, sitemaps_path and filename
-
namer - a SitemapGenerator::SimpleNamer instance. Can be passed instead of filename.
-
public_path - path to the “public” directory, or the directory you want to write sitemaps in. Default is a directory public/ in the current working directory, or relative to the Rails root directory if running under Rails.
-
sitemaps_path - gives the path relative to the public_path in which to write sitemaps e.g. sitemaps/.
-
verbose - whether to output summary into to STDOUT. Default false.
-
create_index - whether to create a sitemap index. Default `:auto`. See LinkSet.
Only applies to the SitemapIndexLocation object.
35 36 37 38 39 40 41 42 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 35 def initialize(opts={}) SitemapGenerator::Utilities.assert_valid_keys(opts, [:adapter, :public_path, :sitemaps_path, :host, :filename, :namer, :verbose, :create_index]) opts[:adapter] ||= SitemapGenerator::FileAdapter.new opts[:public_path] ||= SitemapGenerator.app.root + 'public/' opts[:namer] = SitemapGenerator::SitemapNamer.new(:sitemap) if !opts[:filename] && !opts[:namer] opts[:verbose] = !!opts[:verbose] self.merge!(opts) end |
Instance Method Details
- (Object) []=(key, value, opts = {})
If you set the filename, clear the namer and vice versa.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 110 def []=(key, value, opts={}) if !opts[:super] case key when :namer super(:filename, nil) when :filename super(:namer, nil) end end super(key, value) end |
- (Object) directory
Full path to the directory of the file.
50 51 52 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 50 def directory (public_path + sitemaps_path)..to_s end |
- (Object) filename
Return the filename. Raises an exception if no filename or namer is set. If using a namer once the filename has been retrieved from the namer its value is locked so that it is unaffected by further changes to the namer.
77 78 79 80 81 82 83 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 77 def filename raise SitemapGenerator::SitemapError, "No filename or namer set" unless self[:filename] || self[:namer] unless self[:filename] self.send(:[]=, :filename, self[:namer].to_s, :super => true) end self[:filename] end |
- (Object) filesize
Return the size of the file at path
70 71 72 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 70 def filesize File.size?(path) end |
- (Object) namer
101 102 103 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 101 def namer self[:namer] end |
- (Object) path
Full path of the file including the filename.
55 56 57 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 55 def path (public_path + sitemaps_path + filename)..to_s end |
- (Object) path_in_public
Relative path of the file (including the filename) relative to public_path
60 61 62 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 60 def path_in_public (sitemaps_path + filename).to_s end |
- (Object) reserve_name
If a namer is set, reserve the filename and increment the namer. Returns the reserved name.
87 88 89 90 91 92 93 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 87 def reserve_name if self[:namer] filename self[:namer].next end self[:filename] end |
- (Boolean) reserved_name?
Return true if this location has a fixed filename. If no name has been reserved from the namer, for instance, returns false.
97 98 99 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 97 def reserved_name? !!self[:filename] end |
- (Object) url
Full URL of the file.
65 66 67 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 65 def url URI.join(host, sitemaps_path.to_s, filename.to_s).to_s end |
- (Boolean) verbose?
105 106 107 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 105 def verbose? self[:verbose] end |
- (Object) with(opts = {})
Return a new Location instance with the given options merged in
45 46 47 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 45 def with(opts={}) self.merge(opts) end |
- (Object) write(data)
122 123 124 |
# File 'lib/sitemap_generator/sitemap_location.rb', line 122 def write(data) adapter.write(self, data) end |