paperclip-ghostscript 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01355a680e75d0c53f45303ea98e42a2d2ba49b2
4
+ data.tar.gz: 59d734772369f2ab6fae41ecd0feea5734ee3da4
5
+ SHA512:
6
+ metadata.gz: 2ccb1512eb0ef96e03653c380c434083ef8aece601a169119e6366afa4b23009399f3f811f5f6f97e460d0dcb65c01a45c18849f6c194154fa95e16a21b46396
7
+ data.tar.gz: b1d07dd919f34362a56b6003273d808c08c14dbeb466eb3548e533c4b62db4cfb28afafe28adca55c812758cb83290a9813cd1d5b12d8f5af387ec54961852e7
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paperclip-ghostscript.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Adam Cuppy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Paperclip::Ghostscript
2
+
3
+ Adding support to process attachments with Ghostscript
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'paperclip-ghostscript'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install paperclip-ghostscript
18
+
19
+ ## Usage
20
+
21
+ Coming soon...
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/paperclip-ghostscript/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,67 @@
1
+ require "paperclip"
2
+ require "tempfile"
3
+
4
+ module Paperclip
5
+ class Ghostscript < Processor
6
+
7
+ VERSION = "0.1.0"
8
+ COMMAND = "gs"
9
+
10
+ attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :source_file_options
11
+
12
+ def initialize file, options = {}, attachment = nil
13
+ super
14
+ @file = file
15
+ @format = options[:format]
16
+
17
+ @current_format = File.extname(@file.path)
18
+ @basename = File.basename(@file.path, @current_format)
19
+ end
20
+
21
+ def make
22
+ handle_make { process! }
23
+ destination_file
24
+ end
25
+
26
+ private
27
+
28
+ def basename
29
+ @basename or raise "Basename is not defined"
30
+ end
31
+
32
+ def destination_file
33
+ @destination_file ||= Tempfile.new([basename, destination_format])
34
+ end
35
+
36
+ def destination_format
37
+ self.format ? ".#{self.format}" : ''
38
+ end
39
+
40
+ def source_path
41
+ File.expand_path(file.path)
42
+ end
43
+
44
+ def destination_path
45
+ File.expand_path(destination_file.path)
46
+ end
47
+
48
+ def parameters
49
+ @parameters ||= [
50
+ "-dNOPAUSE -dBATCH -sDEVICE=jpeg -r144 -dUseCIEColor -dFirstPage=1 -dLastPage=1",
51
+ "-sOutputFile=:dest",
52
+ ":source"
53
+ ].flatten.compact.join(" ").strip.squeeze(" ")
54
+ end
55
+
56
+ def process!
57
+ Paperclip.run(COMMAND, parameters, source: source_path, dest: destination_path)
58
+ end
59
+
60
+ def handle_make(&block)
61
+ destination_file.binmode
62
+ block.call
63
+ rescue => e
64
+ raise "There was an error processing the thumbnail for #{@basename}: #{e.message}"
65
+ end
66
+ end
67
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paperclip/ghostscript'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "paperclip-ghostscript"
8
+ spec.version = Paperclip::Ghostscript::VERSION
9
+ spec.authors = ["Adam Cuppy"]
10
+ spec.email = ["adam@codingzeal.com"]
11
+ spec.summary = %q{Paperclip processor for the Ghostscript library}
12
+ spec.description = %q{Paperclip processor for the Ghostscript library}
13
+ spec.homepage = "https://github.com/CodingZeal/paperclip-ghostscript"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "paperclip"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry-debugger"
26
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "tempfile"
3
+
4
+ module Paperclip
5
+ describe Ghostscript do
6
+ let(:file) { support_file("attachable.jpg") }
7
+ let(:options) { Hash.new }
8
+ let(:attachment) { nil }
9
+
10
+ subject { Ghostscript.new(file, options, attachment) }
11
+
12
+ describe "#make" do
13
+ let(:command) { "gs" }
14
+ let(:source_path) { file.path }
15
+ let(:destination_path) { support_file_path("output.jpg") }
16
+ let(:destination_file) { support_file("output.jpg") }
17
+ let(:parameters) { "-dNOPAUSE -dBATCH -sDEVICE=jpeg -r144 -dUseCIEColor -dFirstPage=1 -dLastPage=1 -sOutputFile=:dest :source" }
18
+ let(:run_options) {
19
+ {
20
+ source: source_path,
21
+ dest: destination_path
22
+ }
23
+ }
24
+
25
+ before do
26
+ allow(Tempfile).to receive(:new).and_return(destination_file)
27
+ end
28
+
29
+ it "runs a Paperclip processor with all options" do
30
+ expect(Paperclip).to receive(:run).with(command, parameters, run_options)
31
+ expect(subject.make).to eq destination_file
32
+ end
33
+
34
+ context "when file is undefined" do
35
+ let(:file) { nil }
36
+ it { expect { subject.make }.to raise_error }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ require "rspec"
2
+ require "pry"
3
+
4
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
5
+ Dir[File.join(PROJECT_ROOT, 'spec/support/**/*.rb')].each { |file| require(file) }
6
+
7
+ require File.join(PROJECT_ROOT, "lib/paperclip/ghostscript")
8
+
9
+ RSpec.configure do |config|
10
+ config.include SupportHelpers
11
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ module SupportHelpers
2
+ def support_file_path(path)
3
+ File.expand_path("../../#{path}", __FILE__)
4
+ end
5
+
6
+ def support_file(path, method = "r")
7
+ File.open(support_file_path(path), method)
8
+ end
9
+ end
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-ghostscript
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cuppy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paperclip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Paperclip processor for the Ghostscript library
84
+ email:
85
+ - adam@codingzeal.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/paperclip/ghostscript.rb
96
+ - lib/paperclip/ghostscript/version.rb
97
+ - paperclip-ghostscript.gemspec
98
+ - spec/paperclip/ghostscript_spec.rb
99
+ - spec/spec_helper.rb
100
+ - spec/support/attachable.jpg
101
+ - spec/support/helpers/support.rb
102
+ - spec/support/output.jpg
103
+ - spec/support/tempfile.jpg
104
+ homepage: https://github.com/CodingZeal/paperclip-ghostscript
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Paperclip processor for the Ghostscript library
128
+ test_files:
129
+ - spec/paperclip/ghostscript_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/support/attachable.jpg
132
+ - spec/support/helpers/support.rb
133
+ - spec/support/output.jpg
134
+ - spec/support/tempfile.jpg
135
+ has_rdoc: