Class: Uploader::Helpers::FieldTag
- Inherits:
-
Object
- Object
- Uploader::Helpers::FieldTag
- Defined in:
- lib/uploader/helpers/field_tag.rb
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
- #klass ⇒ Object
- #method_name ⇒ Object
- #multiple? ⇒ Boolean
- #object_name ⇒ Object
- #sort_path(options = {}) ⇒ Object
-
#to_s(locals = {}) ⇒ Object
:nodoc:.
- #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.to_s
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/uploader/helpers/field_tag.rb', line 14 def initialize(object_name, method_name, template, = {}) #:nodoc: = { :object_name => object_name, :method_name => method_name }.merge() @template, @options = template, .dup @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.
4 5 6 |
# File 'lib/uploader/helpers/field_tag.rb', line 4 def object @object end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/uploader/helpers/field_tag.rb', line 4 def template @template end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
4 5 6 |
# File 'lib/uploader/helpers/field_tag.rb', line 4 def theme @theme end |
Instance Method Details
#attachments_path(options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/uploader/helpers/field_tag.rb', line 67 def ( = {}) = { :guid => @object.fileupload_guid, :assetable_type => @object.class.base_class.name.to_s, :klass => klass.to_s }.merge() [:assetable_id] = @object.id if @object.persisted? uploader.() end |
#exists? ⇒ Boolean
59 60 61 |
# File 'lib/uploader/helpers/field_tag.rb', line 59 def exists? values.map(&:persisted?).any? end |
#id ⇒ Object
31 32 33 |
# File 'lib/uploader/helpers/field_tag.rb', line 31 def id @id ||= @template.dom_id(@object, [method_name, 'uploader', @object.fileupload_guid].join('_')) end |
#input_html ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/uploader/helpers/field_tag.rb', line 91 def input_html @input_html ||= { :"data-url" => , :multiple => multiple?, :class => "uploader" }.merge(@options[:input_html] || {}) end |
#klass ⇒ Object
63 64 65 |
# File 'lib/uploader/helpers/field_tag.rb', line 63 def klass @klass ||= @object.class.fileupload_klass(method_name) end |
#method_name ⇒ Object
35 36 37 |
# File 'lib/uploader/helpers/field_tag.rb', line 35 def method_name @options[:method_name] end |
#multiple? ⇒ Boolean
43 44 45 |
# File 'lib/uploader/helpers/field_tag.rb', line 43 def multiple? @object.fileupload_multiple?(method_name) end |
#object_name ⇒ Object
39 40 41 |
# File 'lib/uploader/helpers/field_tag.rb', line 39 def object_name @options[:object_name] end |
#sort_path(options = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/uploader/helpers/field_tag.rb', line 79 def sort_path( = {}) = { :guid => @object.fileupload_guid, :assetable_type => @object.class.base_class.name.to_s, :klass => klass.to_s }.merge() [:assetable_id] = @object.id if @object.persisted? uploader.() end |
#to_s(locals = {}) ⇒ Object
:nodoc:
26 27 28 29 |
# File 'lib/uploader/helpers/field_tag.rb', line 26 def to_s(locals = {}) #:nodoc: locals = { :field => self }.merge(locals) @template.render :partial => "uploader/#{@theme}/container", :locals => locals end |
#value ⇒ Object
47 48 49 |
# File 'lib/uploader/helpers/field_tag.rb', line 47 def value @value ||= @object.fileupload_asset(method_name) end |
#values ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/uploader/helpers/field_tag.rb', line 51 def values if !value.nil? && value.first.respond_to?(:sort) Array.wrap(value).sort_by(&:sort) else Array.wrap(value) end end |