Class: Alchemy::Page::UrlPath

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/page/url_path.rb

Overview

The url_path for this page

Use this to build relative links to this page

It takes several circumstances into account:

  1. It returns just a slash for language root pages of the default langauge

  2. It returns a url path with a leading slash for regular pages

  3. It returns a url path with a leading slash and language code prefix for pages not having the default language

  4. It returns a url path with a leading slash and the language code for language root pages of a non-default language

Examples

Using Rails’ link_to helper

link_to page.url

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ UrlPath

Returns a new instance of UrlPath.



23
24
25
26
27
# File 'app/models/alchemy/page/url_path.rb', line 23

def initialize(page)
  @page = page
  @language = @page.language
  @site = @language.site
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
36
37
# File 'app/models/alchemy/page/url_path.rb', line 29

def call
  if @page.language_root?
    language_root_path
  elsif @site.languages.count(&:public?) > 1
    page_path_with_language_prefix
  else
    page_path_with_leading_slash
  end
end