ghost_in_the_post 0.0.6 → 0.0.7
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/lib/ghost_in_the_post/phantom/staticize.js +2 -2
- data/lib/ghost_in_the_post/phantom_transform.rb +17 -3
- data/lib/ghost_in_the_post/version.rb +1 -1
- data/spec/dummy/Gemfile.lock +1 -1
- data/spec/dummy/log/development.log +4 -0
- data/spec/lib/ghost_in_the_post/phantom_transform_spec.rb +29 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6561f125f9d69483b0e7179f0cb1369e4d5fab94
|
4
|
+
data.tar.gz: 089cd0a208b3ad1b1bf72f134adf049ca167820c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 898b9dbbaf58f25ca5afb4c732a1aba39c6bc09e7b313771cc5e645d796760a2a143a78ec08aaebd468d16447c952af4a1fe46042c4a548098d6e67248152c5e
|
7
|
+
data.tar.gz: a43d7270016d22ca4a160ecd1363b51f74b8a61018ed5d0402bc9c8a8afab62408a5b9e05cab61ad7c155ff5390ec4d065c5dad7b0dbd20826b9022baada2e2f
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
var system = require('system'),
|
3
3
|
page = require('webpage').create(),
|
4
|
-
|
4
|
+
address = system.args[1], //tmp file of the html to be processed
|
5
5
|
timeout = parseInt(system.args[4]) || 1000, //return page contents after a timeout
|
6
6
|
wait_event = system.args[5], //return page contents after an event
|
7
7
|
error_tag = "[GHOSTINTHEPOST-STATICIZE-ERROR]";
|
@@ -46,4 +46,4 @@ page.onLoadFinished = function(status){
|
|
46
46
|
};
|
47
47
|
|
48
48
|
//load html content
|
49
|
-
page.
|
49
|
+
page.open("file://"+address)
|
@@ -15,23 +15,37 @@ module GhostInThePost
|
|
15
15
|
def transform
|
16
16
|
@inliner.inline
|
17
17
|
p @inliner.html if GhostInThePost.debug
|
18
|
-
|
18
|
+
begin
|
19
|
+
htmlfile = html_file(@inliner.html)
|
20
|
+
@inliner.html = checkError(IO.popen(command(htmlfile)){|io| io.read})
|
21
|
+
ensure
|
22
|
+
htmlfile.unlink unless htmlfile.nil?
|
23
|
+
end
|
19
24
|
@inliner.remove_all_script if GhostInThePost.remove_js_tags
|
20
25
|
@inliner.html
|
21
26
|
end
|
22
27
|
|
23
28
|
private
|
24
29
|
|
25
|
-
def command
|
30
|
+
def command html_file
|
26
31
|
[
|
27
32
|
GhostInThePost.phantomjs_path,
|
28
33
|
PHANTOMJS_SCRIPT,
|
29
|
-
|
34
|
+
html_file.path,
|
30
35
|
@timeout,
|
31
36
|
@wait_event,
|
32
37
|
].map(&:to_s)
|
33
38
|
end
|
34
39
|
|
40
|
+
#generate a tempfile with all the html that we need so that phantom can inject
|
41
|
+
#easily and not have to max out a single command
|
42
|
+
def html_file(html)
|
43
|
+
file = Tempfile.new(['inject', '.html'])
|
44
|
+
file.write(html)
|
45
|
+
file.close #closing the file makes it accessible by phantom
|
46
|
+
file
|
47
|
+
end
|
48
|
+
|
35
49
|
def checkError output
|
36
50
|
raise GhostJSError.new(output.gsub(ERROR_TAG, "")) if output.start_with?(ERROR_TAG)
|
37
51
|
output
|
data/spec/dummy/Gemfile.lock
CHANGED
@@ -494,3 +494,7 @@ AutoMailer#normal_email: processed outbound mail in 545.1ms
|
|
494
494
|
Rendered auto_mailer/normal_email.text (0.3ms)
|
495
495
|
|
496
496
|
AutoMailer#normal_email: processed outbound mail in 542.3ms
|
497
|
+
Rendered auto_mailer/normal_email.html.erb (229.4ms)
|
498
|
+
Rendered auto_mailer/normal_email.text (0.4ms)
|
499
|
+
|
500
|
+
AutoMailer#normal_email: processed outbound mail in 552.5ms
|
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
3
3
|
module GhostInThePost
|
4
4
|
describe PhantomTransform do
|
5
5
|
let(:html){"<html><head><script></script></head><body><div id='test'></div></body></html>"}
|
6
|
+
let(:html_path){"/this/is/path"}
|
6
7
|
let(:js){"(function(){document.getElementById('test').innerHTML='complete';})()"}
|
7
8
|
let(:included_scripts){["application.js"]}
|
8
9
|
subject {PhantomTransform.new(html, nil, nil,included_scripts)}
|
@@ -41,13 +42,20 @@ module GhostInThePost
|
|
41
42
|
@inliner = JsInline.new(html)
|
42
43
|
allow(@inliner).to receive(:inline)
|
43
44
|
allow(JsInline).to receive(:new){@inliner}
|
45
|
+
|
46
|
+
@file = Object.new
|
47
|
+
allow(Tempfile).to receive(:new){@file}
|
48
|
+
allow(@file).to receive(:path){html_path}
|
49
|
+
allow(@file).to receive(:write)
|
50
|
+
allow(@file).to receive(:close)
|
51
|
+
allow(@file).to receive(:unlink)
|
44
52
|
end
|
45
53
|
|
46
54
|
it "should call IO.popen with arguments" do
|
47
55
|
expect(IO).to receive(:popen).with([
|
48
56
|
GhostInThePost.phantomjs_path,
|
49
57
|
GhostInThePost::PhantomTransform::PHANTOMJS_SCRIPT,
|
50
|
-
|
58
|
+
html_path,
|
51
59
|
"1000",
|
52
60
|
"ghost_in_the_post:done",
|
53
61
|
]).and_return html
|
@@ -66,6 +74,26 @@ module GhostInThePost
|
|
66
74
|
subject.transform
|
67
75
|
end
|
68
76
|
|
77
|
+
it "should create a temp file for the html" do
|
78
|
+
allow(IO).to receive(:popen).and_return ""
|
79
|
+
file = Object.new
|
80
|
+
expect(Tempfile).to receive(:new){file}
|
81
|
+
allow(file).to receive(:path){html_path}
|
82
|
+
expect(file).to receive(:write)
|
83
|
+
expect(file).to receive(:close)
|
84
|
+
expect(file).to receive(:unlink)
|
85
|
+
subject.transform
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should unlink file even if there was an error" do
|
89
|
+
html_file = Object.new
|
90
|
+
expect(subject).to receive(:html_file){html_file}
|
91
|
+
allow(html_file).to receive(:path){html_path}
|
92
|
+
expect(html_file).to receive(:unlink)
|
93
|
+
allow(IO).to receive(:popen) {raise ArgumentError}
|
94
|
+
expect{subject.transform}.to raise_error ArgumentError
|
95
|
+
end
|
96
|
+
|
69
97
|
end
|
70
98
|
end
|
71
99
|
end
|