Sha256: 5efe86f529b16c190015264e937214972fdb3a5d0538f5883a37f8ff62c09934

Contents?: true

Size: 1.29 KB

Versions: 36

Compression:

Stored size: 1.29 KB

Contents

module Scrivito

class WidgetTag < BaseWidgetTag
  def render
    super
  rescue => error
    if handle_render_errors?
      errored_widget_tag(error).render
    else
      raise error
    end
  end

  def content
    render_content(render_context)
  end

  private

  def errored_widget_tag(error)
    ErroredWidgetTag.new(view, widget, placement_modification: placement_modification,
        render_context: render_context, inner_tag: inner_tag, error: error)
  end

  def description_for_editor
    widget.description_for_editor
  end

  def render_content(context)
    template_path = widget.public_send("#{context}_view_path")
    view.render(template: template_path, locals: {widget: widget})
  rescue ActionView::MissingTemplate
    if context == DEFAULT_RENDER_CONTEXT
      if view.scrivito_user
        view.content_tag(:h4, "Error: Missing 'show' template for #{widget.obj_class}",
          class: 'scrivito_error')
      end
    else
      render_content(DEFAULT_RENDER_CONTEXT)
    end
  end

  def render_context
    super || DEFAULT_RENDER_CONTEXT
  end

  def has_widget_details_view?(widget)
    view.lookup_context.find(widget.details_view_path).present?
  rescue ActionView::MissingTemplate
    false
  end

  def handle_render_errors?
    !Rails.env.development? && !Rails.env.test?
  end
end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
scrivito_sdk-1.1.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-1.1.0.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-1.0.0 lib/scrivito/widget_tag.rb
scrivito_sdk-1.0.0.rc4 lib/scrivito/widget_tag.rb
scrivito_sdk-1.0.0.rc3 lib/scrivito/widget_tag.rb
scrivito_sdk-1.0.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-1.0.0.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.90.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.90.0.rc3 lib/scrivito/widget_tag.rb
scrivito_sdk-0.90.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.90.0.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.71.2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.71.1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.71.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.71.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.71.0.rc1 lib/scrivito/widget_tag.rb