Class: Alchemy::Page::UrlPath
- Inherits:
-
Object
- Object
- Alchemy::Page::UrlPath
- 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:
-
It returns just a slash for language root pages of the default langauge
-
It returns a url path with a leading slash for regular pages
-
It returns a url path with a leading slash and language code prefix for pages not having the default language
-
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
Constant Summary collapse
- ROOT_PATH =
"/"
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(page) ⇒ UrlPath
constructor
A new instance of UrlPath.
Constructor Details
#initialize(page) ⇒ UrlPath
Returns a new instance of UrlPath.
25 26 27 28 29 |
# File 'app/models/alchemy/page/url_path.rb', line 25 def initialize(page) @page = page @language = @page.language @site = @language.site end |
Instance Method Details
#call ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/alchemy/page/url_path.rb', line 31 def call return @page.urlname if @page.definition["redirects_to_external"] if @page.language_root? language_root_path elsif @site.languages.select(&:public?).length > 1 page_path_with_language_prefix else page_path_with_leading_slash end end |