wraith 2.8.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wraith/gallery.rb +9 -2
- data/lib/wraith/javascript/_helper.js +45 -0
- data/lib/wraith/javascript/_phantom__common.js +112 -0
- data/lib/wraith/javascript/casper.js +81 -0
- data/{templates → lib/wraith}/javascript/phantom--nojs.js +0 -0
- data/{templates → lib/wraith}/javascript/phantom.js +0 -0
- data/lib/wraith/save_images.rb +45 -17
- data/lib/wraith/version.rb +1 -1
- data/lib/wraith/wraith.rb +39 -11
- data/spec/{helpers.rb → _helpers.rb} +5 -4
- data/spec/before_capture_spec.rb +81 -0
- data/spec/config_spec.rb +139 -0
- data/spec/configs/test_config--casper.yaml +2 -2
- data/spec/configs/test_config--phantom.yaml +3 -3
- data/spec/gallery_spec.rb +38 -0
- data/{templates/javascript/casper.js → spec/js/custom_snap_file.js} +5 -1
- data/spec/resize_reload_spec.rb +55 -0
- data/spec/save_images_spec.rb +54 -0
- data/templates/configs/component.yaml +4 -7
- data/templates/configs/multiple_domains.yaml +2 -8
- data/templates/configs/spider.yaml +13 -19
- data/templates/javascript/beforeCapture--casper_example.js +10 -3
- data/templates/javascript/beforeCapture--phantom_example.js +29 -2
- metadata +51 -42
- data/spec/wraith_spec.rb +0 -209
- data/templates/javascript/README.md +0 -5
- data/templates/javascript/_getDimensions.js +0 -7
- data/templates/javascript/_phantom__common.js +0 -122
@@ -1,5 +0,0 @@
|
|
1
|
-
These JavaScript files have been provided by Wraith for your benefit, but you are free to edit these or add new JavaScript files if you wish.
|
2
|
-
|
3
|
-
Files beginning with an underscore should not be referenced directly in your YAML files. They are 'private' modules required by some of the other modules in this directory.
|
4
|
-
|
5
|
-
The two most important files to be aware of are `casper.js` and `_phantom__common.js`, as these files map Wraith's command line arguments to each respective browser engine.
|
@@ -1,122 +0,0 @@
|
|
1
|
-
module.exports = function (config) {
|
2
|
-
|
3
|
-
// modules
|
4
|
-
var page = require('webpage').create();
|
5
|
-
|
6
|
-
// config
|
7
|
-
var systemArgs = config.systemArgs,
|
8
|
-
javascriptEnabled = config.javascriptEnabled;
|
9
|
-
|
10
|
-
// command line arguments
|
11
|
-
var url = systemArgs[1],
|
12
|
-
dimensions = require('./_getDimensions.js')(systemArgs[2]),
|
13
|
-
image_name = systemArgs[3],
|
14
|
-
selector = systemArgs[4],
|
15
|
-
globalBeforeCaptureJS = systemArgs[5],
|
16
|
-
pathBeforeCaptureJS = systemArgs[6];
|
17
|
-
|
18
|
-
globalBeforeCaptureJS = globalBeforeCaptureJS === 'false' ? false : globalBeforeCaptureJS;
|
19
|
-
pathBeforeCaptureJS = pathBeforeCaptureJS === 'false' ? false : pathBeforeCaptureJS;
|
20
|
-
|
21
|
-
var current_requests = 0;
|
22
|
-
var last_request_timeout;
|
23
|
-
var final_timeout;
|
24
|
-
|
25
|
-
page.viewportSize = { width: dimensions.viewportWidth, height: dimensions.viewportHeight};
|
26
|
-
page.settings = { loadImages: true, javascriptEnabled: javascriptEnabled };
|
27
|
-
|
28
|
-
// If you want to use additional phantomjs commands, place them here
|
29
|
-
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.17';
|
30
|
-
|
31
|
-
// You can place custom headers here, example below.
|
32
|
-
// page.customHeaders = {
|
33
|
-
|
34
|
-
// 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
|
35
|
-
|
36
|
-
// };
|
37
|
-
|
38
|
-
// If you want to set a cookie, just add your details below in the following way.
|
39
|
-
|
40
|
-
// phantom.addCookie({
|
41
|
-
// 'name': 'ckns_policy',
|
42
|
-
// 'value': '111',
|
43
|
-
// 'domain': '.bbc.co.uk'
|
44
|
-
// });
|
45
|
-
// phantom.addCookie({
|
46
|
-
// 'name': 'locserv',
|
47
|
-
// 'value': '1#l1#i=6691484:n=Oxford+Circus:h=e@w1#i=8:p=London@d1#1=l:2=e:3=e:4=2@n1#r=40',
|
48
|
-
// 'domain': '.bbc.co.uk'
|
49
|
-
// });
|
50
|
-
|
51
|
-
page.onResourceRequested = function(req) {
|
52
|
-
current_requests += 1;
|
53
|
-
};
|
54
|
-
|
55
|
-
page.onResourceReceived = function(res) {
|
56
|
-
if (res.stage === 'end') {
|
57
|
-
current_requests -= 1;
|
58
|
-
debounced_render();
|
59
|
-
}
|
60
|
-
};
|
61
|
-
|
62
|
-
page.open(url, function(status) {
|
63
|
-
if (status !== 'success') {
|
64
|
-
console.log('Error with page ' + url);
|
65
|
-
phantom.exit();
|
66
|
-
}
|
67
|
-
});
|
68
|
-
|
69
|
-
|
70
|
-
function debounced_render() {
|
71
|
-
clearTimeout(last_request_timeout);
|
72
|
-
clearTimeout(final_timeout);
|
73
|
-
|
74
|
-
// If there's no more ongoing resource requests, wait for 1 second before
|
75
|
-
// rendering, just in case the page kicks off another request
|
76
|
-
if (current_requests < 1) {
|
77
|
-
clearTimeout(final_timeout);
|
78
|
-
last_request_timeout = setTimeout(function() {
|
79
|
-
|
80
|
-
if (globalBeforeCaptureJS) {
|
81
|
-
require(globalBeforeCaptureJS)(page);
|
82
|
-
}
|
83
|
-
if (pathBeforeCaptureJS) {
|
84
|
-
require(pathBeforeCaptureJS)(page);
|
85
|
-
}
|
86
|
-
|
87
|
-
console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
|
88
|
-
page.clipRect = {
|
89
|
-
top: 0,
|
90
|
-
left: 0,
|
91
|
-
height: dimensions.viewportHeight,
|
92
|
-
width: dimensions.viewportWidth
|
93
|
-
};
|
94
|
-
page.render(image_name);
|
95
|
-
phantom.exit();
|
96
|
-
}, 1000);
|
97
|
-
}
|
98
|
-
|
99
|
-
// Sometimes, straggling requests never make it back, in which
|
100
|
-
// case, timeout after 5 seconds and render the page anyway
|
101
|
-
final_timeout = setTimeout(function() {
|
102
|
-
|
103
|
-
if (globalBeforeCaptureJS) {
|
104
|
-
require(globalBeforeCaptureJS)(page);
|
105
|
-
}
|
106
|
-
if (pathBeforeCaptureJS) {
|
107
|
-
require(pathBeforeCaptureJS)(page);
|
108
|
-
}
|
109
|
-
|
110
|
-
console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
|
111
|
-
page.clipRect = {
|
112
|
-
top: 0,
|
113
|
-
left: 0,
|
114
|
-
height: dimensions.viewportHeight,
|
115
|
-
width: dimensions.viewportWidth
|
116
|
-
};
|
117
|
-
page.render(image_name);
|
118
|
-
phantom.exit();
|
119
|
-
}, 5000);
|
120
|
-
}
|
121
|
-
|
122
|
-
}
|