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 |
# 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, = template, .dup @theme = (.delete(:theme) || "default") @value = .delete(:value) if .key?(:value) @object = .delete(:object) if .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
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/uploader/helpers/field_tag.rb', line 66 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
58 59 60 |
# File 'lib/uploader/helpers/field_tag.rb', line 58 def exists? values.map(&:persisted?).any? end |
#id ⇒ Object
30 31 32 |
# File 'lib/uploader/helpers/field_tag.rb', line 30 def id @id ||= @template.dom_id(@object, [method_name, 'uploader', @object.fileupload_guid].join('_')) end |
#input_html ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/uploader/helpers/field_tag.rb', line 90 def input_html @input_html ||= { :"data-url" => , :multiple => multiple?, :class => "uploader" }.merge([:input_html] || {}) end |
#klass ⇒ Object
62 63 64 |
# File 'lib/uploader/helpers/field_tag.rb', line 62 def klass @klass ||= @object.class.fileupload_klass(method_name) end |
#method_name ⇒ Object
34 35 36 |
# File 'lib/uploader/helpers/field_tag.rb', line 34 def method_name [:method_name] end |
#multiple? ⇒ Boolean
42 43 44 |
# File 'lib/uploader/helpers/field_tag.rb', line 42 def multiple? @object.fileupload_multiple?(method_name) end |
#object_name ⇒ Object
38 39 40 |
# File 'lib/uploader/helpers/field_tag.rb', line 38 def object_name [:object_name] end |
#sort_path(options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/uploader/helpers/field_tag.rb', line 78 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:
25 26 27 28 |
# File 'lib/uploader/helpers/field_tag.rb', line 25 def to_s(locals = {}) #:nodoc: locals = { :field => self }.merge(locals) @template.render :partial => "uploader/#{@theme}/container", :locals => locals end |
#value ⇒ Object
46 47 48 |
# File 'lib/uploader/helpers/field_tag.rb', line 46 def value @value ||= @object.fileupload_asset(method_name) end |
#values ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/uploader/helpers/field_tag.rb', line 50 def values if !value.nil? && value.respond_to?(:first) && value.first.respond_to?(:sort) Array.wrap(value).sort_by(&:sort) else Array.wrap(value) end end |