Sha256: a0ab46b1be6f4ef9a4633668e8faf13361eeac8c3663a476a4b9daa40838339c

Contents?: true

Size: 1.45 KB

Versions: 18

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Decidim
  # A Helper to render and link to resources.
  module AttachmentsHelper
    include IconHelper

    # Renders a the attachments of a model that includes the
    # HasAttachments concern.
    #
    # attached_to - The model to render the attachments from.
    def attachments_for(attached_to)
      return unless attached_to.is_a?(Decidim::HasAttachments)

      cell "decidim/tab_panels", attachments_tab_panel_items(attached_to)
    end

    def attachments_tab_panel_items(attached_to)
      [
        {
          enabled: attached_to.photos.any?,
          id: "images",
          text: t("decidim.application.photos.photos"),
          icon: resource_type_icon_key("images"),
          method: :cell,
          args: ["decidim/images_panel", attached_to]
        },
        {
          enabled: attached_to.documents.any?,
          id: "documents",
          text: t("decidim.application.documents.documents"),
          icon: resource_type_icon_key("documents"),
          method: :cell,
          args: ["decidim/documents_panel", attached_to]
        }
      ]
    end

    # Renders the attachment's title.
    # Checks if the attachment's title is translated or not and use
    # the correct render method.
    #
    # attachment - An Attachment object
    #
    # Returns String.
    def attachment_title(attachment)
      attachment.title.is_a?(Hash) ? translated_attribute(attachment.title) : attachment.title
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
decidim-core-0.30.0.rc3 app/helpers/decidim/attachments_helper.rb
decidim-core-0.30.0.rc2 app/helpers/decidim/attachments_helper.rb
decidim-core-0.30.0.rc1 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.2 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.5 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.1 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.4 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.0 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.3 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.0.rc4 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.0.rc3 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.0.rc2 app/helpers/decidim/attachments_helper.rb
decidim-core-0.29.0.rc1 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.2 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.1 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.0 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.0.rc5 app/helpers/decidim/attachments_helper.rb
decidim-core-0.28.0.rc4 app/helpers/decidim/attachments_helper.rb