dragonfly_phantomjs 0.0.5 → 0.0.6
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/README.md +2 -2
- data/lib/dragonfly_phantomjs/processors/rasterize.rb +1 -1
- data/lib/dragonfly_phantomjs/version.rb +1 -1
- data/script/rasterize.js +98 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 776ea8945c3335aeed678a9c90f08924c0db9c7b
|
4
|
+
data.tar.gz: 74012ae422c42d8e70d88b36e794358a8ae81dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eac964ae595426b7b4c714f8b4fe93b6e66c8fbb5db44d58bcf11c03aead1bc87df79647435baf76eb23651bf5e4a02511ec2a9b6031d18d5431c2bc18f90f7
|
7
|
+
data.tar.gz: 2e10a14d7f7eafa7704a64a7a50b41dfe6e0d4cd83c74fbf6df93ad5a1cc8b7c8777ea9eb26011ff7249a927082297b7451c81d78399ddf2f25cd56b70be4427
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Add the plugin to Dragonfly:
|
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
Dragonfly.app.configure do
|
31
|
-
plugin :
|
31
|
+
plugin :phantomjs
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
@@ -60,4 +60,4 @@ For now refer to the phantomjs [api](http://phantomjs.org/api/webpage/property/p
|
|
60
60
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
61
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
62
|
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
-
5. Create a new Pull Request
|
63
|
+
5. Create a new Pull Request
|
data/script/rasterize.js
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
var border, element_id, footer, format, fs, header, input, margin, options, options_json, output, page, page_height, page_width, paper_size, referer, system, user_agent, viewport_height, viewport_size, viewport_width, zoom_factor;
|
2
|
+
|
3
|
+
fs = require('fs');
|
4
|
+
system = require('system');
|
5
|
+
input = system.args[1];
|
6
|
+
output = system.args[2];
|
7
|
+
|
8
|
+
if (options_json = system.args[3]) {
|
9
|
+
options = JSON.parse(options_json);
|
10
|
+
} else {
|
11
|
+
options = {};
|
12
|
+
}
|
13
|
+
|
14
|
+
margin = options['margin'] || 0;
|
15
|
+
border = options['border'] || 0;
|
16
|
+
format = options['format'] || 'A4';
|
17
|
+
paper_size = options['paper_size'];
|
18
|
+
viewport_size = options['viewport_size'];
|
19
|
+
zoom_factor = options['zoom_factor'] || 1;
|
20
|
+
user_agent = options['user_agent'];
|
21
|
+
referer = options['referer'];
|
22
|
+
element_id = options['element_id'];
|
23
|
+
|
24
|
+
header = options['header'] ? {
|
25
|
+
height: options['header']['height'],
|
26
|
+
contents: phantom.callback(function(pageNum, numPages) {
|
27
|
+
if ((options['header']['hide_on'] || []).indexOf(pageNum) > -1) {
|
28
|
+
return "";
|
29
|
+
}
|
30
|
+
return eval(options['header']['content']);
|
31
|
+
})
|
32
|
+
} : null;
|
33
|
+
|
34
|
+
footer = options['footer'] ? {
|
35
|
+
height: options['footer']['height'],
|
36
|
+
contents: phantom.callback(function(pageNum, numPages) {
|
37
|
+
if ((options['footer']['hide_on'] || []).indexOf(pageNum) > -1) {
|
38
|
+
return "";
|
39
|
+
}
|
40
|
+
return eval(options['footer']['content']);
|
41
|
+
})
|
42
|
+
} : null;
|
43
|
+
|
44
|
+
page = require('webpage').create();
|
45
|
+
|
46
|
+
if (user_agent) {
|
47
|
+
page.settings.userAgent = options['user_agent'];
|
48
|
+
}
|
49
|
+
|
50
|
+
if (referer) {
|
51
|
+
page.customHeaders = {
|
52
|
+
'Referer': options['referer']
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
if (output.substr(-4) === ".pdf") {
|
57
|
+
if (paper_size !== void 0) {
|
58
|
+
page_width = paper_size.split('*')[0];
|
59
|
+
page_height = paper_size.split('*')[1];
|
60
|
+
page.paperSize = {
|
61
|
+
width: page_width,
|
62
|
+
height: page_height,
|
63
|
+
margin: margin,
|
64
|
+
border: border,
|
65
|
+
header: header,
|
66
|
+
footer: footer
|
67
|
+
};
|
68
|
+
} else if (format !== void 0) {
|
69
|
+
page.paperSize = {
|
70
|
+
format: format,
|
71
|
+
margin: margin,
|
72
|
+
border: border,
|
73
|
+
header: header,
|
74
|
+
footer: footer
|
75
|
+
};
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
if (viewport_size !== void 0) {
|
80
|
+
viewport_width = viewport_size.split('*')[0];
|
81
|
+
viewport_height = viewport_size.split('*')[1];
|
82
|
+
page.viewportSize = {
|
83
|
+
width: viewport_width,
|
84
|
+
height: viewport_height
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
page.zoomFactor = zoom_factor;
|
89
|
+
|
90
|
+
page.open(input, function() {
|
91
|
+
if (element_id) {
|
92
|
+
page.clipRect = page.evaluate(function() {
|
93
|
+
return document.getElementById('demo').getBoundingClientRect();
|
94
|
+
});
|
95
|
+
}
|
96
|
+
page.render(output);
|
97
|
+
return phantom.exit();
|
98
|
+
});
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly_phantomjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- samples/sample.html
|
133
133
|
- samples/sample.svg
|
134
134
|
- script/rasterize.coffee
|
135
|
+
- script/rasterize.js
|
135
136
|
- test/dragonfly_phantomjs/plugin_test.rb
|
136
137
|
- test/dragonfly_phantomjs/processors/rasterize_test.rb
|
137
138
|
- test/test_helper.rb
|