module Card::Env::Location

Public Instance Methods

card_path(rel_path) click to toggle source

card_path makes a relative path site-absolute (if not already) card_url makes it a full url (if not already)

# File lib/card/env/location.rb, line 7
def card_path rel_path
  unless rel_path.is_a? String
    Rails.logger.warn "Pass only strings to card_path. "\
                      "(#{rel_path} = #{rel_path.class})"
  end
  if rel_path.match? %r{^(https?:)?/}
    rel_path
  else
    "#{relative_url_root}/#{rel_path}"
  end
end
card_url(rel) click to toggle source
# File lib/card/env/location.rb, line 19
def card_url rel
  rel.match?(/^https?:/) ? rel : "#{Env.origin}#{card_path rel}"
end
cardname_from_url(url) click to toggle source
# File lib/card/env/location.rb, line 23
def cardname_from_url url
  return unless (cardname = cardname_from_url_regexp)

  m = url.match cardname
  m ? Card::Name[m[:mark]] : nil
end
relative_url_root() click to toggle source
# File lib/card/env/location.rb, line 30
def relative_url_root
  Cardio.config.relative_url_root
end

Private Instance Methods

cardname_from_url_regexp() click to toggle source
# File lib/card/env/location.rb, line 36
def cardname_from_url_regexp
  return unless Env.origin.present?

  %r{#{Regexp.escape Env.origin}/(?<mark>[^?]+)}
end