Sha256: 2be0297f9e7daf3eb36500077b4ce9bac776bfdcf3c414937526a27c6ffaacb7

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

class Tramway::Landing::BlockDecorator < ::Tramway::Core::ApplicationDecorator
  class << self
    def collections
      [:all]
    end

    def list_attributes
      %i[page_title position view_state block_type]
    end

    def show_associations
      [:forms]
    end

    delegate :human_view_state_event_name, to: :model_class
  end

  decorate_association :forms
  decorate_association :page

  delegate_attributes :position, :title, :background, :anchor, :description, :view_name

  def public_path
    if object.published?
      Tramway::Page::Engine.routes.url_helpers.page_path slug: object.page.slug if object.page.slug.present?
    else
      Tramway::Page::Engine.routes.url_helpers.preview_path id: object.page.id
    end
  end

  def page_title
    object.page&.title
  end

  def block_type
    object.block_type_text
  end

  def view_state
    object.human_view_state_name
  end

  def link
    "##{object.anchor}"
  end

  def view_state_button_color(event)
    case event
    when :publish
      :primary
    when :hide
      :secondary
    end
  end

  def button
    if object.button.present? && object.button['button_title'].present? && object.button['button_link'].present?
      content_tag :a, href: object.button['button_link'], target: '_blank', class: 'btn btn-primary' do
        object.button['button_title']
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tramway-landing-3.2 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.12 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.11 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.10 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.9 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.8 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.7 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.6 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.5 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.4 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.3 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.2 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1.1 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.1 app/decorators/tramway/landing/block_decorator.rb
tramway-landing-3.1.0.6 app/decorators/tramway/landing/block_decorator.rb