module RailsConnector # 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 http://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. # @api public module CmsAssetHelper # 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. # @api public def cms_image_tag(target, options = {}) options.symbolize_keys! options[:src] = cms_asset_path(target) options[:alt] ||= display_title(target) tag("img", options) end # 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. # @api public def cms_asset_path(target) regular_path = cms_path(target) return regular_path if regular_path.first == "#" asset_paths.compute_public_path(regular_path, nil) end private def display_title(target) if target.respond_to?(:display_title) return target.display_title elsif target.respond_to?(:first) && target.first.respond_to?(:display_title) return target.first.display_title end end end end