class Attachy::Viewer
Public Class Methods
new(method, object, options = {}, view = ActionController::Base.helpers)
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 7 def initialize(method, object, options = {}, view = ActionController::Base.helpers) @method = method @object = object @options = options @view = view end
Public Instance Methods
attachments()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 14 def attachments [criteria].flatten.compact end
content(html: {}) { |html, attachments| ... }
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 28 def content(html: {}) html = content_options.merge(html) return yield(html, attachments) if block_given? @view.content_tag :ul, nodes.join.html_safe, html end
content_options()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 36 def content_options { class: :attachy__content, data: { crop: metadata[:crop], height: transform[:height], multiple: metadata[:multiple], width: transform[:width] } } end
field(html: {}) { |html| ... }
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 53 def field(html: {}) html = field_options.merge(html) return yield(html) if block_given? @view.content_tag :div, content + file_button, html end
field_options()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 49 def field_options { class: :attachy } end
file_field(html: file_field_options)
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 83 def file_field(html: file_field_options) options = { html: html, tags: [ENV_TAG, TMP_TAG] } options[:folder] = metadata[:folder] if metadata[:folder] @view.cl_image_upload_tag @method, options end
file_field_options()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 73 def file_field_options options = { class: :attachy__fileupload } accept = MIME::Types.type_for([metadata[:accept]].flatten.map(&:to_s)) options[:accept] = accept.join(',') if accept.present? options[:multiple] = true if metadata[:multiple] options end
image(file = criteria, t: transform, html: htm)
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 95 def image(file = criteria, t: transform, html: htm) return if file.nil? url = file.url(t) html = html.reverse_merge(height: t[:height], width: t[:width]) html[:data] = file.transform(t) @view.image_tag url, html end
link(file = criteria, t: transform, tl: { crop: :none }, html: {}) { |html, attachments| ... }
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 109 def link(file = criteria, t: transform, tl: { crop: :none }, html: {}) html = link_options.merge(data: tl).merge(html) return yield(html, attachments) if block_given? @view.link_to image(file, t: t), file.url(tl), html end
link_options()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 105 def link_options { class: :attachy__link } end
node(file = criteria, tl: { crop: :none }, t: transform, html: {}) { |html, attachments| ... }
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 121 def node(file = criteria, tl: { crop: :none }, t: transform, html: {}) html = html.reverse_merge(node_options) return yield(html, attachments) if block_given? value = [link(file, t: t, tl: tl)] value << remove_button unless @options[:destroy] == false @view.content_tag :li, value.join.html_safe, html end
node_options()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 117 def node_options { class: :attachy__node } end
nodes()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 132 def nodes attachments.map { |file| node file } end
value()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 148 def value default? ? '[]' : attachments.to_json end
Private Instance Methods
criteria()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 154 def criteria @criteria ||= @object.send(@method) end
default?()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 158 def default? attachments.size == 1 && attachments.last.public_id == Attachy::File.default&.public_id end
htm(path = [])
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 162 def htm(path = []) @options.dig(*[path, :html].flatten) || {} end
metadata()
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 166 def metadata @metadata ||= @object.send("#{@method}_metadata") end
transform(path = [])
click to toggle source
# File lib/attachy/models/attachy/viewer.rb, line 170 def transform(path = []) @options.dig(*[path, :t].flatten) || {} end