Sha256: 2dbcc36dfeeba4263e78d9ca7346dd58b00b4f3c03910b12c2ae51cc87c3118b

Contents?: true

Size: 860 Bytes

Versions: 2

Compression:

Stored size: 860 Bytes

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

  delegate :title, to: :object

  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
    if object.published?
      Tramway::Page::Engine.routes.url_helpers.page_path slug: object.slug
    else
      Tramway::Page::Engine.routes.url_helpers.preview_path id: object.id
    end
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tramway-page-1.5.1.1 app/decorators/tramway/page/page_decorator.rb
tramway-page-1.5.1 app/decorators/tramway/page/page_decorator.rb