Sha256: eb90ce670da5ab6f38cbd7d5cf0b2c977f6895f0c60cbf1cef1d3036eb7e0cc0

Contents?: true

Size: 1.27 KB

Versions: 17

Compression:

Stored size: 1.27 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 ComfortableMexicanSofa::Content::Tag::Files < ComfortableMexicanSofa::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: "comfy/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

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

Version data entries

17 entries across 17 versions & 6 rubygems

Version Path
comfortable_mexican_sofa-2.0.19 lib/comfortable_mexican_sofa/content/tags/files.rb
PixelForce_ETS-0.0.2 lib/comfortable_mexican_sofa/content/tags/files.rb
PixelForce_ETS-0.0.1 lib/comfortable_mexican_sofa/content/tags/files.rb
kcyEtsTest2-0.0.4 lib/comfortable_mexican_sofa/content/tags/files.rb
kcyEtsTest2-0.0.3 lib/comfortable_mexican_sofa/content/tags/files.rb
kcyEtsTest2-0.0.2 lib/comfortable_mexican_sofa/content/tags/files.rb
kcyEtsTest2-0.0.1 lib/comfortable_mexican_sofa/content/tags/files.rb
kcyEtsTest-0.0.1 lib/comfortable_mexican_sofa/content/tags/files.rb
kcyEtsTest-2.2.19 lib/comfortable_mexican_sofa/content/tags/files.rb
ComfortableMexicanSofa-2.0.18 lib/comfortable_mexican_sofa/content/tags/files.rb
kcy1-1.0 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.18 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.17 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.16 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.15 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.14 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.13 lib/comfortable_mexican_sofa/content/tags/files.rb