Sha256: e9f2262fca860e71159eee0517aca06de7cb16eeac3f9a80478a3daf5366aa47

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders the card of the given instance of a Component
  # delegated to the components' cell if specified in the manifest
  # otherwise a primary cell wil be shown.
  class CardCell < Decidim::ViewModel
    def show
      if resource_cell?
        cell(resource_cell, model, options)
      else
        render :show
      end
    end

    private

    def resource_cell?
      resource_cell.present?
    end

    def resource_cell
      if model.respond_to?(:resource_manifest) && model.resource_manifest.card.present?
        @resource_cell ||= model.resource_manifest.card
      elsif ["Decidim::Proposals::OfficialAuthorPresenter", "Decidim::Debates::OfficialAuthorPresenter"].include? model.class.to_s
        @resource_cell ||= "decidim/author"
      elsif ["Decidim::User", "Decidim::UserGroup"].include? model.model_name.name
        @resource_cell ||= "decidim/author"
      end
    end

    def title
      return if model.respond_to? :title
      model.name
    end

    def body
      return if model.respond_to? :body
      model.about
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-core-0.15.2 app/cells/decidim/card_cell.rb
decidim-core-0.15.1 app/cells/decidim/card_cell.rb
decidim-core-0.15.0 app/cells/decidim/card_cell.rb
decidim-core-0.14.4 app/cells/decidim/card_cell.rb
decidim-core-0.14.3 app/cells/decidim/card_cell.rb
decidim-core-0.14.2 app/cells/decidim/card_cell.rb
decidim-core-0.14.1 app/cells/decidim/card_cell.rb
decidim-core-0.13.1 app/cells/decidim/card_cell.rb
decidim-core-0.12.2 app/cells/decidim/card_cell.rb
decidim-core-0.13.0 app/cells/decidim/card_cell.rb
decidim-core-0.12.1 app/cells/decidim/card_cell.rb
decidim-core-0.13.0.pre1 app/cells/decidim/card_cell.rb
decidim-core-0.12.0 app/cells/decidim/card_cell.rb
decidim-core-0.12.0.pre app/cells/decidim/card_cell.rb