Sha256: 7efeefa4b55324ec7edd7be8347c289c62f16afe84a10f5379f2b0c2abcbf43d

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

# Same tag as File, only it handles multiple attachments.
# Generally not a bad idea to handle rendering of this in a partial/helper.
# Example tag:
#   {{ cms:files identifier }}
#
class Occams::Content::Tag::Files < Occams::Content::Tag::File
  def content
    return "" if fragment.attachments.blank?

    fragment.attachments.collect do |attachment|
      super(file: attachment, label: attachment.filename)
    end.join(" ")
  end

  def form_field(object_name, view, index)
    name    = "#{object_name}[fragments_attributes][#{index}][files][]"
    input   = view.send(:file_field_tag, name, id: form_field_id, multiple: true, class: "form-control")

    attachments_partial =
      if fragment.attachments
        view.render(
          partial: "occams/admin/cms/fragments/form_fragment_attachments",
          locals: {
            object_name: object_name,
            index: index,
            attachments: fragment.attachments,
            fragment_id: identifier,
            multiple: true
          }
        )
      end

    yield view.safe_join([input, attachments_partial], "")
  end
end

Occams::Content::Renderer.register_tag(
  :files, Occams::Content::Tag::Files
)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
occams-1.0.1 lib/occams/content/tags/files.rb