Method: ScrivitoHelper#scrivito_thumbnail

Defined in:
app/helpers/scrivito_helper.rb

#scrivito_thumbnail(title, icon = :scrivito, &block) ⇒ Object

Thumbnail helper generates HTML for the page class selection dialog and the widget class selection dialog. The generated HTML has appropriate DOM structure and CSS classes, which are compatible with the CSS of the SDK. By using this helper you ensure, that the look of your thumbnails fits into the SDK's design.

Examples:

A simple thumbnail

scrivito_thumbnail('Content Page') do
  'A content page.'
end

A thumbnail with a built-in icon

scrivito_thumbnail('Image Widget', :image) do
  'An image widget.'
end

A thumbnail with custom icon HTML

scrivito_thumbnail('Blog', (:i, '', class: 'thumbnail-blog')) do
  'A blog post.'
end

Parameters:

  • title (String)

    title of the thumbnail, e.g. “Content Page” or “Image Widget”.

  • icon (Symbol, String) (defaults to: :scrivito)

    icon of the thumbnail. You can use one of the built-in icons or specify your own HTML. There are following built-in icons: :content, :headline, :image, :scrivito and :text. If the name of the specified icon is unknown, then the default icon (:scrivito) will be displayed. If you are specifying your own HTML string, then make sure it is HTML safe.

  • block (Proc)

    the description of the thumbnail.


287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'app/helpers/scrivito_helper.rb', line 287

def scrivito_thumbnail(title, icon = :scrivito, &block)
  if icon.is_a?(Symbol)
    icon_code = {
      content:  '',
      headline: '',
      image:    '',
      scrivito: '',
      text:     '',
    }.fetch(icon, '')
    icon = (:i, icon_code.html_safe, class: 'scrivito_icon')
  end

  (:div, 'data-scrivito-private-thumbnail-title' => title) do
    capture do
      concat (:div, icon, class: 'thumbnail')
      concat (:div, title, class: 'title')

      if block_given?
        concat (:div, class: 'description', &block)
      else
        concat (:div, nil, class: 'description')
      end
    end
  end
end