Class: Uploader::Helpers::FieldTag
- Inherits:
-
Object
- Object
- Uploader::Helpers::FieldTag
- Defined in:
- lib/uploader/helpers/field_tag.rb
Constant Summary collapse
- RESERVED_OPTIONS_KEYS =
%w[method_name object_name theme value object sortable].freeze
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
- #attachments_path(options = {}) ⇒ Object
- #exists? ⇒ Boolean
- #extension_whitelist ⇒ Object
- #id ⇒ Object
-
#initialize(object_name, method_name, template, options = {}) ⇒ FieldTag
constructor
Wrapper for render uploader field Usage:.
- #input_html ⇒ Object
- #input_html_options ⇒ Object
- #klass ⇒ Object
- #method_name ⇒ Object
- #multiple? ⇒ Boolean
- #object_name ⇒ Object
-
#render(locals = {}) ⇒ Object
:nodoc:.
- #sortable? ⇒ Boolean
- #value ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(object_name, method_name, template, options = {}) ⇒ FieldTag
Wrapper for render uploader field Usage:
uploader = FieldTag.new(object_name, method_name, template, )
uploader.render
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/uploader/helpers/field_tag.rb', line 18 def initialize(object_name, method_name, template, = {}) #:nodoc: @options = { object_name: object_name, method_name: method_name }.merge() @template = template @theme = (@options.delete(:theme) || 'default') @value = @options.delete(:value) if @options.key?(:value) @object = @options.delete(:object) if @options.key?(:object) @object ||= @template.instance_variable_get("@#{object_name}") end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
8 9 10 |
# File 'lib/uploader/helpers/field_tag.rb', line 8 def object @object end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
8 9 10 |
# File 'lib/uploader/helpers/field_tag.rb', line 8 def template @template end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
8 9 10 |
# File 'lib/uploader/helpers/field_tag.rb', line 8 def theme @theme end |
Instance Method Details
#attachments_path(options = {}) ⇒ Object
70 71 72 73 |
# File 'lib/uploader/helpers/field_tag.rb', line 70 def ( = {}) = @object.fileupload_params(method_name).merge() uploader.() end |
#exists? ⇒ Boolean
58 59 60 |
# File 'lib/uploader/helpers/field_tag.rb', line 58 def exists? values.map(&:persisted?).any? end |
#extension_whitelist ⇒ Object
87 88 89 |
# File 'lib/uploader/helpers/field_tag.rb', line 87 def extension_whitelist @extension_whitelist ||= extract_extension_whitelist end |
#id ⇒ Object
34 35 36 |
# File 'lib/uploader/helpers/field_tag.rb', line 34 def id @id ||= @template.dom_id(@object, [method_name, 'uploader'].join('_')) end |
#input_html ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/uploader/helpers/field_tag.rb', line 75 def input_html @input_html ||= { multiple: multiple?, class: 'uploader' }.merge() @input_html[:data] ||= {} @input_html[:data][:url] ||= (singular: !multiple?) @input_html[:accept] ||= extension_whitelist @input_html end |
#input_html_options ⇒ Object
83 84 85 |
# File 'lib/uploader/helpers/field_tag.rb', line 83 def @options.reject { |key, _value| RESERVED_OPTIONS_KEYS.include?(key.to_s) } end |
#klass ⇒ Object
66 67 68 |
# File 'lib/uploader/helpers/field_tag.rb', line 66 def klass @klass ||= @object.fileupload_klass(method_name) end |
#method_name ⇒ Object
38 39 40 |
# File 'lib/uploader/helpers/field_tag.rb', line 38 def method_name @options[:method_name] end |
#multiple? ⇒ Boolean
46 47 48 |
# File 'lib/uploader/helpers/field_tag.rb', line 46 def multiple? @object.fileupload_multiple?(method_name) end |
#object_name ⇒ Object
42 43 44 |
# File 'lib/uploader/helpers/field_tag.rb', line 42 def object_name @options[:object_name] end |
#render(locals = {}) ⇒ Object
:nodoc:
29 30 31 32 |
# File 'lib/uploader/helpers/field_tag.rb', line 29 def render(locals = {}) #:nodoc: locals = { field: self }.merge(locals) @template.render(partial: "uploader/#{@theme}/container", locals: locals) end |
#sortable? ⇒ Boolean
62 63 64 |
# File 'lib/uploader/helpers/field_tag.rb', line 62 def sortable? @options[:sortable] == true end |
#value ⇒ Object
50 51 52 |
# File 'lib/uploader/helpers/field_tag.rb', line 50 def value @value ||= @object.fileupload_asset(method_name) end |
#values ⇒ Object
54 55 56 |
# File 'lib/uploader/helpers/field_tag.rb', line 54 def values Array.wrap(value) end |