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
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(page, optional_params = {}) ⇒ UrlPath
constructor
A new instance of UrlPath.
Constructor Details
#initialize(page, optional_params = {}) ⇒ UrlPath
Returns a new instance of UrlPath.
23 24 25 26 27 28 |
# File 'app/models/alchemy/page/url_path.rb', line 23 def initialize(page, optional_params = {}) @page = page @language = @page.language @site = @language.site @optional_params = optional_params end |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/alchemy/page/url_path.rb', line 30 def call path = 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 if @optional_params.present? uri = URI(path) uri.query = @optional_params.to_query uri.to_s else path end end |