Sha256: 82a6aa54d69b64b9ea57cd1cbeab814be6445363a1ceeea279dad2da5d7c3791

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

module Scrivito
class BaseWidgetTag < Struct.new(
    :view, :widget, :placement_modification, :render_context, :inner_tag)

  DEFAULT_RENDER_CONTEXT = 'show'
  DEFAULT_TAG = 'div'

  include TagRenderer

  def initialize(view, widget, options = {})
    super view, widget, *options.values_at(:placement_modification, :render_context, :inner_tag)
  end

  def content
    raise NotImplementedError
  end

  def tag_name
    inner_tag || DEFAULT_TAG
  end

  def options
    options = {}

    if inplace_editing_allowed?
      options['private-widget-id'] = widget.id
      options['widget-obj-class'] = widget.obj_class
      options['private-widget-description-for-editor'] = description_for_editor

      if has_widget_details_view?(widget)
        options['private-widget-has-details-view'] = true
      end

      comparison = editing_context.comparison
      options['private-widget-modification'] =
        if comparison.revision == widget.revision
          if placement_modification && !widget.in_revision(Workspace.current.revision)
            Modification::DELETED
          end
        else
          comparison.modification(widget)
        end

      options['private-widget-placement-modification'] =
        placement_modification
    end

    options
  end

  private

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

  def description_for_editor
    raise NotImplementedError
  end

  def inplace_editing_allowed?
    editing_context.authenticated_editor?
  end

  def editing_context
    EditingContextMiddleware.from_request(view.request)
  end

end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
scrivito_sdk-1.8.1 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.8.1.rc1 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.8.0 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.8.0.rc2 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.8.0.rc1 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.7.0 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.7.0.rc2 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.1 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.1.rc1 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.7.0.rc1 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.0 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.0.rc5 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.0.rc4 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.0.rc3 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.0.rc2 lib/scrivito/base_widget_tag.rb
scrivito_sdk-1.6.0.rc1 lib/scrivito/base_widget_tag.rb