Sha256: d8e62c9fe42d70d2b0bf86dabfaef28ea41de60a22a7425ad64dbba20d873437

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

class Tramway::Page::PageDecorator < ::Tramway::Core::ApplicationDecorator
  class << self
    def collections
      [:all]
    end

    def show_associations
      [:blocks]
    end

    delegate :human_view_state_event_name, to: :model_class
  end

  def additional_buttons
    {
      show: [
        { 
          url: Tramway::Page::Engine.routes.url_helpers.preview_path(id: object.id),
          method: :get,
          text: 'Preview',
          color: :primary
        }
      ]
    }
  end

  delegate_attributes :title, :page_type, :body

  decorate_association :blocks, state_machines: [:view_state]

  def lead
    object.body.first 200
  end

  def link
    Tramway::Page::Engine.routes.url_helpers.page_path slug: object.slug
  end

  def public_path
    Tramway::Page::Engine.routes.url_helpers.page_path slug: object.slug if object.published?
  end

  def view_state_button_color(event)
    case event
    when :publish
      :success
    when :hide
      :default
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tramway-page-1.6 app/decorators/tramway/page/page_decorator.rb
tramway-page-1.5.4.3 app/decorators/tramway/page/page_decorator.rb
tramway-page-1.5.4.2 app/decorators/tramway/page/page_decorator.rb
tramway-page-1.5.4.1 app/decorators/tramway/page/page_decorator.rb