Class: Indexmap::Writer
- Inherits:
-
Object
- Object
- Indexmap::Writer
- Defined in:
- lib/indexmap/writer.rb
Constant Summary collapse
- VALID_FORMATS =
%i[index single_file].freeze
Instance Attribute Summary collapse
-
#public_path ⇒ Object
Returns the value of attribute public_path.
Instance Method Summary collapse
-
#initialize(public_path:, base_url:, sections: nil, entries: nil, index_filename: "sitemap.xml", format: :index) ⇒ Writer
constructor
A new instance of Writer.
- #write ⇒ Object
Constructor Details
#initialize(public_path:, base_url:, sections: nil, entries: nil, index_filename: "sitemap.xml", format: :index) ⇒ Writer
Returns a new instance of Writer.
7 8 9 10 11 12 13 14 |
# File 'lib/indexmap/writer.rb', line 7 def initialize(public_path:, base_url:, sections: nil, entries: nil, index_filename: "sitemap.xml", format: :index) @entries = normalize_entries(entries) @format = normalize_format(format) @sections = normalize_sections(sections) @public_path = Pathname(public_path) @base_url = base_url @index_filename = index_filename end |
Instance Attribute Details
#public_path ⇒ Object
Returns the value of attribute public_path.
28 29 30 |
# File 'lib/indexmap/writer.rb', line 28 def public_path @public_path end |
Instance Method Details
#write ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/indexmap/writer.rb', line 16 def write FileUtils.mkdir_p(public_path) return [write_file(index_filename, urlset_xml(entries))] if single_file? paths = sections.map do |section| write_file(section.filename, urlset_xml(section.entries)) end paths + [write_file(index_filename, index_xml(sections))] end |