Sha256: 2cf9d790273927dc3e873886827cd657cca9c943c4f15a70e9d6dea1ed804527

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

# Same tag as File, only it handles multiple attachments.
# Generally not a bad idea to handle rendering of this in a partial/helper
#
class ComfortableMexicanSofa::Content::Tag::Files < ComfortableMexicanSofa::Content::Tag::File

  def initialize(context, params_string)
    super
  end

  def content
    return "" if fragment.attachments.blank?

    fragment.attachments.collect do |attachment|
      super(attachment)
    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: nil, multiple: true)

    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
          }
        )
      end

    yield [input, attachments_partial].join.html_safe
  end

end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-2.0.8 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.7 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.6 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.5 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.4 lib/comfortable_mexican_sofa/content/tags/files.rb
comfortable_mexican_sofa-2.0.3 lib/comfortable_mexican_sofa/content/tags/files.rb