Class: MassiveSitemap::Builder::Base
- Inherits:
-
Object
- Object
- MassiveSitemap::Builder::Base
- Defined in:
- lib/massive_sitemap/builder/base.rb
Constant Summary collapse
- OPTS =
{ :url => nil, :indent_by => 2 }
- HEADER_NAME =
'urlset'
- HEADER_ATTRIBUTES =
{ 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9', 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xsi:schemaLocation' => "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" }
Class Method Summary collapse
-
.generate(writer, options = {}, &block) ⇒ Object
alias for .new.
Instance Method Summary collapse
-
#add(path, attrs = {}) ⇒ Object
add url, prefix with given base_url.
-
#close!(indent = true) ⇒ Object
close a tag, if last one, close writer too.
-
#init_writer!(writer_options = {}, &block) ⇒ Object
implicitly called by add_url!, call explicitly to check if writer can be used.
-
#initialize(writer, options = {}, &block) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(writer, options = {}, &block) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 |
# File 'lib/massive_sitemap/builder/base.rb', line 22 def initialize(writer, = {}, &block) @writer = writer @options = self.class::OPTS.merge() @opened_tags = [] process(&block) end |
Class Method Details
.generate(writer, options = {}, &block) ⇒ Object
alias for .new
31 32 33 |
# File 'lib/massive_sitemap/builder/base.rb', line 31 def self.generate(writer, = {}, &block) self.new(writer, , &block) end |
Instance Method Details
#add(path, attrs = {}) ⇒ Object
add url, prefix with given base_url
36 37 38 |
# File 'lib/massive_sitemap/builder/base.rb', line 36 def add(path, attrs = {}) add_url! ::File.join(url, path), attrs end |
#close!(indent = true) ⇒ Object
close a tag, if last one, close writer too
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/massive_sitemap/builder/base.rb', line 50 def close!(indent = true) if name = @opened_tags.pop @writer.print "\n" + ' ' * @options[:indent_by] * @opened_tags.size if indent @writer.print "</#{name}>" if @opened_tags.size == 0 @writer.close! true end end end |
#init_writer!(writer_options = {}, &block) ⇒ Object
implicitly called by add_url!, call explicitly to check if writer can be used
41 42 43 44 45 46 47 |
# File 'lib/massive_sitemap/builder/base.rb', line 41 def init_writer!( = {}, &block) unless @writer.inited? @writer.init!() header! end process(&block) end |