Module: Alchemy::UrlHelper

Included in:
ElementsHelper
Defined in:
app/helpers/alchemy/url_helper.rb

Instance Method Summary collapse

Instance Method Details

#download_alchemy_attachment_path(attachment) ⇒ Object

Returns the path for downloading an alchemy attachment



55
56
57
# File 'app/helpers/alchemy/url_helper.rb', line 55

def download_alchemy_attachment_path(attachment)
  alchemy.download_attachment_path(attachment, attachment.urlname)
end

#download_alchemy_attachment_url(attachment) ⇒ Object

Returns the url for downloading an alchemy attachment



60
61
62
# File 'app/helpers/alchemy/url_helper.rb', line 60

def download_alchemy_attachment_url(attachment)
  alchemy.download_attachment_url(attachment, attachment.urlname)
end

#full_url_for_element(element) ⇒ Object

Returns the full url containing host, page and anchor for the given element



65
66
67
# File 'app/helpers/alchemy/url_helper.rb', line 65

def full_url_for_element(element)
  "#{current_server}/#{element.page.urlname}##{element_dom_id(element)}"
end

#show_alchemy_page_path(page, optional_params = {}) ⇒ Object

Returns the path for rendering an alchemy page



8
9
10
# File 'app/helpers/alchemy/url_helper.rb', line 8

def show_alchemy_page_path(page, optional_params = {})
  alchemy.show_page_path(show_page_path_params(page, optional_params))
end

#show_alchemy_page_url(page, optional_params = {}) ⇒ Object

Returns the url for rendering an alchemy page



13
14
15
# File 'app/helpers/alchemy/url_helper.rb', line 13

def show_alchemy_page_url(page, optional_params = {})
  alchemy.show_page_url(show_page_path_params(page, optional_params))
end

#show_alchemy_picture_path(picture, optional_params = {}) ⇒ Object

Deprecated.

Use Alchemy::Picture#url instead

This helper returns a path to picture for use inside a image_tag helper.

Any additional options are passed to the url_helper, so you can add arguments to your url.

Example:

<%= image_tag show_alchemy_picture_path(picture, size: '320x200', format: :png) %>


27
28
29
30
# File 'app/helpers/alchemy/url_helper.rb', line 27

def show_alchemy_picture_path(picture, optional_params = {})
  ActiveSupport::Deprecation.warn("`show_alchemy_picture_path` helper is deprecated and will be removed in Alchemy 4.0. Please use the `picture.url` method instead.")
  picture.url(optional_params)
end

#show_alchemy_picture_url(picture, optional_params = {}) ⇒ Object

Deprecated.

Use Alchemy::Picture#url instead

This helper returns an url to picture for use inside a image_tag helper.

Any additional options are passed to the url_helper, so you can add arguments to your url.

Example:

<%= image_tag show_alchemy_picture_url(picture, size: '320x200', format: :png) %>


42
43
44
45
# File 'app/helpers/alchemy/url_helper.rb', line 42

def show_alchemy_picture_url(picture, optional_params = {})
  ActiveSupport::Deprecation.warn("`show_alchemy_picture_url` helper is deprecated and will be removed in Alchemy 4.0. Please use the `picture.url` method instead.")
  picture.url(optional_params)
end

#show_page_path_params(page, optional_params = {}) ⇒ Object

Returns the correct params-hash for passing to show_page_path

Raises:

  • (ArgumentError)


48
49
50
51
52
# File 'app/helpers/alchemy/url_helper.rb', line 48

def show_page_path_params(page, optional_params = {})
  raise ArgumentError, 'Page is nil' if page.nil?
  url_params = {urlname: page.urlname}.update(optional_params)
  prefix_locale? ? url_params.update(locale: page.language_code) : url_params
end