app/helpers/scrivito_helper.rb in scrivito_sdk-0.30.0.rc1 vs app/helpers/scrivito_helper.rb in scrivito_sdk-0.30.0

- old
+ new

@@ -76,41 +76,58 @@ def scrivito_tag_list(tag_name, obj, field_name, options = {}, &block) Scrivito::ChildListTag.new(tag_name, obj, field_name.to_s, self).render(options, &block) end # - # Calculates an HTML image tag of an image storeg in the CMS for inplace editing. + # Calculates an HTML image tag of an image stored in the CMS for inplace editing. # # @api public # # @note If you do not specify an HTML +alt+ attribute, the helper method will use # +display_title+ of the target object # - # @param [Obj] obj Obj with an attribute of type +LinkList+ - # @param [String, Symbol] field_name Name of +LinkList+, +reference+ or +link+ attribute, - # which contains the image - # @param [Hash] tag_options Additional HTML attributes for the tag + # @param [Obj] obj Obj with a +link_list+, +reference+, +link+ or +binary+ attribute + # @param [String, Symbol, Hash] field_name_or_tag_options Name of +link_list+, +reference+, +link+, or +binary+ + # attribute, which contains the image or additional HTML attributes for the tag + # @param [Hash] tag_or_editing_options Additional HTML attributes for the tag or + # the editing options if no +field_name+ was given # @param [Hash] editing_options Additional options for inplace editing # @option editing_options [String] :placeholder ('/assets/scrivito/image_placeholder.png') URL # or path to image to be displayed if target is missing # # @example # scrivito_image_tag @obj, :my_linklist # scrivito_image_tag @obj, :my_linklist, alt: 'Interesting picture', class: 'my_image' # scrivito_image_tag @obj, :my_linklist, {}, placeholder: image_path('my_placeholder.png') # scrivito_image_tag @obj, :my_linklist, {class: 'my_image'}, placeholder: 'http://placehold.it/350x150' # - # @example Create image tag for reference attributes. + # @example Create image tag for a reference attribute. # scrivito_image_tag @obj, :my_reference # - # @example Create image tag for link attributes. + # @example Create image tag for a link attribute. # scrivito_image_tag @obj, :my_link # + # @example Create image tag for a binary attribute + # scrivito_image_tag @obj, :my_binary + # + # @example Create image tag for a binary object + # scrivito_image_tag @image + # # @return [String] HTML image tag # - def scrivito_image_tag(obj, field_name, tag_options = {}, editing_options = {}) + # @raise [ScrivitoError] if +field_name+ is not set and obj is not binary + # + def scrivito_image_tag(obj, field_name_or_tag_options=nil, + tag_or_editing_options = {}, editing_options = {}) + field_name, tag_options, editing_options = + if field_name_or_tag_options.is_a?(Hash) + [nil, field_name_or_tag_options, tag_or_editing_options] + else + [field_name_or_tag_options, tag_or_editing_options, editing_options] + end + options = Scrivito::ImageTagHelper.new(self).options(obj, field_name, - tag_options.symbolize_keys, editing_options.symbolize_keys) + tag_options.with_indifferent_access, editing_options.with_indifferent_access) scrivito_tag('img', obj, field_name, options) end # # Renders an attribute <em>value</em> of a CMS model.