Class: Refinery::Pages::Url::Localised

Inherits:
Refinery::Pages::Url show all
Defined in:
pages/lib/refinery/pages/url.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Refinery::Pages::Url

build, #initialize

Constructor Details

This class inherits a constructor from Refinery::Pages::Url

Class Method Details

.handle?(page) ⇒ Boolean



6
7
8
# File 'pages/lib/refinery/pages/url.rb', line 6

def self.handle?(page)
  page.link_url.present?
end

Instance Method Details

#urlObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'pages/lib/refinery/pages/url.rb', line 10

def url
  current_url = page.link_url
  # Don't mess around with absolute URLs, just accept them.  Examples:
  #
  # * https://github.com/parndt
  # * http://github.com/parndt
  # * //github.com/parndt
  return current_url if current_url =~ %r{\A(https?:)?//}

  if Refinery::I18n.url_filter_enabled? && current_url =~ %r{^/} &&
    Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale
    current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}"
  end

  # See https://github.com/refinery/refinerycms/issues/2740
  if current_url == '/'
    Refinery::Core.mounted_path
  else
    [Refinery::Core.mounted_path, current_url.sub(%r{\A/}, '')].
      join("/").sub("//", "/").sub(%r{/\z}, '')
  end
end