class SitemapBoiler::SitemapGenerator
Attributes
config[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/sitemap_boiler/sitemap_generator.rb, line 8 def initialize config @config = config end
Public Instance Methods
location_url(config, localization, page)
click to toggle source
# File lib/sitemap_boiler/sitemap_generator.rb, line 16 def location_url config, localization, page URLComposer.compose(config[:base_url], localization['prefix'], page['path']) end
to_xml(localization)
click to toggle source
# File lib/sitemap_boiler/sitemap_generator.rb, line 20 def to_xml localization xml_markup.urlset(config[:urlset_headers]) do |urlset| config[:pages].each do |page| urlset.url do |url| url.loc location_url(config, localization, page) config[:localizations].each do |alternate| url.tag!('xhtml:link', href: location_url(config, alternate, page), hreflang: alternate['hreflang'], rel: :alternate ) end if page['android_url'] url.tag!('xhtml:link', href: page['android_url'], rel: :alternate) end end end end end
write(localization, path)
click to toggle source
# File lib/sitemap_boiler/sitemap_generator.rb, line 12 def write localization, path File.open(path, 'w') { |file| file.write(to_xml(localization)) } end
Private Instance Methods
xml_markup()
click to toggle source
# File lib/sitemap_boiler/sitemap_generator.rb, line 42 def xml_markup xml = Builder::XmlMarkup.new(indent: 2) xml.instruct! :xml, encoding: 'UTF-8' xml end