module Snippr::Links

Constants

HREF_REGEX

Public Class Methods

adjust_url(url) click to toggle source

Adjusts an url, prepending / and relative url root (context path) as needed.

# File lib/snippr/links.rb, line 38
def self.adjust_url(url)
  adjust_urls_except.each do |regex|
    return url if url =~ regex
  end
  root = relative_url_root
  url.gsub(/^(#{root}|\/)?/, root)
end
adjust_urls_except() click to toggle source

Returns the regular expressions used to determine which urls to exclude from adjustment.

# File lib/snippr/links.rb, line 10
def self.adjust_urls_except
  @@adjust_urls_except ||= [/^#/, /^[a-z]+:/i]
end
adjust_urls_except=(adjust_urls_except) click to toggle source

Sets the regular expressions used to determine which urls to exclude from adjustment.

# File lib/snippr/links.rb, line 15
def self.adjust_urls_except=(adjust_urls_except)
  @@adjust_urls_except = adjust_urls_except
end
relative_url_root() click to toggle source

Returns the relative url root (context path) the application is deployed to.

# File lib/snippr/links.rb, line 47
def self.relative_url_root
  if defined? ActionController::Base
    root = ActionController::Base.config.relative_url_root || '/'
    root = "/#{root}" unless root.start_with?('/')
    root << '/' unless root.end_with?('/')
    root
  else
    '/'
  end
end