phantompdf 1.1.1 → 1.2.0

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: ae86097f0600f67b8b4dcce04e387310a0616080
4
- data.tar.gz: ffaf226240d70a72325ed280f3c9175eca110cbf
3
+ metadata.gz: 38258c9e01c5fcd60729363baafab69f2789eefc
4
+ data.tar.gz: 7e8057ee830c08e5fb193dae4041d0053765b31a
5
5
  SHA512:
6
- metadata.gz: a84c1aff47a454b516861c7eafd346543ff09d11e0bd33b1d9fd088efba218dbc0d4b9736aff92dd50938689d72d9b82616389ca5eea1a36fb8f59b29dc3cda6
7
- data.tar.gz: 824fc062d2c2e429192f5ff69679a1cf5ac6e38f25f20aa0f1cf7e3b92417e3dd93ba1fe7bc0695e4dc17995d3f77bee7ab9f547ce38978d9aed2b132c7cd293
6
+ metadata.gz: c8e32f3283c0f663c11ef1391020304435c653c77c01ccd4942e5631cc20615767998de92f97438a8a2b2d02cf3daef607f98f336d64a67dab1daa99ad6a8c4d
7
+ data.tar.gz: 4a1bc43c970df6de138dbaa521c29e3b53b3f2a753d1696721fb1f7d560c32be7e8fb27e024bd523c54029b96ded18225d99753bc6f2ed3c2b9425c026b342f9
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  # using PhantomJS github repo
7
- gem 'phantomjs', :github => 'colszowka/phantomjs-gem'
7
+ gem 'phantomjs', '>= 1.8.0'
@@ -1,13 +1,7 @@
1
- GIT
2
- remote: git://github.com/colszowka/phantomjs-gem.git
3
- revision: f8a30905c28dac99490efaa608f1af59618616cb
4
- specs:
5
- phantomjs (1.9.2.0)
6
-
7
1
  PATH
8
2
  remote: .
9
3
  specs:
10
- phantompdf (1.1.0)
4
+ phantompdf (1.1.1)
11
5
  json
12
6
  phantomjs
13
7
  rack
@@ -17,20 +11,21 @@ GEM
17
11
  specs:
18
12
  Ascii85 (1.0.2)
19
13
  afm (0.2.0)
20
- byebug (2.3.0)
14
+ byebug (2.3.1)
21
15
  columnize (~> 0.3.6)
22
16
  debugger-linecache (~> 1.2.0)
23
17
  columnize (0.3.6)
24
18
  debugger-linecache (1.2.0)
25
- diff-lcs (1.2.4)
19
+ diff-lcs (1.2.5)
26
20
  hashery (2.1.1)
27
- json (1.8.0)
21
+ json (1.8.1)
28
22
  pdf-reader (1.3.3)
29
23
  Ascii85 (~> 1.0.0)
30
24
  afm (~> 0.2.0)
31
25
  hashery (~> 2.0)
32
26
  ruby-rc4
33
27
  ttfunk
28
+ phantomjs (1.9.2.0)
34
29
  rack (1.5.2)
35
30
  rack-test (0.6.2)
36
31
  rack (>= 1.0)
@@ -38,10 +33,10 @@ GEM
38
33
  rspec-core (~> 2.14.0)
39
34
  rspec-expectations (~> 2.14.0)
40
35
  rspec-mocks (~> 2.14.0)
41
- rspec-core (2.14.5)
42
- rspec-expectations (2.14.3)
36
+ rspec-core (2.14.7)
37
+ rspec-expectations (2.14.4)
43
38
  diff-lcs (>= 1.1.3, < 2.0)
44
- rspec-mocks (2.14.3)
39
+ rspec-mocks (2.14.4)
45
40
  ruby-rc4 (0.1.5)
46
41
  ttfunk (1.0.3)
47
42
 
@@ -51,7 +46,7 @@ PLATFORMS
51
46
  DEPENDENCIES
52
47
  byebug
53
48
  pdf-reader
54
- phantomjs!
49
+ phantomjs (>= 1.8.0)
55
50
  phantompdf!
56
51
  rack-test
57
52
  rspec
@@ -63,14 +63,14 @@ module PhantomPDF
63
63
  format, header, footer = options[:format], options[:header], options[:footer]
64
64
  zoom, margin, orientation = options[:zoom], options[:margin], options[:orientation]
65
65
  rendering_timeout, timeout = options[:rendering_timeout], options[:timeout]
66
- cookie_file = dump_cookies(options[:cookies])
66
+ cookies = dump_cookies(options[:cookies])
67
67
 
68
68
  [Assets.javascripts('rasterize'),
69
- @input.to_s,
69
+ @input,
70
70
  @output,
71
71
  format, dump_header(header), dump_footer(footer),
72
72
  margin, orientation, zoom,
73
- cookie_file,
73
+ cookies,
74
74
  rendering_timeout, timeout].map(&:to_s)
75
75
  end
76
76
 
@@ -91,14 +91,7 @@ module PhantomPDF
91
91
  end
92
92
 
93
93
  def dump_cookies(cookies)
94
- cookie_host = @input.url? ? URI::parse(@input.to_s).host : '/'
95
-
96
- cookie_json = cookies.inject([]) {|ck, (k, v)| ck.push({:name => k, :value => v, :domain => cookie_host}); ck}.to_json
97
- return nil if cookie_json.empty?
98
-
99
- cookie_file = Tempfile.new('temp_cookie_file')
100
- cookie_file.write(cookie_json)
101
- cookie_file.path
94
+ JSON.dump(cookies)
102
95
  end
103
96
  end
104
97
  end
@@ -1,3 +1,3 @@
1
1
  module PhantomPDF
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -2,6 +2,7 @@ var page = require('webpage').create(),
2
2
  fs = require('fs'),
3
3
  system = require('system'),
4
4
  system_args_len = system.args.length,
5
+ timer = null,
5
6
  phantom_exit = function(code, message){
6
7
  if (message) {
7
8
  console.log(message);
@@ -11,14 +12,34 @@ var page = require('webpage').create(),
11
12
  page.close();
12
13
  }
13
14
 
15
+ if (timer) {
16
+ clearTimeout(timer);
17
+ }
18
+
14
19
  phantom.exit(code || 0);
15
20
  };
21
+ if (phantom.version.major < 1 || phantom.version.minor < 7) {
22
+ phantom_exit(1, "PhantomJS version must greater than 1.7!");
23
+ }
16
24
  if (system_args_len < 3 || system_args_len > 12) {
17
- phantom_exit(1, "Usage: phantomjs rasterize.js SOURCE DESTINATION [paperWidth*paperHeight|paperFormat] [header] [footer] [margin] [orientation] [zoom] [cookie_file] [render_timeout] [timeout]\n : paper (pdf output) examples: \"5in*7.5in\", \"10cm*20cm\", \"A4\", \"Letter\"");
25
+ phantom_exit(1, "Usage: phantomjs rasterize.js SOURCE DESTINATION [paperWidth*paperHeight|paperFormat] [header] [footer] [margin] [orientation] [zoom] [cookies] [render_timeout] [timeout]\n : paper (pdf output) examples: \"5in*7.5in\", \"10cm*20cm\", \"A4\", \"Letter\"");
18
26
  }
19
27
 
20
- var // PhantomJS CAN NOT handle images in custom header/footer,
28
+ var input = system.args[1],
29
+ output = system.args[2],
30
+
31
+ margin = system.args[6] || '0cm',
32
+ orientation = system.args[7] || 'portrait',
33
+ zoom = system.args[8] || '1.0',
34
+
35
+ cookies = system.args[9],
36
+
37
+ render_timeout = system.args[10] || 10000,
38
+ timeout = system.args[11] || 90000,
39
+
40
+ // PhantomJS CAN NOT handle images in custom header/footer,
21
41
  // and this is used to fix the issue.
42
+ // NOTE: You must pass HTML content if you want to use this feature!
22
43
  io_images = [],
23
44
 
24
45
  is_http = function(s){
@@ -82,7 +103,7 @@ var // PhantomJS CAN NOT handle images in custom header/footer,
82
103
  page.content = inject_images(html);
83
104
  }
84
105
 
85
- window.setTimeout(function(){
106
+ timer = window.setTimeout(function(){
86
107
  var output_tmp = output + '_tmp.pdf';
87
108
 
88
109
  page.render(output_tmp);
@@ -105,22 +126,10 @@ var // PhantomJS CAN NOT handle images in custom header/footer,
105
126
 
106
127
  phantom_exit()
107
128
  }, render_timeout);
108
- },
109
-
110
- input = system.args[1],
111
- output = system.args[2],
112
-
113
- margin = system.args[6] || '0cm',
114
- orientation = system.args[7] || 'portrait',
115
- zoom = system.args[8] || '1.0',
116
-
117
- cookie_file = system.args[9],
118
- cookies = {},
119
-
120
- render_timeout = system.args[10] || 10000,
121
- timeout = system.args[11] || 90000;
129
+ };
122
130
 
123
- window.setTimeout(function(){
131
+ var overtimer = window.setTimeout(function(){
132
+ clearTimeout(overtimer);
124
133
  phantom_exit(1, "Shit's being weird no result within " + timeout + "ms");
125
134
  }, timeout);
126
135
 
@@ -166,17 +175,15 @@ if (output.substr(-4) === '.pdf') {
166
175
  page.zoomFactor = zoom;
167
176
 
168
177
  // cookies injection
169
- if (cookie_file) {
178
+ phantom.cookiesEnabled = false;
179
+ if (cookies) {
170
180
  try {
171
- fd = fs.open(cookie_file, 'r');
172
- cookies = JSON.parse(fd.read());
173
- fs.remove(cookie_file);
174
-
181
+ cookies = JSON.parse(cookies);
175
182
 
176
183
  phantom.cookiesEnabled = true;
177
184
  phantom.cookies = cookies;
178
185
  } catch (e) {
179
- // ignore
186
+ phantom.cookiesEnabled = false;
180
187
  }
181
188
  }
182
189
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phantompdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spring MC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-12 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phantomjs
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.1.4
163
+ rubygems_version: 2.1.11
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: A PhantomJS based PDF generator
@@ -173,4 +173,3 @@ test_files:
173
173
  - spec/phantompdf/middleware_spec.rb
174
174
  - spec/phantompdf/source_spec.rb
175
175
  - spec/spec_helper.rb
176
- has_rdoc: