Sha256: 0058b8662d29d828e4a5408ae8af5ed954793a5b0a53208e4b97d13fc8ab090c

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module RailsConnector

  module CmsTagHelper

    # A wrapper for [http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag]
    # If {cms_editor_mode?} returns true, it also renders additional data attributes, which are needed for inplace editing.
    # @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
    # @param obj [Obj] A {Obj} from which attribute is read.
    # @param attribute [String, Symbol] Which attribute should be render.
    # @param options [Hash] Additional options, which are passed to +content_tag+.
    def cms_tag(tag_name, obj, attribute, options = {})
      options = options.merge({
        'data-ip-field-id' => obj.id,
        'data-ip-field-obj-class' => obj.obj_class,
        'data-ip-field-name' => attribute,
        'data-ip-field-type' => obj.type_of_attribute(attribute.to_s),
        # Concate with empty string to disable html_safe:
        'data-ip-field-original-content' => "" + display_original_value(obj[attribute]),
      }) if cms_editor_mode?

      content_tag(tag_name, display_value(obj[attribute]), options)
    end

    def cms_editor_mode?
      !Workspace.current.published?
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.3.174.51542603 app/helpers/rails_connector/cms_tag_helper.rb
infopark_cloud_connector-6.8.3.115.227021242 app/helpers/rails_connector/cms_tag_helper.rb