paperclip-phantom_svg 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9efdd038a6daecb6203d76e224b785829405b4bb
4
- data.tar.gz: 2df4de80642c5d9d2f3c2ffabe7d3539d69caf2f
3
+ metadata.gz: 7e1843db2fa77ceef0ba71b38627b03f7a902aa6
4
+ data.tar.gz: a30ce72166aeb26cff5a7f2d352e98310097fa52
5
5
  SHA512:
6
- metadata.gz: 664b0ad911a3610819d70c82269cef16a53053a674e449ebd90d7bbbbce82646964677c960f8d012ff9bcba2eb7cc8ec45463f62a7d59ebb6e599275c7986478
7
- data.tar.gz: 5dce0b4bebf5c8bfc912220939095fdfef986d4d8d1631ac654ba72748c41817170bfe1861ac34ee3d876c8513de42077190159ee25bca2cc07f2da15537da12
6
+ metadata.gz: 5316bd6167e7fa9272b124576ec870edfc355ac5feac3259d963b5d7386bc9dcad2f1d6d0f61a78eaea5263f26316747522b4b00c3d66b4fe93f4a0886b91359
7
+ data.tar.gz: e9df85e9760f755de359d24fca6bfcc3d9443595a2c0b96fddb9b131f815f5f9aeb937de5b38d2453f0c767585c6c86aa5dee3d7f87f79b69c064dd66be4eb30
@@ -7,43 +7,42 @@ module Paperclip
7
7
  attr_accessor :format, :height, :width, :dst
8
8
  def initialize(file, options = {}, attachment = nil)
9
9
  super
10
- @src = file
11
- @options = options
12
- @format = options[:format] || :svg
13
- @height = options[:height] || 64
14
- @width = options[:width] || 64
15
- @attachment = attachment
10
+ @format = options.fetch(:format, :svg)
11
+ @height = options.fetch(:height, 64)
12
+ @width = options.fetch(:width, 64)
13
+
16
14
  @base_name = File.basename(@file.path, '.*')
17
- @ouput_name = options[:output_name] || @base_name
15
+ @ouput_name = options.fetch(:output_name, @base_name)
18
16
  @svg = Phantom::SVG::Base.new(@file.path)
19
17
  end
20
18
 
21
19
  def make
22
- Paperclip.log "[PhantomSVG] Making #{@output_name}" if @whiny
23
- case @format
24
- when :svg
25
- return _create_svg
26
- when :png
27
- return _create_png
20
+ case @format.to_sym
21
+ when :svg then _create_svg
22
+ when :png then _create_png
23
+ else
24
+ raise 'Format not supported'
28
25
  end
29
26
  end
30
27
 
31
28
  private
32
29
 
33
30
  def _create_svg
34
- @dst = Tempfile.new([@output_name, '.svg'])
35
- Paperclip.log "[PhantomSVG] Creating SVG #{@output_name}" if @whiny
36
- @svg.save_svg(dst.path)
37
- @dst
31
+ @dst = Tempfile.new([@output_name, '.svg']).tap do |file|
32
+ Paperclip.log "[PhantomSVG] Creating SVG #{@output_name}" if @whiny
33
+ @svg.height = @height if @height
34
+ @svg.width = @width if @width
35
+ @svg.save_svg(file.path)
36
+ end
38
37
  end
39
38
 
40
39
  def _create_png
41
- @dst = Tempfile.new([@output_name, '.png'])
42
- Paperclip.log "[PhantomSVG] Creating SVG #{@output_name} @ #{@height}x#{@width}" if @whiny
43
- @svg.height = @height if @height
44
- @svg.width = @width if @width
45
- @svg.save_apng(@dst.path)
46
- @dst
40
+ @dst = Tempfile.new([@output_name, '.png']).tap do |file|
41
+ Paperclip.log "[PhantomSVG] Creating SVG #{@output_name} @ #{@height}x#{@width}" if @whiny
42
+ @svg.height = @height if @height
43
+ @svg.width = @width if @width
44
+ @svg.save_apng(file.path)
45
+ end
47
46
  end
48
47
  end
49
48
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = 'paperclip-phantom_svg'
4
- s.version = '0.0.1'
4
+ s.version = '0.0.2'
5
5
  s.license = 'LGPL-3.0'
6
6
  s.summary = 'SVG and Raster (primarily PNG) conerters for Paperclip' \
7
7
  ' that don\'t suck so much.'
@@ -30,7 +30,7 @@ describe Paperclip::PhantomProcessor do
30
30
  processor = Paperclip::PhantomProcessor.new(svg_source, test_options_svg)
31
31
  expect(processor.make).to be_an_instance_of(Paperclip::Tempfile)
32
32
  expect(File).to exist(processor.dst.path)
33
- end
33
+ end
34
34
  end
35
35
 
36
36
  describe '.make({format: :png, height: 128, width: 128})' do
@@ -38,7 +38,7 @@ describe Paperclip::PhantomProcessor do
38
38
  processor = Paperclip::PhantomProcessor.new(svg_source, test_options_png)
39
39
  expect(processor.make).to be_an_instance_of(Paperclip::Tempfile)
40
40
  expect(File).to exist(processor.dst.path)
41
- end
41
+ end
42
42
  end
43
43
 
44
44
  describe '.make({format: :png, height: 64})' do
@@ -46,7 +46,7 @@ describe Paperclip::PhantomProcessor do
46
46
  processor = Paperclip::PhantomProcessor.new(svg_source, test_options_png_h)
47
47
  expect(processor.make).to be_an_instance_of(Paperclip::Tempfile)
48
48
  expect(File).to exist(processor.dst.path)
49
- end
49
+ end
50
50
  end
51
51
  end
52
52
 
@@ -56,7 +56,7 @@ describe Paperclip::PhantomProcessor do
56
56
  processor = Paperclip::PhantomProcessor.new(png_source, test_options_svg)
57
57
  expect(processor.make).to be_an_instance_of(Paperclip::Tempfile)
58
58
  expect(File).to exist(processor.dst.path)
59
- end
59
+ end
60
60
  end
61
61
 
62
62
  describe '.make({format: :png, height: 128, width: 128})' do
@@ -64,7 +64,7 @@ describe Paperclip::PhantomProcessor do
64
64
  processor = Paperclip::PhantomProcessor.new(png_source, test_options_png)
65
65
  expect(processor.make).to be_an_instance_of(Paperclip::Tempfile)
66
66
  expect(File).to exist(processor.dst.path)
67
- end
67
+ end
68
68
  end
69
69
 
70
70
  describe '.make({format: :png, height: 64})' do
@@ -72,7 +72,7 @@ describe Paperclip::PhantomProcessor do
72
72
  processor = Paperclip::PhantomProcessor.new(png_source, test_options_png_h)
73
73
  expect(processor.make).to be_an_instance_of(Paperclip::Tempfile)
74
74
  expect(File).to exist(processor.dst.path)
75
- end
75
+ end
76
76
  end
77
77
  end
78
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-phantom_svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei Kagetsuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paperclip