Class: Uploader::Helpers::FieldTag
- Inherits:
-
Object
- Object
- Uploader::Helpers::FieldTag
- Defined in:
- lib/uploader/helpers/field_tag.rb
Constant Summary collapse
- RESERVED_OPTIONS_KEYS =
%(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
- #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
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/uploader/helpers/field_tag.rb', line 16 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.
6 7 8 |
# File 'lib/uploader/helpers/field_tag.rb', line 6 def object @object end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
6 7 8 |
# File 'lib/uploader/helpers/field_tag.rb', line 6 def template @template end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
6 7 8 |
# File 'lib/uploader/helpers/field_tag.rb', line 6 def theme @theme end |
Instance Method Details
#attachments_path(options = {}) ⇒ Object
68 69 70 71 |
# File 'lib/uploader/helpers/field_tag.rb', line 68 def ( = {}) = @object.fileupload_params(method_name).merge() uploader.() end |
#exists? ⇒ Boolean
56 57 58 |
# File 'lib/uploader/helpers/field_tag.rb', line 56 def exists? values.map(&:persisted?).any? end |
#id ⇒ Object
32 33 34 |
# File 'lib/uploader/helpers/field_tag.rb', line 32 def id @id ||= @template.dom_id(@object, [method_name, 'uploader'].join('_')) end |
#input_html ⇒ Object
73 74 75 76 77 78 |
# File 'lib/uploader/helpers/field_tag.rb', line 73 def input_html @input_html ||= { multiple: multiple?, class: 'uploader' }.merge() @input_html[:data] ||= {} @input_html[:data][:url] ||= @input_html end |
#input_html_options ⇒ Object
80 81 82 |
# File 'lib/uploader/helpers/field_tag.rb', line 80 def @options.select { |key, _value| !RESERVED_OPTIONS_KEYS.include?(key.to_s) } end |
#klass ⇒ Object
64 65 66 |
# File 'lib/uploader/helpers/field_tag.rb', line 64 def klass @klass ||= @object.fileupload_klass(method_name) end |
#method_name ⇒ Object
36 37 38 |
# File 'lib/uploader/helpers/field_tag.rb', line 36 def method_name @options[:method_name] end |
#multiple? ⇒ Boolean
44 45 46 |
# File 'lib/uploader/helpers/field_tag.rb', line 44 def multiple? @object.fileupload_multiple?(method_name) end |
#object_name ⇒ Object
40 41 42 |
# File 'lib/uploader/helpers/field_tag.rb', line 40 def object_name @options[:object_name] end |
#render(locals = {}) ⇒ Object
:nodoc:
27 28 29 30 |
# File 'lib/uploader/helpers/field_tag.rb', line 27 def render(locals = {}) #:nodoc: locals = { field: self }.merge(locals) @template.render(partial: "uploader/#{@theme}/container", locals: locals) end |
#sortable? ⇒ Boolean
60 61 62 |
# File 'lib/uploader/helpers/field_tag.rb', line 60 def sortable? @options[:sortable] == true end |
#value ⇒ Object
48 49 50 |
# File 'lib/uploader/helpers/field_tag.rb', line 48 def value @value ||= @object.fileupload_asset(method_name) end |
#values ⇒ Object
52 53 54 |
# File 'lib/uploader/helpers/field_tag.rb', line 52 def values Array.wrap(value) end |