Module: Ksk::Asset

Extended by:
ActiveSupport::Concern
Defined in:
lib/actives/asset.rb

Instance Method Summary collapse

Instance Method Details

#allow_only_imagesObject



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

Returns:

  • (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_thumbsObject



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, meta|
    if cords_set?(style)
      resize_banner style, [send("#{style}_x"), send("#{style}_y"), send("#{style}_w"), send("#{style}_h")], meta.attachment.options[:styles][style][0]
      send("#{style}_x=", false)
    end
  end
  file.save
  file.instance.save
end

#cropping?Boolean

Returns:

  • (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, meta|
    if !needs_crop
      needs_crop = cords_set?(style)
    end
  end
  needs_crop
end

#has_preview?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


79
80
81
# File 'lib/actives/asset.rb', line 79

def is_image?
  IMGTYPE.include?(file.content_type)
end

#preview_fileObject



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_accessorsObject



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, meta|
    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 resize_banner(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.processor_options, file.queued_for_write[name])
  file.queued_for_write[name] = Paperclip.io_adapters.for(file.queued_for_write[name])
end

#set_last_positionObject



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_sObject



97
98
99
# File 'lib/actives/asset.rb', line 97

def to_bhf_s
  "ID: #{id} - Name: #{file_file_name}"
end