paperclip-tinify 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/paperclip-tinify.rb +48 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 565bb6ebe534f0da8889c4e75dbc38e105f31548
4
+ data.tar.gz: ca160158d460eecb2af53c74f7570926b1f883f0
5
+ SHA512:
6
+ metadata.gz: 796452c2541c689297a21e04856343eee6915f78d6a7c8d1f8cd8237c05859894d490dbb554f2bfffb8137f68266838820ded193784264eaa05b68ffeacce095
7
+ data.tar.gz: 7924c4534b886b63d758098f05fd4e878eaf898c98ce1a4d7cc05ec96cb172e2cef170fd558a85b3fd089ca5a939372dada5cddcbab02510c386b635d97eba92
@@ -0,0 +1,48 @@
1
+ module Paperclip
2
+ require "tinify"
3
+
4
+ class Tinify < Processor
5
+ class << self
6
+ attr_accessor :tinify_key
7
+ end
8
+
9
+ def make
10
+ case content_type
11
+ when 'image/jpeg', 'image/png' then compress
12
+ else
13
+ @file
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def first_processor?
20
+ @first_processor ||= @file.is_a?(Paperclip::AbstractAdapter)
21
+ end
22
+
23
+ def content_type
24
+ first_processor? ? @file.content_type : Paperclip::ContentTypeDetector.new(@file.path).detect
25
+ end
26
+
27
+ def compress
28
+ current_extension = File.extname(@file.path)
29
+ basename = File.basename(@file.path, current_extension)
30
+
31
+ src = @file
32
+ dst = TempfileFactory.new.generate(basename)
33
+
34
+ if Tinify.tinify_key
35
+ Paperclip.log "tinifying..."
36
+
37
+ ::Tinify.key = Tinify.tinify_key
38
+ ::Tinify.from_file(File.expand_path(src.path)).to_file(File.expand_path(dst))
39
+
40
+ dst
41
+ else
42
+ Paperclip.log "tinify key was not defined, skipping..."
43
+
44
+ File.open(src.path)
45
+ end
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-tinify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thales Pereira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tinify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ description: JPEG and PNG compression for Paperclip gem
28
+ email: thalesfp@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/paperclip-tinify.rb
34
+ homepage: https://github.com/thalesfp/paperclip-tinify
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.5.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Compress Paperclip attachments using Tinyfy API
58
+ test_files: []