Module: Bunto::Filters::URLFilters

Included in:
Bunto::Filters
Defined in:
lib/bunto/filters/url_filters.rb

Instance Method Summary collapse

Instance Method Details

#absolute_url(input) ⇒ Object

Produces an absolute URL based on site.url and site.baseurl.

input - the URL to make absolute.

Returns the absolute URL as a String.



11
12
13
14
15
16
# File 'lib/bunto/filters/url_filters.rb', line 11

def absolute_url(input)
  return if input.nil?
  site = @context.registers[:site]
  return relative_url(input).to_s if site.config["url"].nil?
  Addressable::URI.parse(site.config["url"] + relative_url(input)).normalize.to_s
end

#relative_url(input) ⇒ Object

Produces a URL relative to the domain root based on site.baseurl.

input - the URL to make relative to the domain root

Returns a URL relative to the domain root as a String.



23
24
25
26
27
28
29
30
# File 'lib/bunto/filters/url_filters.rb', line 23

def relative_url(input)
  return if input.nil?
  site = @context.registers[:site]
  parts = [site.config["baseurl"], input]
  Addressable::URI.parse(
    parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
  ).normalize.to_s
end