lib/scrivito/controller_actions.rb in scrivito_sdk-0.70.2 vs lib/scrivito/controller_actions.rb in scrivito_sdk-0.71.0.rc1
- old
+ new
@@ -38,67 +38,70 @@
deliver_file if @obj.binary?
end
def show_widget
widget = load_widget
- widget_tag = Scrivito::WidgetTag.new(view_context, widget, nil,
- params[:template_name], params[:inner_tag])
+ widget_tag = Scrivito::WidgetTag.new(view_context, widget,
+ render_context: params[:template_name], inner_tag: params[:inner_tag])
render text: widget_tag.render, layout: false
end
def widget_details
assert_dialog_layout
widget = load_widget
- template_path = "#{widget.obj_class_name.underscore}/details"
- @scrivito_default_widget_template = :details
- render template_path, layout: 'scrivito_dialog', locals: {widget: widget}
+ @scrivito_widget_render_context = :details
+ render widget.details_view_path, layout: 'scrivito_dialog', locals: {widget: widget}
end
def page_details
assert_dialog_layout
- @scrivito_default_widget_template = :details
+ @scrivito_widget_render_context = :details
render @obj.details_view_path, layout: 'scrivito_dialog'
rescue ActionView::MissingTemplate
render 'scrivito/page_details', layout: 'scrivito_dialog'
end
- # How to handle widget errors in +production+.
+ # @!method on_scrivito_widget_error(widget, error)
+ # How to handle widget errors in +production+.
#
- # When an exception is raised from within a widget, the entire page is not available.
- # Often, this is the case in production if the developer has forgotten to handle specific
- # content scenarios such as empty date attributes, missing titles, unmanaged enum values, etc.
- # but also for simple coding mistakes during development.
+ # When an exception is raised from within a widget, the entire page is not available.
+ # Often, this is the case in production if the developer has forgotten to handle specific
+ # content scenarios such as empty date attributes, missing titles, unmanaged enum values, etc.
+ # but also for simple coding mistakes during development.
#
- # Override this method to prevent the entire page from being unavailable due to widget errors.
+ # By default, Scrivito handles exceptions raised while rendering a widget by adding a
+ # placeholder text to the HTML indicating that the widget couldn't be rendered. In addition,
+ # the exception is logged alongside with its backtrace.
#
- # The overridden method allows to:
- # * catch a widget error and replace it with an HTML placeholder.
- # * report a widget error to an external service like Honeybadger or Airbrake.
+ # Override this method to adapt this behaviour.
#
- # This method is _not_ called if Rails is in the +development+ or +test+ environment.
- # In those environments, all widget errors are just raised.
+ # The overridden method allows to:
+ # * catch a widget error and replace it with an HTML placeholder.
+ # * report a widget error to an external service like Honeybadger or Airbrake.
#
- # By default, this method just reraises the given error.
+ # This method is _not_ called if Rails is in the +development+ or +test+ environment.
+ # In those environments, all widget errors are just raised.
#
- # @param widget [Scrivito::BasicWidget] the flawed widget
- # @param error [StandardError] the error that occurred
- # @raise [StandardError] if this method is not overridden, the +error+ passed to it is reraised.
+ # @param widget [Scrivito::BasicWidget] the flawed widget
+ # @param error [StandardError] the error that occurred
+ # @raise [StandardError] if this method is not overridden, the +error+ passed to it
+ # is reraised.
#
- # @example Notify external service about widget error and render an HTML placeholder:
- # def on_scrivito_widget_error(widget, error)
- # # Report error to external service (e.g. Honeybadger or Airbrake):
- # Honeybadger.notify(error)
- # notify_airbrake(error)
+ # @example Notify external service about widget error and render an HTML placeholder:
+ # def on_scrivito_widget_error(widget, error)
+ # # Report error to external service (e.g. Honeybadger or Airbrake):
+ # Honeybadger.notify(error)
+ # notify_airbrake(error)
#
- # # Replace corrupted widget output with a placeholder:
- # message = "Rendering #{widget.description_for_editor} failed with #{error.message}"
- # return "<!--#{message}-->".html_safe if Rails.env.production?
- # "<p>#{message}</p>".html_safe
- # end
- # @api public
- def on_scrivito_widget_error(widget, error)
- raise error
- end
+ # # Replace corrupted widget output with a placeholder:
+ # message = "Rendering #{widget.description_for_editor} failed with #{error.message}"
+ # return "<!--#{message}-->".html_safe if Rails.env.production?
+ # "<p>#{message}</p>".html_safe
+ # end
+ #
+ # @api public
+
+ # This empty line is necessary for yard to function correctly
module ClassMethods
#
# This method indicates if this controller should be used automatically when an +Obj+ is
# requested via the SDK's standard routes. It returns +true+ by default.