Sha256: 0fb1760ed4d3b9ebaa25d973a74ef1a9ba9df018f7e01d2a00ccf318ea79a0aa
Contents?: true
Size: 1.48 KB
Versions: 3
Compression:
Stored size: 1.48 KB
Contents
module Workarea class Sitemap # Model object for representing a single link in the sitemap. A # sitemap XML file is composed of +<url />+ elements, and this class # helps to define the data that ends up in there. class Link delegate_missing_to :@taxon # @param [Workarea::Navigation::Taxon] taxon - Model this link is based on # @param [Workarea::GenerateSitemaps] generator - Worker class this link was instantiated from. def initialize(taxon:, generator:) @taxon = taxon @generator = generator end # Return the parsed +host+ from the given URL, or the default host # (+Workarea.config.host+) if a +Navigable+ model is being linked # to. def host return default_host unless fully_qualified_url? "#{uri.scheme}://#{uri.host}" end # Return the route path for the +Navigable+ model that is linked # to in this taxon, or the +url+ that was hard-coded into the # taxon at creation. def path return uri.path if url? @generator.send(route, navigable_slug) end private def route @route ||= "#{resource_name}_path" end def uri @uri ||= URI.parse(url) end def default_host scheme = Rails.configuration.force_ssl ? 'https' : 'http' "#{scheme}://#{Workarea.config.host}" end def fully_qualified_url? url? && uri.host.present? && uri.scheme.present? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
workarea-sitemaps-2.1.8 | app/models/workarea/sitemap/link.rb |
workarea-sitemaps-2.1.7 | app/models/workarea/sitemap/link.rb |
workarea-sitemaps-2.1.6 | app/models/workarea/sitemap/link.rb |