app/helpers/scrivito_helper.rb in scrivito_sdk-0.65.2 vs app/helpers/scrivito_helper.rb in scrivito_sdk-0.66.0.rc1

- old
+ new

@@ -29,38 +29,45 @@ # the widgets are rendered within block tags. # @param obj_or_widget [Scrivito::BasicObj, Scrivito::BasicWidget] A {Scrivito::BasicObj} # or {Scrivito::BasicWidget} from which the +field_name+ is read. # @param field_name [String, Symbol] Which field of the Obj should be rendered. # @param html_options [Hash] HTML options to be passed to +content_tag+. + # @param editing_options [Hash] Additional editing options for widgets (e.g. +:inner_tag+) + # @option editing_options [Symbol] :inner_tag Wraps widgets inside specified tag # @param block [Proc] Optional block to render inner HTML. If none given the value of attribute # will be rendered instead. +block+ is not allowed for fields of type +widget+. # # @raise ArgumentError if the field behind +field_name+ is of type +widget+ and a +block+ is given. # # @return [String] The rendered HTML tag. # # @example Renders an <h2> tag containing the text of the +headline+ attribute of +@obj+ and assigns the tag a css class called +very_important+ - # <%= scrivito_tag :h2, @obj, :headline, class: "very_important" %> + # scrivito_tag(:h2, @obj, :headline, class: "very_important") # # @example Renders an <h2> tag containing a truncated +headline+ of the +widget+ - # <%= scrivito_tag :h2, widget, :headline do %> - # <%= truncate widget.headline %> - # <% end %> + # scrivito_tag(:h2, widget, :headline) do + # truncate(widget.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 %> + # 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, @scrivito_default_widget_template || :show - ).render(html_options, &block) + # @example Render widgetlist inside an +ul+ tag with the individual widgets inside of +li+ tags. + # scrivito_tag(:ul, @obj, :body, {}, inner_tag: :li) + # + def scrivito_tag(tag_name, obj_or_widget, field_name, + html_options = {}, editing_options = {}, &block) + Scrivito::CmsFieldTag.new(self, tag_name, obj_or_widget, editing_options.merge( + widget_template_name: @scrivito_default_widget_template || :show, + field_name: field_name.to_s + )).render(html_options, &block) end # # @api public # @@ -75,64 +82,65 @@ # @yieldparam [Scrivito::BasicObj] child Each child of +toclist+ # # @return [String] The rendered html tag # # @example - # <%= scrivito_tag_list :div, @obj, :toclist, class: "very_important" do |list, child| %> - # <%= list.tag :div, class: "also_important" do %> - # <%= link_to scrivito_path(child) do %> - # <%= scrivito_tag :span, child, :title %> - # <% end %> - # <% end %> - # <% end %> + # scrivito_tag_list(:div, @obj, :toclist, class: "very_important") do |list, child| + # list.tag(:div, class: "also_important") do + # link_to(scrivito_path(child)) do + # scrivito_tag(:span, child, :title) + # end + # end + # end # - # # results for an obj with two children in + # # result for an obj with two children: + # # + # # <div class="very_important"> + # # <div class="also_important"><a href="/child1"><span>Child 1</span></a></div> + # # <div class="also_important"><a href="/child2"><span>Child 2</span></a></div> + # # </div> # - # <div class="very_important"> - # <div class="also_important"><a href="/child1"><span>Child 1</span></a></div> - # <div class="also_important"><a href="/child2"><span>Child 2</span></a></div> - # </div> - # 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 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 + # {Scrivito::BasicObj#alt_description Obj#alt_description} 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. # 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 # # @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' + # 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 a reference attribute. - # scrivito_image_tag @obj, :my_reference + # @example Render an image tag for a reference attribute. + # scrivito_image_tag(@obj, :my_reference) # - # @example Create image tag for a link attribute. - # scrivito_image_tag @obj, :my_link + # @example Render an 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 Render an image tag for a binary attribute + # scrivito_image_tag(@obj, :my_binary) # - # @example Create image tag for a binary Obj - # scrivito_image_tag @image + # @example Render an 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 # @@ -152,19 +160,19 @@ 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, + options = Scrivito::ImageTag.new(self).options(obj, field_name, 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. # - # <%= scrivito_value @obj.title %> + # scrivito_value(@obj.title) # Renders the value, taking its type into account. # * An HtmlString will be exported by converting its links # * A Time will be exported in an international form: Year-Month-Day Hour:Minutes # * A non-HTML String will be quoted # * other values will be rendered unchanged @@ -176,11 +184,11 @@ # @api public # def scrivito_value(value) case value when Scrivito::HtmlString - Scrivito::CmsRouting.new(request, main_app).convert_links(value).html_safe + Scrivito::CmsRouting.new(request, main_app, scrivito_engine).convert_links(value).html_safe when String then h(value) when Time then h(l(value)) when Scrivito::BasicWidget render(template: value.to_show_view_path, locals: {widget: value}) else value @@ -197,12 +205,12 @@ # # @param obj [Scrivito::BasicObj] an +Obj+, whose field should be rendered. # @param field_name [String, Symbol] the field of +obj+ to be rendered. # # @example - # <%= scrivito_field @obj, :title %> - # <%= scrivito_field @obj, 'headline' %> + # scrivito_field(@obj, :title) + # scrivito_field(@obj, 'headline') # def scrivito_field(obj, field_name) scrivito_value(obj[field_name]) end @@ -220,23 +228,23 @@ # If the name of the specyfied icon is unknown, then the default icon (+:scrivito+) will be displayed. # If you are speifying your own HTML string, then make sure it is HTML safe. # @param block [Proc] the description of the thumbnail. # # @example A simple thumbnail - # <%= scrivito_thumbnail 'Content Page' do %> - # A content page. - # <% end %> + # scrivito_thumbnail('Content Page') do + # 'A content page.' + # end # # @example A thumbnail with a built-in icon - # <%= scrivito_thumbnail 'Image Widget', :image do %> - # An image widget. - # <% end %> + # scrivito_thumbnail('Image Widget', :image) do + # 'An image widget.' + # end # # @example A thumbnail with custom icon HTML - # <%= scrivito_thumbnail 'Blog', content_tag(:i, '', class: 'thumbnail-blog') do %> - # A blog post. - # <% end %> + # scrivito_thumbnail('Blog', content_tag(:i, '', class: 'thumbnail-blog')) do + # 'A blog post.' + # end # def scrivito_thumbnail(title, icon = :scrivito, &block) if icon.is_a?(Symbol) icon_code = { content: '&#xf122;', @@ -266,18 +274,18 @@ # # @param title [String] title of the attribute group. # @param block [Proc] content of the attribute group. # # @example - # <%= scrivito_details_for 'Title and Category' do %> - # <%= scrivito_tag :div, @obj, :title %> - # <%= scrivito_tag :div, @obj, :category %> - # <% end %> + # scrivito_details_for('Title and Category') do + # concat scrivito_tag(:div, @obj, :title) + # concat scrivito_tag(:div, @obj, :category) + # end # - # <%= scrivito_details_for do %> - # <%= scrivito_tag :div, @obj, :abstract %> - # <% end %> + # scrivito_details_for do + # scrivito_tag(:div, @obj, :abstract) + # end # def scrivito_details_for(title = nil, &block) content_tag(:div, class: 'scrivito_content_group') do capture do if title @@ -285,9 +293,52 @@ end yield end end end + + # @!group Details Dialog Size + + # Set the size of the page and widget details dialog to +large+. + # @example + # scrivito_large_dialog do + # scrivito_details_for('Title and Category') do + # concat scrivito_tag(:div, @obj, :title) + # concat scrivito_tag(:div, @obj, :category) + # end + # end + # @param block [Proc] Block to render inner HTML. + # @return [String] + # @api public + def scrivito_large_dialog(&block) + Scrivito::DialogSizeHelper.render_dialog_with_size(self, 'large', &block) + end + + # Set the size of the page and widget details dialog to +medium+ (default). + # @example + # scrivito_medium_dialog do + # # see scrivito_large_dialog example + # end + # @param block [Proc] Block to render inner HTML. + # @return [String] + # @api public + def scrivito_medium_dialog(&block) + Scrivito::DialogSizeHelper.render_dialog_with_size(self, 'medium', &block) + end + + # Set the size of the page and widget details dialog to +small+. + # @example + # scrivito_small_dialog do + # # see scrivito_large_dialog example + # end + # @param block [Proc] Block to render inner HTML. + # @return [String] + # @api public + def scrivito_small_dialog(&block) + Scrivito::DialogSizeHelper.render_dialog_with_size(self, 'small', &block) + end + + # @!endgroup # # Renders all tags needed in the HTML head. # @api public #