2012-01-17 16:04:45 +00:00
|
|
|
module Locomotive
|
|
|
|
module ActionController
|
|
|
|
module UrlHelpers
|
|
|
|
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
helper_method :current_site_public_url, :switch_to_site_url, :public_page_url
|
|
|
|
end
|
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def current_site_public_url
|
|
|
|
request.protocol + request.host_with_port
|
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def switch_to_site_url(site, options = {})
|
|
|
|
options = { :fullpath => true, :protocol => true }.merge(options)
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
|
|
|
url += ":#{request.port}" if request.port != 80
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
url = File.join(url, request.fullpath) if options[:fullpath]
|
|
|
|
url = "http://#{url}" if options[:protocol]
|
|
|
|
url
|
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def public_page_url(page, options = {})
|
2012-04-10 11:55:59 +00:00
|
|
|
if contents = options.delete(:contents)
|
|
|
|
File.join(current_site_public_url, page.compiled_fullpath(contents))
|
2012-02-05 23:54:09 +00:00
|
|
|
else
|
2012-04-10 11:55:59 +00:00
|
|
|
File.join(current_site_public_url, page.pretty_fullpath)
|
2012-01-17 16:04:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-02-05 23:54:09 +00:00
|
|
|
|
2012-01-17 16:04:45 +00:00
|
|
|
end
|
|
|
|
end
|