module BuntoAdmin::URLable

Abstract module to be included in Convertible and Document to provide additional, URL-specific functionality without duplicating logic

Public Instance Methods

api_url() click to toggle source

Absolute URL to the API representation of this resource

# File lib/bunto-admin/urlable.rb, line 17
def api_url
  @api_url ||= Addressable::URI.new(
    :scheme => scheme, :host => host, :port => port,
    :path => path_with_base("/_api", resource_path)
  ).normalize.to_s
end
entries_url() click to toggle source
# File lib/bunto-admin/urlable.rb, line 24
def entries_url
  return unless is_a?(Bunto::Collection)
  "#{api_url}/entries"
end
http_url() click to toggle source

Absolute URL to the HTTP(S) rendered/served representation of this resource

# File lib/bunto-admin/urlable.rb, line 7
def http_url
  return if is_a?(Bunto::Collection) || is_a?(BuntoAdmin::DataFile)
  return if is_a?(Bunto::Document) && !collection.write?
  @http_url ||= Addressable::URI.new(
    :scheme => scheme, :host => host, :port => port,
    :path => path_with_base(BuntoAdmin.site.config["baseurl"], url)
  ).normalize.to_s
end

Private Instance Methods

host() click to toggle source
# File lib/bunto-admin/urlable.rb, line 57
def host
  BuntoAdmin.site.config["host"].sub("127.0.0.1", "localhost")
end
path_with_base(base, path) click to toggle source

URI.join doesn't like joining two relative paths, and File.join may join with `` rather than with `/` on windows

# File lib/bunto-admin/urlable.rb, line 49
def path_with_base(base, path)
  [base, path].join("/").squeeze("/")
end
port() click to toggle source
# File lib/bunto-admin/urlable.rb, line 61
def port
  BuntoAdmin.site.config["port"]
end
resource_path() click to toggle source

URL path relative to `_api/` to retreive the given resource via the API Note: we can't use a case statement here, because === doesn't like includes

# File lib/bunto-admin/urlable.rb, line 33
def resource_path
  if is_a?(Bunto::Document)
    "/collections/#{relative_path.sub(%r!\A_!, "")}"
  elsif is_a?(Bunto::Collection)
    "/collections/#{label}"
  elsif is_a?(BuntoAdmin::DataFile)
    "/data/#{relative_path}"
  elsif is_a?(Bunto::StaticFile)
    "/static_files/#{relative_path}"
  elsif is_a?(Bunto::Page)
    "/pages/#{relative_path}"
  end
end
scheme() click to toggle source
# File lib/bunto-admin/urlable.rb, line 53
def scheme
  BuntoAdmin.site.config["scheme"] || "http"
end