stamp-it 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eff7d68504afde375704f781535b160d509368ea
4
- data.tar.gz: 38e6862a8d172e905fd2ba3ee5e0de009e6d0eff
3
+ metadata.gz: bf0c623b27e29a5bcf7f49af5635f9b70aae3b45
4
+ data.tar.gz: 975872b2e4e177f20a38c76412ad9894b4bb8b5c
5
5
  SHA512:
6
- metadata.gz: eb062266757eb30144dcd525ee619808c45fcbc736908fa55fab0f746de9aba745a6f445dab8a1f4d42f5d44d7c473507a9898486403c01ec62f99e4809ad181
7
- data.tar.gz: 49b6b755b7c785065b12f74d54c7adf2dc8eef66e9fa926e806a893eeac82c32065fc8c5f4427be6b2b8649a7dd1e8b06331cf750e5b0e0d5c481fe1798590e6
6
+ metadata.gz: ca852614f426365d71ded246acb705fdd6e3d87155eb2b24ef1222d2960353ffed593bba67b227e1a721e61d19ad5c8c086ca642e5cda4cedbc98dfc8e6ce292
7
+ data.tar.gz: 0bb6b2c8327c1a6041cd7bb300092f57f2805c78cc820e987fcbb26027401a626b8e83c2e96e625ebefe8da7a428175056bbde664b8844cc19bdf672d828755a
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ spec/output/*.pdf
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile.lock CHANGED
@@ -1,85 +1,130 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stamp-it (0.0.1)
4
+ stamp-it (0.0.3)
5
5
  prawn
6
6
  rails
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionmailer (4.1.8)
12
- actionpack (= 4.1.8)
13
- actionview (= 4.1.8)
11
+ actionmailer (4.2.1)
12
+ actionpack (= 4.2.1)
13
+ actionview (= 4.2.1)
14
+ activejob (= 4.2.1)
14
15
  mail (~> 2.5, >= 2.5.4)
15
- actionpack (4.1.8)
16
- actionview (= 4.1.8)
17
- activesupport (= 4.1.8)
18
- rack (~> 1.5.2)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.1)
18
+ actionview (= 4.2.1)
19
+ activesupport (= 4.2.1)
20
+ rack (~> 1.6)
19
21
  rack-test (~> 0.6.2)
20
- actionview (4.1.8)
21
- activesupport (= 4.1.8)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
24
+ actionview (4.2.1)
25
+ activesupport (= 4.2.1)
22
26
  builder (~> 3.1)
23
27
  erubis (~> 2.7.0)
24
- activemodel (4.1.8)
25
- activesupport (= 4.1.8)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
30
+ activejob (4.2.1)
31
+ activesupport (= 4.2.1)
32
+ globalid (>= 0.3.0)
33
+ activemodel (4.2.1)
34
+ activesupport (= 4.2.1)
26
35
  builder (~> 3.1)
27
- activerecord (4.1.8)
28
- activemodel (= 4.1.8)
29
- activesupport (= 4.1.8)
30
- arel (~> 5.0.0)
31
- activesupport (4.1.8)
32
- i18n (~> 0.6, >= 0.6.9)
36
+ activerecord (4.2.1)
37
+ activemodel (= 4.2.1)
38
+ activesupport (= 4.2.1)
39
+ arel (~> 6.0)
40
+ activesupport (4.2.1)
41
+ i18n (~> 0.7)
33
42
  json (~> 1.7, >= 1.7.7)
34
43
  minitest (~> 5.1)
35
- thread_safe (~> 0.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
36
45
  tzinfo (~> 1.1)
37
- arel (5.0.1.20140414130214)
46
+ arel (6.0.0)
38
47
  builder (3.2.2)
48
+ coderay (1.1.0)
49
+ diff-lcs (1.2.5)
39
50
  erubis (2.7.0)
51
+ globalid (0.3.3)
52
+ activesupport (>= 4.1.0)
40
53
  hike (1.2.3)
41
- i18n (0.6.11)
42
- json (1.8.1)
54
+ i18n (0.7.0)
55
+ json (1.8.2)
56
+ loofah (2.0.1)
57
+ nokogiri (>= 1.5.9)
43
58
  mail (2.6.3)
44
59
  mime-types (>= 1.16, < 3)
60
+ method_source (0.8.2)
45
61
  mime-types (2.4.3)
46
- minitest (5.4.3)
47
- multi_json (1.10.1)
48
- pdf-core (0.4.0)
49
- prawn (1.3.0)
50
- pdf-core (~> 0.4.0)
62
+ mini_portile (0.6.2)
63
+ minitest (5.5.1)
64
+ multi_json (1.11.0)
65
+ nokogiri (1.6.6.2)
66
+ mini_portile (~> 0.6.0)
67
+ pdf-core (0.5.1)
68
+ prawn (2.0.1)
69
+ pdf-core (~> 0.5.1)
51
70
  ttfunk (~> 1.4.0)
52
- rack (1.5.2)
53
- rack-test (0.6.2)
71
+ pry (0.10.1)
72
+ coderay (~> 1.1.0)
73
+ method_source (~> 0.8.1)
74
+ slop (~> 3.4)
75
+ rack (1.6.0)
76
+ rack-test (0.6.3)
54
77
  rack (>= 1.0)
55
- rails (4.1.8)
56
- actionmailer (= 4.1.8)
57
- actionpack (= 4.1.8)
58
- actionview (= 4.1.8)
59
- activemodel (= 4.1.8)
60
- activerecord (= 4.1.8)
61
- activesupport (= 4.1.8)
78
+ rails (4.2.1)
79
+ actionmailer (= 4.2.1)
80
+ actionpack (= 4.2.1)
81
+ actionview (= 4.2.1)
82
+ activejob (= 4.2.1)
83
+ activemodel (= 4.2.1)
84
+ activerecord (= 4.2.1)
85
+ activesupport (= 4.2.1)
62
86
  bundler (>= 1.3.0, < 2.0)
63
- railties (= 4.1.8)
64
- sprockets-rails (~> 2.0)
65
- railties (4.1.8)
66
- actionpack (= 4.1.8)
67
- activesupport (= 4.1.8)
87
+ railties (= 4.2.1)
88
+ sprockets-rails
89
+ rails-deprecated_sanitizer (1.0.3)
90
+ activesupport (>= 4.2.0.alpha)
91
+ rails-dom-testing (1.0.6)
92
+ activesupport (>= 4.2.0.beta, < 5.0)
93
+ nokogiri (~> 1.6.0)
94
+ rails-deprecated_sanitizer (>= 1.0.1)
95
+ rails-html-sanitizer (1.0.2)
96
+ loofah (~> 2.0)
97
+ railties (4.2.1)
98
+ actionpack (= 4.2.1)
99
+ activesupport (= 4.2.1)
68
100
  rake (>= 0.8.7)
69
101
  thor (>= 0.18.1, < 2.0)
70
102
  rake (10.4.1)
103
+ rspec (3.2.0)
104
+ rspec-core (~> 3.2.0)
105
+ rspec-expectations (~> 3.2.0)
106
+ rspec-mocks (~> 3.2.0)
107
+ rspec-core (3.2.2)
108
+ rspec-support (~> 3.2.0)
109
+ rspec-expectations (3.2.0)
110
+ diff-lcs (>= 1.2.0, < 2.0)
111
+ rspec-support (~> 3.2.0)
112
+ rspec-mocks (3.2.1)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.2.0)
115
+ rspec-support (3.2.2)
116
+ slop (3.6.0)
71
117
  sprockets (2.12.3)
72
118
  hike (~> 1.2)
73
119
  multi_json (~> 1.0)
74
120
  rack (~> 1.0)
75
121
  tilt (~> 1.1, != 1.3.0)
76
- sprockets-rails (2.2.2)
122
+ sprockets-rails (2.2.4)
77
123
  actionpack (>= 3.0)
78
124
  activesupport (>= 3.0)
79
125
  sprockets (>= 2.8, < 4.0)
80
- sqlite3 (1.3.10)
81
126
  thor (0.19.1)
82
- thread_safe (0.3.4)
127
+ thread_safe (0.3.5)
83
128
  tilt (1.4.1)
84
129
  ttfunk (1.4.0)
85
130
  tzinfo (1.2.2)
@@ -90,6 +135,7 @@ PLATFORMS
90
135
 
91
136
  DEPENDENCIES
92
137
  bundler (~> 1.3)
138
+ pry
93
139
  rake
94
- sqlite3
140
+ rspec
95
141
  stamp-it!
@@ -2,14 +2,19 @@ class StampIt
2
2
  class Background
3
3
  class << self
4
4
 
5
- def add(original_path, watermark_path, output_path)
5
+ def add(original_path, watermark_path, output_path, password = nil)
6
6
  unless files_exist?([original_path, watermark_path])
7
7
  return 'Original or Watermark files are missing'
8
8
  end
9
9
 
10
10
  pdftk_cmd = StampIt.new.pdftk_cmd
11
11
 
12
- %x(#{pdftk_cmd} #{original_path} background #{watermark_path} output #{output_path})
12
+ if password
13
+ %x(#{pdftk_cmd} #{original_path} background #{watermark_path} output #{output_path} owner_pw #{password})
14
+ else
15
+ %x(#{pdftk_cmd} #{original_path} background #{watermark_path} output #{output_path})
16
+ end
17
+
13
18
  $?.success?
14
19
  end
15
20
 
@@ -1,3 +1,3 @@
1
1
  class StampIt
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -7,11 +7,9 @@ class StampIt
7
7
  def create(file_path, message, config = {})
8
8
  begin
9
9
  Prawn::Document.generate(file_path) do
10
- rotate(52, origin: [0,0]) do
11
- transparent(0.5) do
12
- fill_color "FF000"
13
- draw_text message, size: 24, at: [0,0]
14
- end
10
+ transparent(0.5) do
11
+ fill_color "FF000"
12
+ draw_text message, size: 16, at: [bounds.left, bounds.top]
15
13
  end
16
14
  end
17
15
 
@@ -0,0 +1,69 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 1
16
+ /Kids [5 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 85
21
+ >>
22
+ stream
23
+ q
24
+
25
+ BT
26
+ 36.0 747.384 Td
27
+ /F1.0 12 Tf
28
+ [<48656c6c6f2077> 10 <6f72> -15 <6c6421>] TJ
29
+ ET
30
+
31
+ Q
32
+
33
+ endstream
34
+ endobj
35
+ 5 0 obj
36
+ << /Type /Page
37
+ /Parent 3 0 R
38
+ /MediaBox [0 0 612.0 792.0]
39
+ /Contents 4 0 R
40
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
41
+ /Font << /F1.0 6 0 R
42
+ >>
43
+ >>
44
+ >>
45
+ endobj
46
+ 6 0 obj
47
+ << /Type /Font
48
+ /Subtype /Type1
49
+ /BaseFont /Helvetica
50
+ /Encoding /WinAnsiEncoding
51
+ >>
52
+ endobj
53
+ xref
54
+ 0 7
55
+ 0000000000 65535 f
56
+ 0000000015 00000 n
57
+ 0000000109 00000 n
58
+ 0000000158 00000 n
59
+ 0000000215 00000 n
60
+ 0000000350 00000 n
61
+ 0000000528 00000 n
62
+ trailer
63
+ << /Size 7
64
+ /Root 2 0 R
65
+ /Info 1 0 R
66
+ >>
67
+ startxref
68
+ 625
69
+ %%EOF
@@ -0,0 +1,89 @@
1
+ %PDF-1.4
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 1
16
+ /Kids [5 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 261
21
+ >>
22
+ stream
23
+ q
24
+ q
25
+ 1.00000 0.00000 0.00000 1.00000 42.20457 -14.53220 cm
26
+ q
27
+ 0.61566 0.78801 -0.78801 0.61566 0.00000 0.00000 cm
28
+ q
29
+ /Tr1 gs
30
+ /DeviceRGB cs
31
+ 1.000 0.000 0.000 scn
32
+
33
+ BT
34
+ 36.0 36.0 Td
35
+ /F1.0 24 Tf
36
+ [<4578616d706c652077> 15 <61746572> -25 <6d6172> -15 <6b>] TJ
37
+ ET
38
+
39
+ Q
40
+ Q
41
+ Q
42
+ Q
43
+
44
+ endstream
45
+ endobj
46
+ 5 0 obj
47
+ << /Type /Page
48
+ /Parent 3 0 R
49
+ /MediaBox [0 0 612.0 792.0]
50
+ /Contents 4 0 R
51
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
52
+ /ExtGState << /Tr1 6 0 R
53
+ >>
54
+ /Font << /F1.0 7 0 R
55
+ >>
56
+ >>
57
+ >>
58
+ endobj
59
+ 6 0 obj
60
+ << /Type /ExtGState
61
+ /CA 0.5
62
+ /ca 0.5
63
+ >>
64
+ endobj
65
+ 7 0 obj
66
+ << /Type /Font
67
+ /Subtype /Type1
68
+ /BaseFont /Helvetica
69
+ /Encoding /WinAnsiEncoding
70
+ >>
71
+ endobj
72
+ xref
73
+ 0 8
74
+ 0000000000 65535 f
75
+ 0000000015 00000 n
76
+ 0000000109 00000 n
77
+ 0000000158 00000 n
78
+ 0000000215 00000 n
79
+ 0000000527 00000 n
80
+ 0000000733 00000 n
81
+ 0000000787 00000 n
82
+ trailer
83
+ << /Size 8
84
+ /Root 2 0 R
85
+ /Info 1 0 R
86
+ >>
87
+ startxref
88
+ 884
89
+ %%EOF
@@ -0,0 +1,30 @@
1
+ describe StampIt::Background do
2
+ describe '#add' do
3
+ context 'when everything is good' do
4
+ let(:dirname) { File.dirname(__FILE__) }
5
+ let(:original_file) { "#{dirname}/assets/hello.pdf" }
6
+ let(:watermark_file) { "#{dirname}/assets/watermark.pdf" }
7
+ let(:output_file) { "#{dirname}/output/final.pdf" }
8
+
9
+ before(:each) do
10
+ File.delete(output_file) if File.exist? output_file
11
+ end
12
+
13
+ it 'returns true after the pdftk command is executed' do
14
+ expect(StampIt::Background.add(original_file, watermark_file, output_file)).to eql true
15
+ end
16
+
17
+ it 'creates the watermarked final file' do
18
+ expect(File.exist?(output_file)).to be_falsy
19
+ StampIt::Background.add(original_file, watermark_file, output_file)
20
+ expect(File.exist?(output_file)).to be_truthy
21
+ end
22
+ end
23
+
24
+ context 'when a file is missing' do
25
+ it 'returns a message if files do not exist' do
26
+ expect(StampIt::Background.add('/not/exist.pdf', '/neither/exist.pdf', '/path/to/file')).to eql 'Original or Watermark files are missing'
27
+ end
28
+ end
29
+ end
30
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ require 'pry'
2
+ require_relative '../lib/stamp_it'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ describe StampIt::Watermark do
2
+ describe '#create' do
3
+ let(:file_path) { "#{File.dirname(__FILE__)}/output/watermark.pdf" }
4
+
5
+ before(:each) do
6
+ File.delete(file_path) if File.exist? file_path
7
+ end
8
+
9
+ it 'returns the file path when everything goes well' do
10
+ expect(StampIt::Watermark.create(file_path, 'Watermark example')).to eql file_path
11
+ end
12
+
13
+ it 'creates a watermkark pdf file' do
14
+ expect(File.exist?(file_path)).to be_falsy
15
+ StampIt::Watermark.create(file_path, 'Watermark example')
16
+ expect(File.exist?(file_path)).to be_truthy
17
+ end
18
+ end
19
+ end
data/stamp-it.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'prawn'
23
23
  spec.add_development_dependency 'bundler', '~> 1.3'
24
24
  spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'pry'
25
27
 
26
28
  spec.description = 'Add watermarks to existing PDF files, the easy way.'
27
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stamp-it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Figarola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,12 +66,42 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: Add watermarks to existing PDF files, the easy way.
70
98
  email: eduardofigarola@gmail.com
71
99
  executables: []
72
100
  extensions: []
73
101
  extra_rdoc_files: []
74
102
  files:
103
+ - ".gitignore"
104
+ - ".rspec"
75
105
  - Gemfile
76
106
  - Gemfile.lock
77
107
  - LICENSE
@@ -80,6 +110,12 @@ files:
80
110
  - lib/stamp_it/background.rb
81
111
  - lib/stamp_it/version.rb
82
112
  - lib/stamp_it/watermark.rb
113
+ - spec/assets/hello.pdf
114
+ - spec/assets/watermark.pdf
115
+ - spec/background_spec.rb
116
+ - spec/output/.gitkeep
117
+ - spec/spec_helper.rb
118
+ - spec/watermark_spec.rb
83
119
  - stamp-it.gemspec
84
120
  homepage: https://github.com/efigarolam/stamp-it
85
121
  licenses:
@@ -105,4 +141,10 @@ rubygems_version: 2.2.2
105
141
  signing_key:
106
142
  specification_version: 4
107
143
  summary: Add watermarks to existing PDF files
108
- test_files: []
144
+ test_files:
145
+ - spec/assets/hello.pdf
146
+ - spec/assets/watermark.pdf
147
+ - spec/background_spec.rb
148
+ - spec/output/.gitkeep
149
+ - spec/spec_helper.rb
150
+ - spec/watermark_spec.rb