paperclip-tinify 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/paperclip-tinify.rb +16 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35faae5ee027d6b07f0179c7c1a804c577d7c9ac
|
4
|
+
data.tar.gz: 53be166370e6e3a0727367b91fa80e7c1ead64f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f933741373de1a4a57eb8261a792675f201f8e1901449443c5e8c7cafb47028e2e7c6e3f2489d8101b0c16ca65a3497888b6979cfeb44c5206d861956a43e449
|
7
|
+
data.tar.gz: 2c3188239076d8732b6d569505757cf06bdffdd0bde1adcca77d1fc7f857748b089f216c72b98a43308497fa379e6c5f877d7118acbd9acc7a836741a00fd645
|
data/lib/paperclip-tinify.rb
CHANGED
@@ -3,7 +3,7 @@ module Paperclip
|
|
3
3
|
|
4
4
|
class Tinify < Processor
|
5
5
|
class << self
|
6
|
-
attr_accessor :tinify_key
|
6
|
+
attr_accessor :tinify_key, :environments
|
7
7
|
end
|
8
8
|
|
9
9
|
def make
|
@@ -16,6 +16,10 @@ module Paperclip
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
+
def environments
|
20
|
+
Tinify.environments || [:production]
|
21
|
+
end
|
22
|
+
|
19
23
|
def first_processor?
|
20
24
|
@first_processor ||= @file.is_a?(Paperclip::AbstractAdapter)
|
21
25
|
end
|
@@ -25,24 +29,24 @@ module Paperclip
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def compress
|
28
|
-
|
29
|
-
basename = File.basename(@file.path, current_extension)
|
32
|
+
src_path = File.expand_path(@file.path)
|
30
33
|
|
31
|
-
|
32
|
-
|
34
|
+
unless environments.include? RailsEnvironment.get.to_sym
|
35
|
+
Paperclip.log "tinify ignores this environment, skipping..."
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
return File.open(src_path)
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
if api_key = Tinify.tinify_key
|
41
|
+
Paperclip.log "tinifying #{src_path}"
|
39
42
|
|
40
|
-
|
43
|
+
::Tinify.key = api_key
|
44
|
+
::Tinify.from_file(src_path).to_file(src_path)
|
41
45
|
else
|
42
46
|
Paperclip.log "tinify key was not defined, skipping..."
|
43
|
-
|
44
|
-
File.open(src.path)
|
45
47
|
end
|
48
|
+
|
49
|
+
File.open(src_path)
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|