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

- old
+ new

@@ -34,10 +34,18 @@ # @example Renders an <h2> tag containing an escaped +headline+. # <%= scrivito_tag :h2, @obj, :headline do %> # <%= strip_tags @obj.headline %> # <% end %> # + # @example Render a download link for a PDF document + # <%= scrivito_tag :div, @obj, :pdf do %> + # <% if @obj.pdf %> + # Download: <%= link_to @obj.pdf.filename, @obj.pdf.url %> + # <% elsif scrivito_user %> + # Drop PDF here to upload + # <% end %> + # <% end %> def scrivito_tag(tag_name, obj_or_widget, field_name, html_options = {}, &block) Scrivito::CmsFieldTag.new( self, tag_name, obj_or_widget, field_name.to_s ).render(html_options, &block) end @@ -85,11 +93,12 @@ # @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 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 + # attribute, which contains the image or additional HTML attributes for the tag. + # The +field_name+ can be omitted for binary Objs and +blob+ will be used as default. # @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 @@ -107,26 +116,35 @@ # 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 + # @example Create image tag for a binary Obj # scrivito_image_tag @image # # @return [String] HTML image tag # - # @raise [ScrivitoError] if +field_name+ is not set and obj is not binary + # @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 + if field_name.blank? + if obj.binary? + field_name = :blob + else + raise Scrivito::ScrivitoError, + "when omitting `field_name' you have to pass a binary obj" + end + end + options = Scrivito::ImageTagHelper.new(self).options(obj, field_name, tag_options.with_indifferent_access, editing_options.with_indifferent_access) scrivito_tag('img', obj, field_name, options) end @@ -235,10 +253,9 @@ def scrivito_head_tags layout_tags = Scrivito::LayoutTags.new(self) capture do concat layout_tags.editing_auth_warning concat layout_tags.generator_meta_tag - concat layout_tags.reset_stylesheet_tag end end # # Renders all tags needed in the HTML body.