class RefileInput
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/inputs/refile_input.rb, line 2 def initialize *args super @reference = SecureRandom.hex end
Public Instance Methods
file_input_html_options()
click to toggle source
# File lib/inputs/refile_input.rb, line 8 def file_input_html_options options[:data] ||= {} options[:data][:reference] = @reference attacher = object.send(:"#{method}_attacher") options[:accept] = attacher.definition.accept host = options[:host] || Refile.cdn_host if options[:direct] backend_name = Refile.backends.key(attacher.cache) url = ::File.join(host, Rails.application.routes.url_helpers.refile_app_path, backend_name) options[:data].merge!(direct: true, as: "file", url: url) end if options[:presigned] and attacher.cache.respond_to?(:presign) url = ::File.join(host, Rails.application.routes.url_helpers.refile_app_path, backend_name, "presign") options[:data].merge!(direct: true, url: url) end options.merge(input_html_options) end
to_html()
click to toggle source
# File lib/inputs/refile_input.rb, line 36 def to_html input_wrapping do label_html << builder.hidden_field(method, hidden_input_html_options) << builder.file_field(method, file_input_html_options) << image_preview_content end end
Private Instance Methods
image_preview?()
click to toggle source
# File lib/inputs/refile_input.rb, line 51 def image_preview? !!options[:image_preview] end
image_preview_content()
click to toggle source
# File lib/inputs/refile_input.rb, line 47 def image_preview_content image_preview? ? image_preview_html(options[:image_preview]) : '' end
image_preview_html(options)
click to toggle source
# File lib/inputs/refile_input.rb, line 55 def image_preview_html(options) refile_app_path = Rails.application.routes.url_helpers.refile_app_path url = Refile.attachment_url @object, method, *options, prefix: refile_app_path template.content_tag(:div, template.image_tag(url), class: 'image-preview') end