Module: RailsConnector::CmsAssetHelper

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.

Instance Method Summary collapse

Instance Method Details

#cms_image_tag(target, tag_options = {}) ⇒ String #cms_image_tag(obj, linklist, tag_options = {}, editing_options = {}) ⇒ String

Note:

There are two different signatures of this method: the first one generates an HTML image tag with no inplace editing possible, the second one generated an HTML image tag for inplace editing.

Calculates an HTML image tag for an image stored in the CMS.

Overloads:

  • #cms_image_tag(target, tag_options = {}) ⇒ String
    Note:

    If you do not specify an HTML alt attribute, the helper method will use target‘s display_title.

    Calculates HTML image tag (no inplace editing possible).

    Examples:

    cms_image_tag @target
    cms_image_tag @target, alt: 'Interesting picture', class: 'my_image'

    Parameters:

    • target (Obj, Link)

      Target containing image stored in CMS.

    • tag_options (Hash) (defaults to: {})

      Additional HTML attributes for the tag.

  • #cms_image_tag(obj, linklist, tag_options = {}, editing_options = {}) ⇒ String
    Note:

    If you do not specify an HTML alt attribute, the helper method will use display_title of the target object.

    Calculates HTML image tag for inplace editing.

    Examples:

    cms_image_tag @obj, :my_linklist
    cms_image_tag @obj, :my_linklist, alt: 'Interesting picture', class: 'my_image'
    cms_image_tag @obj, :my_linklist, {}, placeholder: image_path('my_placeholder.png')
    cms_image_tag @obj, :my_linklist, {class: 'my_image'}, placeholder: 'http://placehold.it/350x150'

    Parameters:

    • obj (Obj)

      Obj with an attribute of type LinkList.

    • linklist (String, Symbol)

      Name of LinkList attribute, which contains the image.

    • tag_options (Hash) (defaults to: {})

      Additional HTML attributes for the tag.

    • editing_options (Hash) (defaults to: {})

      Additional options for inplace editing.

    Options Hash (editing_options):

    • :placeholder (String) — default: '/assets/rails_connector/image_placeholder.png'

      URL or path to image to be displayed if target is missing.

Returns:

  • (String)

    HTML image tag



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/rails_connector/cms_asset_helper.rb', line 43

def cms_image_tag(*args)
  if args.second.nil? || args.second.is_a?(Hash)
    # Backwards compatibility.
    target = args.first

    tag_options = args.second || {}
    tag_options.symbolize_keys!
    tag_options[:src] = cms_path(target)
    tag_options[:alt] ||= display_title(target)

    tag('img', tag_options)
  else
    obj             = args.first
    field_name      = args.second
    tag_options     = args.third || {}
    editing_options = args.fourth || {}

    cms_tag('img', obj, field_name, cms_image_tag_options(obj, field_name,
        tag_options.symbolize_keys, editing_options.symbolize_keys))
  end

end