Sha256: 979399ea63c0492c861f19b0c86291dea202a11407fae7b5df75ea6b54d6afae

Contents?: true

Size: 833 Bytes

Versions: 7

Compression:

Stored size: 833 Bytes

Contents

module Bard
  module FileField
    class Field < ActionView::Helpers::Tags::TextField
      def render &block
        options = @options.stringify_keys.reverse_merge({
          "directupload" => "/rails/active_storage/direct_uploads",
          "preview" => true,
        })
        add_default_name_and_id(options)

        content_tag("bard-file", options) do
          next block.call(options) if block
          Array(object.try(@method_name)).map do |attachment|
            content_tag("uploaded-file", nil, {
              name: options["name"],
              src: @template_object.url_for(attachment),
              filename: attachment.filename,
              value: attachment.signed_id,
              preview: options["preview"],
            })
          end.join("\n").html_safe
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bard-file_field-0.1.6 lib/bard/file_field/field.rb
bard-file_field-0.1.5 lib/bard/file_field/field.rb
bard-file_field-0.1.4 lib/bard/file_field/field.rb
bard-file_field-0.1.3 lib/bard/file_field/field.rb
bard-file_field-0.1.2 lib/bard/file_field/field.rb
bard-file_field-0.1.1 lib/bard/file_field/field.rb
bard-file_field-0.1.0 lib/bard/file_field/field.rb