Sha256: 1b627b2c4c8e7352343df7303c793b3037086d342afe0a78fbb8927509a94dd0

Contents?: true

Size: 1.45 KB

Versions: 18

Compression:

Stored size: 1.45 KB

Contents

module Scrivito

class WidgetTag < Struct.new(:view, :widget, :placement_modification)
  include TagRenderer

  def tag_name
    :div
  end

  def content
    view.render(template: template, locals: {widget: widget})
  end

  def options
    options = {}

    if inplace_editing_allowed?
      options['private-widget-id'] = widget.id
      options['widget-obj-class'] = widget.obj_class_name
      options['private-widget-description-for-editor'] = widget.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
            unless widget.in_revision(Workspace.current.revision)
              Modification::DELETED
            end
          end
        else
          comparison.modification(widget)
        end

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

    options
  end

  private

  def template
    widget.to_show_view_path
  end

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

  def inplace_editing_allowed?
    editing_context.authenticated_editor?
  end

  def editing_context
    EditingContextMiddleware.from_request(view.request)
  end

end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
scrivito_sdk-0.50.1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.50.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.50.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.50.0.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.42.1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.42.1.rc3 lib/scrivito/widget_tag.rb
scrivito_sdk-0.42.1.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.42.1.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.42.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.41.1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.41.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.41.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.41.0.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.40.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.40.0.rc2 lib/scrivito/widget_tag.rb
scrivito_sdk-0.40.0.rc1 lib/scrivito/widget_tag.rb
scrivito_sdk-0.30.0 lib/scrivito/widget_tag.rb
scrivito_sdk-0.30.0.rc1 lib/scrivito/widget_tag.rb