Module: Locomotive::ActionController::UrlHelpers

Extended by:
ActiveSupport::Concern
Included in:
BaseController, Public::BaseController
Defined in:
lib/locomotive/action_controller/url_helpers.rb

Instance Method Summary collapse

Instance Method Details

#current_site_public_urlObject



11
12
13
14
# File 'lib/locomotive/action_controller/url_helpers.rb', line 11

def current_site_public_url
  # by convention, a public site is displayed in http not https.
  'http://' + request.host_with_port
end

#public_page_url(page, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/locomotive/action_controller/url_helpers.rb', line 27

def public_page_url(page, options = {})
  # Rails.logger.debug "[public_page_url] =====> #{page.attributes.inspect} / #{page.fullpath.inspect} / #{current_site_public_url}\n\n"

  locale    = options[:locale]
  fullpath  = current_site.localized_page_fullpath(page, locale)

  if content = options.delete(:content)
    fullpath = File.join(fullpath.gsub('content_type_template', ''), content._slug)
  end

  File.join(current_site_public_url, fullpath)
end

#switch_to_site_url(site, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/locomotive/action_controller/url_helpers.rb', line 16

def switch_to_site_url(site, options = {})
  options = { fullpath: true, protocol: true }.merge(options)

  url = "#{site.subdomain}.#{Locomotive.config.domain}"
  url += ":#{request.port}" if request.port != 80

  url = File.join(url, request.fullpath) if options[:fullpath]
  url = "http://#{url}" if options[:protocol]
  url
end