Module: RailsConnector::CmsAssetHelper

Includes:
ActionView::Helpers::AssetUrlHelper
Included in:
DefaultCmsHelper
Defined in:
app/helpers/rails_connector/cms_asset_helper.rb

Overview

This module contains helpers that can be used to reference images and other assets stored in the CMS.

Use this helper to take advantage of rails’ asset host mechanism. (See api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html for details about asset hosts.) If your application does not use any asset hosts, the helper will generate regular (=non asset host) pathes.

Instance Method Summary collapse

Instance Method Details

#cms_asset_path(target) ⇒ Object

Calculate the path to an asset stored in the CMS.

The path can be used to reference a cms object inside an html page. target can be an Obj or a Link or a LinkList. If your application is configured to use asset hosts, the path will reference the object using one of your asset hosts.



38
39
40
41
42
# File 'app/helpers/rails_connector/cms_asset_helper.rb', line 38

def cms_asset_path(target)
  regular_path = cms_path(target)
  return regular_path if regular_path.first == "#"
  asset_path(regular_path)
end

#cms_image_tag(target, options = {}) ⇒ Object

Returns an html image tag for an image stored in the CMS.

target is the image from the cms to be referenced in the image tag. target can be an Obj or a Link or a LinkList. options can be used to specify additional html attributes for the tag. If you do not specify an html alt attribute, the helper method will use target‘s display_title as the html alt attribute. If your application is configured to use asset hosts, the images tag will reference the image using one of your asset hosts.



22
23
24
25
26
27
28
29
# File 'app/helpers/rails_connector/cms_asset_helper.rb', line 22

def cms_image_tag(target, options = {})
  options.symbolize_keys!

  options[:src] = cms_asset_path(target)
  options[:alt] ||= display_title(target)

  tag("img", options)
end