Class: Locomotive::Steam::UrlBuilderService

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/steam/services/url_builder_service.rb

Instance Method Summary collapse

Instance Method Details

#_public_submission_url_for(content_type) ⇒ Object



51
52
53
# File 'lib/locomotive/steam/services/url_builder_service.rb', line 51

def _public_submission_url_for(content_type)
  "/entry_submissions/#{content_type.slug}"
end

#_url_for(page, locale = nil, prefix_default_locale = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/locomotive/steam/services/url_builder_service.rb', line 12

def _url_for(page, locale = nil, prefix_default_locale = nil)
  locale          = locale&.to_sym
  _locale         = (locale || current_locale).to_sym
  default_locale  = site.default_locale.to_sym
  same_locale     = _locale == default_locale

  # the prefix_default_locale can override the site.prefix_default_locale attribute
  prefix_default_locale = prefix_default_locale.nil? ? site.prefix_default_locale : prefix_default_locale

  fullpath = sanitized_fullpath(page, same_locale)

  [''].tap do |segments|
    # To insert the locale in the path, 2 cases:
    #
    # 1.  if the prefix_default_locale is enabled, we need to
    #     add the locale no matter if the locale is the same as the default one.
    #
    # 2.  since we also store the locale in session, calling the index page ("/")
    #     will always return the page in the locale stored in session.
    #     In order to see the index page in the default locale, we need to allow
    #     "/<default locale>" instead of just "/".
    #
    if prefix_default_locale || !same_locale
      segments << _locale
    elsif fullpath.blank? && locale == default_locale && current_locale != locale
      segments << locale
    end

    # we don't want a trailing slash for the home page if a locale is set
    fullpath = nil if segments.size == 2 && fullpath.blank?

    segments << fullpath
  end.compact.join('/')
end

#prefix(url) ⇒ Object



55
56
57
# File 'lib/locomotive/steam/services/url_builder_service.rb', line 55

def prefix(url)
  mounted_on ? "#{mounted_on}#{url}" : url
end

#public_submission_url_for(content_type) ⇒ Object



47
48
49
# File 'lib/locomotive/steam/services/url_builder_service.rb', line 47

def public_submission_url_for(content_type)
  prefix(_public_submission_url_for(content_type))
end

#url_for(page, locale = nil, prefix_default_locale = nil) ⇒ Object



8
9
10
# File 'lib/locomotive/steam/services/url_builder_service.rb', line 8

def url_for(page, locale = nil, prefix_default_locale = nil)
  prefix(_url_for(page, locale, prefix_default_locale))
end