Module: Ksk::Asset
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/actives/asset.rb
Instance Method Summary collapse
- #allow_only_images ⇒ Object
- #cords_set?(style) ⇒ Boolean
- #crop_thumbs ⇒ Object
- #cropping? ⇒ Boolean
- #has_preview? ⇒ Boolean
- #has_preview_image? ⇒ Boolean
- #is_image? ⇒ Boolean
- #preview_file ⇒ Object
- #resize_attr_accessors ⇒ Object
- #resize_banner(name, cords, resize) ⇒ Object
- #set_last_position ⇒ Object
- #to_bhf_s ⇒ Object
Instance Method Details
#allow_only_images ⇒ Object
73 74 75 76 77 |
# File 'lib/actives/asset.rb', line 73 def allow_only_images if !(file.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$}) return false end end |
#cords_set?(style) ⇒ Boolean
50 51 52 |
# File 'lib/actives/asset.rb', line 50 def cords_set?(style) !send("#{style}_x").blank? && !send("#{style}_y").blank? && !send("#{style}_w").blank? && !send("#{style}_h").blank? end |
#crop_thumbs ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/actives/asset.rb', line 54 def crop_thumbs file.styles.each_pair do |style, | if cords_set?(style) style, [send("#{style}_x"), send("#{style}_y"), send("#{style}_w"), send("#{style}_h")], ..[:styles][style][0] send("#{style}_x=", false) end end file.save file.instance.save end |
#cropping? ⇒ Boolean
40 41 42 43 44 45 46 47 48 |
# File 'lib/actives/asset.rb', line 40 def cropping? needs_crop = false file.styles.each_pair do |style, | if !needs_crop needs_crop = cords_set?(style) end end needs_crop end |
#has_preview? ⇒ Boolean
83 84 85 |
# File 'lib/actives/asset.rb', line 83 def has_preview? preview && (preview.assets.any? || !preview.name.blank?) end |
#has_preview_image? ⇒ Boolean
87 88 89 |
# File 'lib/actives/asset.rb', line 87 def has_preview_image? preview.assets.any? and preview.assets.first.file end |
#is_image? ⇒ Boolean
79 80 81 |
# File 'lib/actives/asset.rb', line 79 def is_image? IMGTYPE.include?(file.content_type) end |
#preview_file ⇒ Object
91 92 93 94 95 |
# File 'lib/actives/asset.rb', line 91 def preview_file if has_preview? preview.assets.first.file end end |
#resize_attr_accessors ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/actives/asset.rb', line 31 def resize_attr_accessors file.styles.each_pair do |style, | self.class.send(:attr_accessor, "#{style}_x") self.class.send(:attr_accessor, "#{style}_y") self.class.send(:attr_accessor, "#{style}_w") self.class.send(:attr_accessor, "#{style}_h") end end |
#resize_banner(name, cords, resize) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/actives/asset.rb', line 65 def (name, cords, resize) file.queued_for_write[name] = Paperclip.processor(:ksk_crop).make(file, cords, file) style = Paperclip::Style.new(name, [resize, :jpg], file) file.queued_for_write[name] = Paperclip.processor(:thumbnail).make(file.queued_for_write[name], style., file.queued_for_write[name]) file.queued_for_write[name] = Paperclip.io_adapters.for(file.queued_for_write[name]) end |
#set_last_position ⇒ Object
101 102 103 |
# File 'lib/actives/asset.rb', line 101 def set_last_position self.position = self.class.where(fileable_id: self.fileable_id).count+1 end |
#to_bhf_s ⇒ Object
97 98 99 |
# File 'lib/actives/asset.rb', line 97 def to_bhf_s "ID: #{id} - Name: #{file_file_name}" end |