Class: Alchemy::Admin::UploaderButton

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/alchemy/admin/uploader_button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object:, file_attribute:, redirect_url:, accept: nil, dropzone: nil, label: nil, layout: nil, inline_label: false) ⇒ UploaderButton

Returns a new instance of UploaderButton.



8
9
10
11
12
13
14
15
16
17
# File 'app/components/alchemy/admin/uploader_button.rb', line 8

def initialize(object:, file_attribute:, redirect_url:, accept: nil, dropzone: nil, label: nil, layout: nil, inline_label: false)
  @object = object
  @file_attribute = file_attribute
  @redirect_url = redirect_url
  @dropzone = dropzone || "#main_content"
  @label = label
  @layout = layout
  @accept = accept || ((file_types.to_a == ["*"]) ? nil : file_types.map { |type| ".#{type}" }.join(", "))
  @inline_label = inline_label
end

Instance Attribute Details

#accept ⇒ Object (readonly)

Returns the value of attribute accept.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def accept
  @accept
end

#dropzone ⇒ Object (readonly)

Returns the value of attribute dropzone.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def dropzone
  @dropzone
end

#file_attribute ⇒ Object (readonly)

Returns the value of attribute file_attribute.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def file_attribute
  @file_attribute
end

#inline_label ⇒ Object (readonly)

Returns the value of attribute inline_label.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def inline_label
  @inline_label
end

#layout ⇒ Object (readonly)

Returns the value of attribute layout.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def layout
  @layout
end

#object ⇒ Object (readonly)

Returns the value of attribute object.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def object
  @object
end

#redirect_url ⇒ Object (readonly)

Returns the value of attribute redirect_url.



6
7
8
# File 'app/components/alchemy/admin/uploader_button.rb', line 6

def redirect_url
  @redirect_url
end

Instance Method Details

#call ⇒ Object



19
20
21
22
23
24
25
# File 'app/components/alchemy/admin/uploader_button.rb', line 19

def call
   "alchemy-uploader", "redirect-url": redirect_url, dropzone:, layout: do
    form_for [alchemy, :admin, object], html: {multipart: true, class: "upload-button"} do |f|
      safe_join([upload_hash_field(f), upload_label(f)].compact)
    end
  end
end