Sha256: 6cd185923316919f1cfe9096295b01915bce998c8164d696028f5fe54a8a4999

Contents?: true

Size: 1.96 KB

Versions: 21

Compression:

Stored size: 1.96 KB

Contents

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.
  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.
    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.
    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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
infopark_rails_connector-6.8.0.210.ed204b0 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.110.6570b45 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.72.d18d096 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.23.da7f96b app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.16.def5e85 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.15.a24f5ff app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.891.647580e app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.889.d503e42 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.883.f5f063b app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.884.4bd86e6 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.869.9609b39 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.856.8c0fec5 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.809.bdfa8c3 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.785.05d4af9 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.744.99f67fc app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.720.44fbabd app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.713.e5c3150 app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.681.7c84f4a app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.663.ceecdee app/helpers/rails_connector/cms_asset_helper.rb
infopark_rails_connector-6.8.0.beta.200.650.7c93155 app/helpers/rails_connector/cms_asset_helper.rb