Module: Admin::FilePreviewHelper
- Included in:
- ResourcesHelper
- Defined in:
- app/helpers/admin/file_preview_helper.rb
Instance Method Summary collapse
- #get_type_of_attachment(attachment) ⇒ Object
- #link_to_detach_attribute(attribute) ⇒ Object
- #typus_file_preview(item, attribute, options = {}) ⇒ Object
- #typus_file_preview_for_dragonfly(attachment, options = {}) ⇒ Object
- #typus_file_preview_for_paperclip(attachment, options = {}) ⇒ Object
Instance Method Details
#get_type_of_attachment(attachment) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/helpers/admin/file_preview_helper.rb', line 4 def () if defined?(Paperclip) && .is_a?(Paperclip::Attachment) :paperclip elsif defined?(Dragonfly) && .is_a?(Dragonfly::ActiveModelExtensions::Attachment) :dragonfly end end |
#link_to_detach_attribute(attribute) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/admin/file_preview_helper.rb', line 12 def link_to_detach_attribute(attribute) validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map { |i| i.attributes }.flatten.map { |i| i.to_s } = @item.send(attribute) field = case () when :dragonfly then attribute when :paperclip then "#{attribute}_file_name" end if !validators.include?(field) && attribute_i18n = @item.class.human_attribute_name(attribute) = Typus::I18n.t("Remove") label_text = <<-HTML #{attribute_i18n} <small>#{link_to , { :action => 'update', :id => @item.id, :attribute => attribute }, :confirm => Typus::I18n.t("Are you sure?")}</small> HTML label_text.html_safe end end |
#typus_file_preview(item, attribute, options = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'app/helpers/admin/file_preview_helper.rb', line 33 def typus_file_preview(item, attribute, = {}) if ( = item.send(attribute)) adapter = () send("typus_file_preview_for_#{adapter}", , ) end end |
#typus_file_preview_for_dragonfly(attachment, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/admin/file_preview_helper.rb', line 40 def typus_file_preview_for_dragonfly(, = {}) if .mime_type =~ /^image\/.+/ render "admin/helpers/file_preview", :preview => .process(:thumb, Typus.image_preview_size).url, :thumb => .process(:thumb, Typus.image_thumb_size).url, :options => else link_to .name, .url end end |
#typus_file_preview_for_paperclip(attachment, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/admin/file_preview_helper.rb', line 51 def typus_file_preview_for_paperclip(, = {}) if .exists? styles = .styles.keys if styles.include?(Typus.file_preview) && styles.include?(Typus.file_thumbnail) render "admin/helpers/file_preview", :preview => .url(Typus.file_preview, false), :thumb => .url(Typus.file_thumbnail, false), :options => else link_to .original_filename, .url(:original, false) end end end |