ghost_in_the_post 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ghost_in_the_post.rb +8 -0
- data/lib/ghost_in_the_post/automatic.rb +3 -1
- data/lib/ghost_in_the_post/ghost_on_command.rb +2 -2
- data/lib/ghost_in_the_post/mail_ghost.rb +5 -3
- data/lib/ghost_in_the_post/mailer.rb +3 -1
- data/lib/ghost_in_the_post/phantom/staticize.js +26 -12
- data/lib/ghost_in_the_post/phantom_transform.rb +38 -33
- data/lib/ghost_in_the_post/version.rb +1 -1
- data/spec/dummy/Gemfile +4 -0
- data/spec/dummy/Gemfile.lock +8 -0
- data/spec/dummy/log/development.log +56 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4PgfVpd4CZQ0vAsVTl2KDb1z4f6GLl4mXIc3jSrahHM.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6wWiAXBcdY6PLKOIhXQ6c8h9UtViuvdLcEO6wXK3mh0.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/J_D4gpddr1KPVysTvEE48iHsNzrL5Pbj8S5ZNt3PhA4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UbKcvOd2xh3MJoKxz4l4RHMy5IupdsiDoSllZDvYCZA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/XuOqk2dVOcltjkihZ8J_u5Pbcm9Of5KFkjyihP6-5tc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xstXMnjOlL2Ynn6MaI9bxlRnhTPYdgCIeOWnWphFSlA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zRSH1x7PsiRf9MSILPhc4GKDjRo4xaFNd41wHFCtJSo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zUYxDxkUr_FKBi6fF7kellqyG52AoZbYItHMUq17DJo.cache +1 -0
- data/spec/lib/ghost_in_the_post/ghost_on_command_spec.rb +3 -1
- data/spec/lib/ghost_in_the_post/mail_ghost_spec.rb +5 -3
- data/spec/lib/ghost_in_the_post/phantom_transform_spec.rb +79 -94
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fdee37440de2543663fe6262bbb9462814f01dd
|
4
|
+
data.tar.gz: 015968eca2634d160b1902de601061f3c7538e6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aadad0634b972c587c121282b199f53820300a91d1fb950aa2fc2b3ea3c3bbfbf7cbca9aee87c8da2fd05f47952c9c2283c6782205fb43a0831c51470c412b9
|
7
|
+
data.tar.gz: f34444669b33981f2057279e08c637cd168a4bc0c1d3aa18a060fbfe3066292ea2aad7b75a42850f04e6a0a74b82a713910c1aeb980a9e4353bc4715bd136876
|
data/lib/ghost_in_the_post.rb
CHANGED
@@ -4,11 +4,17 @@ module GhostInThePost
|
|
4
4
|
:phantomjs_path,
|
5
5
|
:includes,
|
6
6
|
:remove_js_tags,
|
7
|
+
:timeout,
|
8
|
+
:wait_event,
|
7
9
|
]
|
10
|
+
DEFAULT_TIMEOUT = 1000
|
11
|
+
DEFAULT_WAIT_EVENT = "ghost_in_the_post:done"
|
8
12
|
private_constant :ATTRIBUTE_NAMES
|
9
13
|
cattr_reader(*ATTRIBUTE_NAMES)
|
10
14
|
|
11
15
|
@@phantomjs_path = nil #setting this to nil helps testing
|
16
|
+
@@timeout = DEFAULT_TIMEOUT
|
17
|
+
@@wait_event = DEFAULT_WAIT_EVENT
|
12
18
|
@@includes = []
|
13
19
|
@@remove_js_tags = true
|
14
20
|
|
@@ -17,6 +23,8 @@ module GhostInThePost
|
|
17
23
|
@@phantomjs_path = new_config[:phantomjs_path]
|
18
24
|
@@includes = Array(new_config[:includes])
|
19
25
|
@@remove_js_tags = new_config[:remove_js_tags].nil? ? true : new_config[:remove_js_tags]
|
26
|
+
@@timeout = new_config[:timeout] || DEFAULT_TIMEOUT
|
27
|
+
@@wait_event = new_config[:wait_event] || DEFAULT_WAIT_EVENT
|
20
28
|
raise ArgumentError, "GhostInThePost.config.phantomjs_path is not set" if self.phantomjs_path.nil?
|
21
29
|
end
|
22
30
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module GhostInThePost
|
2
2
|
module Automatic
|
3
|
-
attr_accessor :included_scripts
|
3
|
+
attr_accessor :included_scripts, :ghost_timeout, :ghost_wait_event
|
4
4
|
|
5
5
|
def include_script(*paths)
|
6
6
|
@included_scripts ||= []
|
@@ -12,6 +12,8 @@ module GhostInThePost
|
|
12
12
|
email.extend GhostOnCommand
|
13
13
|
email.extend GhostOnDelivery
|
14
14
|
email.included_scripts = @included_scripts
|
15
|
+
email.ghost_timeout = @ghost_timeout
|
16
|
+
email.ghost_wait_event = @ghost_wait_event
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module GhostInThePost
|
2
2
|
module GhostOnCommand
|
3
|
-
attr_accessor :included_scripts
|
3
|
+
attr_accessor :included_scripts, :ghost_timeout, :ghost_wait_event
|
4
4
|
|
5
5
|
def ghost
|
6
|
-
MailGhost.new(self, included_scripts).execute
|
6
|
+
MailGhost.new(self, ghost_timeout, ghost_wait_event, included_scripts).execute
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module GhostInThePost
|
2
2
|
class MailGhost
|
3
|
-
attr_reader :email, :included_scripts
|
3
|
+
attr_reader :email, :included_scripts, :timeout, :wait_event
|
4
4
|
|
5
|
-
def initialize(email, included_scripts)
|
5
|
+
def initialize(email, timeout=nil, wait_event=nil, included_scripts=[])
|
6
6
|
@email = email
|
7
|
+
@timeout = timeout
|
8
|
+
@wait_event = wait_event
|
7
9
|
@included_scripts = Array(included_scripts).compact
|
8
10
|
end
|
9
11
|
|
@@ -24,7 +26,7 @@ module GhostInThePost
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def ghost_html(old_html)
|
27
|
-
PhantomTransform.new(old_html, included_scripts).transform
|
29
|
+
PhantomTransform.new(old_html, timeout, wait_event, included_scripts).transform
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module GhostInThePost
|
2
2
|
module Mailer
|
3
|
-
attr_accessor :included_scripts
|
3
|
+
attr_accessor :included_scripts, :ghost_timeout, :ghost_wait_event
|
4
4
|
|
5
5
|
def include_script(*paths)
|
6
6
|
@included_scripts ||= []
|
@@ -11,6 +11,8 @@ module GhostInThePost
|
|
11
11
|
super.tap do |email|
|
12
12
|
email.extend GhostOnCommand
|
13
13
|
email.included_scripts = included_scripts
|
14
|
+
email.ghost_timeout = @ghost_timeout
|
15
|
+
email.ghost_wait_event = @ghost_wait_event
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -1,15 +1,26 @@
|
|
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
|
no_script = system.args[2] == "true",
|
6
|
-
include = system.args[3]
|
6
|
+
include = system.args[3], //tmp file for the injected js file
|
7
|
+
timeout = parseInt(system.args[4]) || 1000, //return page contents after a timeout
|
8
|
+
wait_event = system.args[5]; //return page contents after an event
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
//write out to console to export contents
|
11
|
+
//and get out of here
|
12
|
+
function finish(){
|
13
|
+
console.log(page.content);
|
14
|
+
phantom.exit();
|
15
|
+
}
|
16
|
+
|
17
|
+
page.onLoadFinished = function(status){
|
18
|
+
//catch wait_event
|
19
|
+
page.onCallback = finish
|
20
|
+
page.evaluate(function(finish, wait_event) {
|
21
|
+
document.addEventListener(wait_event, window.callPhantom, false)
|
22
|
+
}, finish, wait_event)
|
23
|
+
//clear script tags
|
13
24
|
if(no_script) {
|
14
25
|
page.evaluate(function(){
|
15
26
|
var script_tags = document.getElementsByTagName("script");
|
@@ -18,10 +29,13 @@ page.onLoadFinished = function(status) {
|
|
18
29
|
}
|
19
30
|
})
|
20
31
|
}
|
21
|
-
//
|
22
|
-
|
23
|
-
|
32
|
+
//load included scripts to be loaded on the dom
|
33
|
+
if(!!include){
|
34
|
+
page.injectJs(include);
|
35
|
+
}
|
36
|
+
if(timeout > 0){
|
37
|
+
setTimeout(finish, timeout);//timout to bailout after a period
|
38
|
+
}
|
24
39
|
};
|
25
|
-
//load html content
|
26
|
-
page.setContent(html, 'http://www.whatever.com');
|
27
40
|
|
41
|
+
page.open("file://"+address)
|
@@ -2,55 +2,60 @@ module GhostInThePost
|
|
2
2
|
class PhantomTransform
|
3
3
|
PHANTOMJS_SCRIPT = File.expand_path('../phantom/staticize.js', __FILE__)
|
4
4
|
|
5
|
-
def initialize(html, included_scripts=[])
|
5
|
+
def initialize(html, timeout=nil, wait_event=nil, included_scripts=[])
|
6
6
|
@html = html
|
7
|
+
@timeout = timeout || GhostInThePost.timeout
|
8
|
+
@wait_event = wait_event || GhostInThePost.wait_event
|
7
9
|
@included_scripts = Array(included_scripts).compact
|
8
10
|
end
|
9
11
|
|
10
12
|
def transform
|
11
|
-
|
13
|
+
output = @html
|
14
|
+
begin
|
15
|
+
htmlfile = html_file()
|
16
|
+
jsfile = js_file()
|
17
|
+
p command(htmlfile, jsfile)
|
18
|
+
output = IO.popen(command(htmlfile, jsfile)){|io| io.read}
|
19
|
+
ensure
|
20
|
+
htmlfile.unlink unless htmlfile.nil?
|
21
|
+
jsfile.unlink unless jsfile.nil?
|
22
|
+
end
|
23
|
+
output
|
12
24
|
end
|
13
25
|
|
14
26
|
private
|
15
27
|
|
16
|
-
def command
|
28
|
+
def command(htmlfile, jsfile)
|
17
29
|
[
|
18
30
|
GhostInThePost.phantomjs_path,
|
19
31
|
PHANTOMJS_SCRIPT,
|
20
|
-
|
21
|
-
GhostInThePost.remove_js_tags
|
22
|
-
|
32
|
+
htmlfile.path,
|
33
|
+
GhostInThePost.remove_js_tags,
|
34
|
+
jsfile.path,
|
35
|
+
@timeout,
|
36
|
+
@wait_event,
|
37
|
+
].map(&:to_s)
|
23
38
|
end
|
24
39
|
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#easily and not have to max out a single command
|
33
|
-
file = Tempfile.new(['inject', '.js'])
|
34
|
-
injectable_scripts.map do |script|
|
35
|
-
asset = find_asset_in_pipeline(script)
|
36
|
-
file.write(asset.to_s) unless asset.nil?
|
37
|
-
end.compact
|
38
|
-
file.close #closing the file makes it accessible by phantom
|
39
|
-
|
40
|
-
#generate the html with the javascript
|
41
|
-
output = IO.popen(command + [file.path]){|io| io.read}
|
42
|
-
|
43
|
-
file.unlink
|
44
|
-
rescue => e
|
45
|
-
#clean up the temp file
|
46
|
-
file.unlink
|
47
|
-
end
|
48
|
-
output
|
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
|
43
|
+
file = Tempfile.new(['inject', '.html'])
|
44
|
+
file.write(@html)
|
45
|
+
file.close #closing the file makes it accessible by phantom
|
46
|
+
file
|
49
47
|
end
|
50
48
|
|
51
|
-
#
|
52
|
-
|
53
|
-
|
49
|
+
#generate a tempfile with all the js that we need so that phantom can inject
|
50
|
+
#easily and not have to max out a single command
|
51
|
+
def js_file
|
52
|
+
jsfile = Tempfile.new(['inject', '.js'])
|
53
|
+
injectable_scripts.map do |script|
|
54
|
+
asset = find_asset_in_pipeline(script)
|
55
|
+
jsfile.write(asset.to_s) unless asset.nil?
|
56
|
+
end.compact
|
57
|
+
jsfile.close #closing the file makes it accessible by phantom
|
58
|
+
jsfile
|
54
59
|
end
|
55
60
|
|
56
61
|
def injectable_scripts
|
data/spec/dummy/Gemfile
CHANGED
data/spec/dummy/Gemfile.lock
CHANGED
@@ -44,6 +44,7 @@ GEM
|
|
44
44
|
tzinfo (~> 1.1)
|
45
45
|
arel (6.0.3)
|
46
46
|
builder (3.2.2)
|
47
|
+
coderay (1.1.0)
|
47
48
|
concurrent-ruby (1.0.0)
|
48
49
|
concurrent-ruby (1.0.0-java)
|
49
50
|
erubis (2.7.0)
|
@@ -56,12 +57,17 @@ GEM
|
|
56
57
|
nokogiri (>= 1.5.9)
|
57
58
|
mail (2.6.3)
|
58
59
|
mime-types (>= 1.16, < 3)
|
60
|
+
method_source (0.8.2)
|
59
61
|
mime-types (2.99)
|
60
62
|
mini_portile2 (2.0.0)
|
61
63
|
minitest (5.8.4)
|
62
64
|
nokogiri (1.6.7.2)
|
63
65
|
mini_portile2 (~> 2.0.0.rc2)
|
64
66
|
nokogiri (1.6.7.2-java)
|
67
|
+
pry (0.10.3)
|
68
|
+
coderay (~> 1.1.0)
|
69
|
+
method_source (~> 0.8.1)
|
70
|
+
slop (~> 3.4)
|
65
71
|
rack (1.6.4)
|
66
72
|
rack-test (0.6.3)
|
67
73
|
rack (>= 1.0)
|
@@ -90,6 +96,7 @@ GEM
|
|
90
96
|
rake (>= 0.8.7)
|
91
97
|
thor (>= 0.18.1, < 2.0)
|
92
98
|
rake (10.5.0)
|
99
|
+
slop (3.6.0)
|
93
100
|
sprockets (3.5.2)
|
94
101
|
concurrent-ruby (~> 1.0)
|
95
102
|
rack (> 1, < 3)
|
@@ -109,6 +116,7 @@ PLATFORMS
|
|
109
116
|
|
110
117
|
DEPENDENCIES
|
111
118
|
ghost_in_the_post!
|
119
|
+
pry
|
112
120
|
rails (= 4.2.3)
|
113
121
|
|
114
122
|
BUNDLED WITH
|
@@ -214,3 +214,59 @@ AutoMailer#normal_email: processed outbound mail in 42.0ms
|
|
214
214
|
Rendered auto_mailer/normal_email.text (4.0ms)
|
215
215
|
|
216
216
|
AutoMailer#normal_email: processed outbound mail in 415.0ms
|
217
|
+
Rendered auto_mailer/normal_email.html.erb (1.9ms)
|
218
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
219
|
+
|
220
|
+
AutoMailer#normal_email: processed outbound mail in 218.4ms
|
221
|
+
Rendered auto_mailer/normal_email.html.erb (0.1ms)
|
222
|
+
Rendered auto_mailer/normal_email.text (0.0ms)
|
223
|
+
|
224
|
+
AutoMailer#normal_email: processed outbound mail in 10.3ms
|
225
|
+
Rendered auto_mailer/normal_email.html.erb (1.7ms)
|
226
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
227
|
+
|
228
|
+
AutoMailer#normal_email: processed outbound mail in 222.5ms
|
229
|
+
Rendered auto_mailer/normal_email.html.erb (1.8ms)
|
230
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
231
|
+
|
232
|
+
AutoMailer#normal_email: processed outbound mail in 221.7ms
|
233
|
+
Rendered auto_mailer/normal_email.html.erb (1.9ms)
|
234
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
235
|
+
|
236
|
+
AutoMailer#normal_email: processed outbound mail in 217.4ms
|
237
|
+
Rendered auto_mailer/normal_email.html.erb (0.1ms)
|
238
|
+
Rendered auto_mailer/normal_email.text (0.1ms)
|
239
|
+
|
240
|
+
AutoMailer#normal_email: processed outbound mail in 11.7ms
|
241
|
+
Rendered auto_mailer/normal_email.html.erb (0.1ms)
|
242
|
+
Rendered auto_mailer/normal_email.text (0.1ms)
|
243
|
+
|
244
|
+
AutoMailer#normal_email: processed outbound mail in 14.3ms
|
245
|
+
Rendered auto_mailer/normal_email.html.erb (4.9ms)
|
246
|
+
Rendered auto_mailer/normal_email.text (0.7ms)
|
247
|
+
|
248
|
+
AutoMailer#normal_email: processed outbound mail in 318.1ms
|
249
|
+
Rendered auto_mailer/normal_email.html.erb (2.0ms)
|
250
|
+
Rendered auto_mailer/normal_email.text (0.4ms)
|
251
|
+
|
252
|
+
AutoMailer#normal_email: processed outbound mail in 226.4ms
|
253
|
+
Rendered auto_mailer/normal_email.html.erb (0.1ms)
|
254
|
+
Rendered auto_mailer/normal_email.text (0.0ms)
|
255
|
+
|
256
|
+
AutoMailer#normal_email: processed outbound mail in 8.6ms
|
257
|
+
Rendered auto_mailer/normal_email.html.erb (2.1ms)
|
258
|
+
Rendered auto_mailer/normal_email.text (0.4ms)
|
259
|
+
|
260
|
+
AutoMailer#normal_email: processed outbound mail in 226.5ms
|
261
|
+
Rendered auto_mailer/normal_email.html.erb (2.0ms)
|
262
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
263
|
+
|
264
|
+
AutoMailer#normal_email: processed outbound mail in 218.6ms
|
265
|
+
Rendered auto_mailer/normal_email.html.erb (1.1ms)
|
266
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
267
|
+
|
268
|
+
AutoMailer#normal_email: processed outbound mail in 180.1ms
|
269
|
+
Rendered auto_mailer/normal_email.html.erb (1.8ms)
|
270
|
+
Rendered auto_mailer/normal_email.text (0.3ms)
|
271
|
+
|
272
|
+
AutoMailer#normal_email: processed outbound mail in 224.1ms
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6wWiAXBcdY6PLKOIhXQ6c8h9UtViuvdLcEO6wXK3mh0.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/test.js?type=application/javascript&pipeline=self&id=12b05e7da72de9b196b844829893c6dd17135d893a81b9a1872199b8189a69da:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/J_D4gpddr1KPVysTvEE48iHsNzrL5Pbj8S5ZNt3PhA4.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&id=24a76124d867ad27aa7510f40701c74430d66668ae273445d54914f5c29b5ef8:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UbKcvOd2xh3MJoKxz4l4RHMy5IupdsiDoSllZDvYCZA.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/XuOqk2dVOcltjkihZ8J_u5Pbcm9Of5KFkjyihP6-5tc.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache
CHANGED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache
CHANGED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xstXMnjOlL2Ynn6MaI9bxlRnhTPYdgCIeOWnWphFSlA.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=e3a979bc569cf175e48bf432cbfc5f77aa2bcf282931866a1f4a71d049d118ab:ET
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zRSH1x7PsiRf9MSILPhc4GKDjRo4xaFNd41wHFCtJSo.cache
ADDED
Binary file
|
data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zUYxDxkUr_FKBi6fF7kellqyG52AoZbYItHMUq17DJo.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"%f�먞3���@�����Ŝ���q�3|b��ϡB�
|
@@ -12,7 +12,9 @@ module GhostInThePost
|
|
12
12
|
end
|
13
13
|
it "should create a MailGhost" do
|
14
14
|
email.included_scripts = ["test"]
|
15
|
-
|
15
|
+
email.ghost_timeout = 1000
|
16
|
+
email.ghost_wait_event = "test"
|
17
|
+
expect(MailGhost).to receive(:new).with(email, 1000, "test", ["test"]).and_call_original
|
16
18
|
email.ghost
|
17
19
|
end
|
18
20
|
it "should apply included scripts to the mail ghost" do
|
@@ -5,10 +5,12 @@ module GhostInThePost
|
|
5
5
|
describe MailGhost do
|
6
6
|
let(:email) { Mail.new }
|
7
7
|
let(:included_scripts) { ["application.js"] }
|
8
|
-
subject(:ghost) { MailGhost.new(email, included_scripts) }
|
8
|
+
subject(:ghost) { MailGhost.new(email, 1000, "wait", included_scripts) }
|
9
9
|
|
10
10
|
it "takes an email and options" do
|
11
11
|
expect(ghost.email).to eq(email)
|
12
|
+
expect(ghost.timeout).to eq(1000)
|
13
|
+
expect(ghost.wait_event).to eq("wait")
|
12
14
|
expect(ghost.included_scripts).to eq(included_scripts)
|
13
15
|
end
|
14
16
|
|
@@ -44,7 +46,7 @@ module GhostInThePost
|
|
44
46
|
|
45
47
|
it "adjusts the html part using Roadie" do
|
46
48
|
document = double "A document", transform: "transformed HTML"
|
47
|
-
expect(PhantomTransform).to receive(:new).with(html, included_scripts).and_return document
|
49
|
+
expect(PhantomTransform).to receive(:new).with(html,1000, "wait", included_scripts).and_return document
|
48
50
|
ghost.execute
|
49
51
|
expect(email.body.decoded).to eq("transformed HTML")
|
50
52
|
end
|
@@ -62,7 +64,7 @@ module GhostInThePost
|
|
62
64
|
|
63
65
|
it "adjusts the html part using Roadie" do
|
64
66
|
document = double "A document", transform: "transformed HTML"
|
65
|
-
expect(PhantomTransform).to receive(:new).with(html, included_scripts).and_return document
|
67
|
+
expect(PhantomTransform).to receive(:new).with(html,1000, "wait", included_scripts).and_return document
|
66
68
|
ghost.execute
|
67
69
|
expect(email.html_part.body.decoded).to eq("transformed HTML")
|
68
70
|
end
|
@@ -5,7 +5,7 @@ module GhostInThePost
|
|
5
5
|
let(:html){"<html><head><script></script></head><body><div id='test'></div></body></html>"}
|
6
6
|
let(:js){"(function(){document.getElementById('test').innerHTML='complete';})()"}
|
7
7
|
let(:included_scripts){["application.js"]}
|
8
|
-
subject {PhantomTransform.new(html, included_scripts)}
|
8
|
+
subject {PhantomTransform.new(html, nil, nil,included_scripts)}
|
9
9
|
|
10
10
|
before :each do
|
11
11
|
GhostInThePost.config = {phantomjs_path: "this/is/path"}
|
@@ -14,121 +14,106 @@ module GhostInThePost
|
|
14
14
|
|
15
15
|
describe "#initialize" do
|
16
16
|
it "should set html" do
|
17
|
-
pt = PhantomTransform.new(html, included_scripts)
|
17
|
+
pt = PhantomTransform.new(html, nil, nil, included_scripts)
|
18
18
|
expect(pt.instance_variable_get(:@html)).to eq(html)
|
19
19
|
end
|
20
|
+
it "should set the timeout" do
|
21
|
+
pt = PhantomTransform.new(html, 45, nil, included_scripts)
|
22
|
+
expect(pt.instance_variable_get(:@timeout)).to eq(45)
|
23
|
+
end
|
24
|
+
it "should set the default timeout if none given" do
|
25
|
+
pt = PhantomTransform.new(html, nil, nil, included_scripts)
|
26
|
+
expect(pt.instance_variable_get(:@timeout)).to eq(GhostInThePost.timeout)
|
27
|
+
end
|
28
|
+
it "should set the wait event" do
|
29
|
+
pt = PhantomTransform.new(html, nil, "my wait", included_scripts)
|
30
|
+
expect(pt.instance_variable_get(:@wait_event)).to eq("my wait")
|
31
|
+
end
|
32
|
+
it "should set the default wait event if none given" do
|
33
|
+
pt = PhantomTransform.new(html, nil, nil, included_scripts)
|
34
|
+
expect(pt.instance_variable_get(:@wait_event)).to eq(GhostInThePost.wait_event)
|
35
|
+
end
|
20
36
|
it "should set included_scripts" do
|
21
|
-
pt = PhantomTransform.new(html, included_scripts)
|
37
|
+
pt = PhantomTransform.new(html, nil, nil, included_scripts)
|
22
38
|
expect(pt.instance_variable_get(:@included_scripts)).to eq(included_scripts)
|
23
39
|
end
|
24
40
|
it "should default included_scripts to an array" do
|
25
|
-
pt = PhantomTransform.new(html, nil)
|
41
|
+
pt = PhantomTransform.new(html, nil, nil, nil)
|
26
42
|
expect(pt.instance_variable_get(:@included_scripts)).to eq([])
|
27
43
|
end
|
28
44
|
end
|
29
45
|
|
30
46
|
describe "#transform" do
|
47
|
+
let(:html_path) {"/this/is/htmlpath"}
|
48
|
+
let(:js_path) {"/this/is/js_path"}
|
31
49
|
|
32
50
|
before :each do
|
33
51
|
allow(IO).to receive(:popen)
|
52
|
+
allow(Rails.application).to receive(:assets){{"application.js": js}}
|
34
53
|
end
|
35
54
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
"application.js": "asset string"
|
44
|
-
}
|
45
|
-
}
|
46
|
-
allow_any_instance_of(Tempfile).to receive(:path){path}
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should call transform_with_injections" do
|
50
|
-
expect(subject).to receive(:transform_with_injections)
|
51
|
-
subject.transform
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should create a temp file, write to it and unlink it" do
|
55
|
-
file = Object.new
|
56
|
-
expect(subject).to receive(:injectable_scripts).twice{included_scripts}
|
57
|
-
expect(subject).to receive(:find_asset_in_pipeline).once.with(included_scripts.first){""}
|
58
|
-
expect(Tempfile).to receive(:new).with(['inject', '.js']){file}
|
59
|
-
allow(file).to receive(:path){path}
|
60
|
-
expect(file).to receive(:write)
|
61
|
-
expect(file).to receive(:close)
|
62
|
-
expect(file).to receive(:unlink)
|
63
|
-
subject.transform
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should call IO.popen with arguments" do
|
67
|
-
expect(IO).to receive(:popen).with([
|
68
|
-
GhostInThePost.phantomjs_path,
|
69
|
-
GhostInThePost::PhantomTransform::PHANTOMJS_SCRIPT,
|
70
|
-
html,
|
71
|
-
GhostInThePost.remove_js_tags,
|
72
|
-
path
|
73
|
-
])
|
74
|
-
subject.transform
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should return the result of IO.popen with arguments" do
|
78
|
-
allow(IO).to receive(:popen) {"this is the end"}
|
79
|
-
expect(subject.transform).to eq("this is the end")
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should return the html if there was an error" do
|
83
|
-
file = Object.new
|
84
|
-
allow(Tempfile).to receive(:new).with(['inject', '.js']){file}
|
85
|
-
allow(file).to receive(:path){path}
|
86
|
-
allow(file).to receive(:write)
|
87
|
-
allow(file).to receive(:close)
|
88
|
-
allow(file).to receive(:unlink)
|
89
|
-
allow(IO).to receive(:popen) {raise ArgumentError}
|
90
|
-
expect(subject.transform).to eq(html)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should unlink file even if there was an error" do
|
94
|
-
file = Object.new
|
95
|
-
allow(Tempfile).to receive(:new).with(['inject', '.js']){file}
|
96
|
-
allow(file).to receive(:path){path}
|
97
|
-
allow(file).to receive(:write)
|
98
|
-
allow(file).to receive(:close)
|
99
|
-
allow(file).to receive(:unlink)
|
100
|
-
allow(IO).to receive(:popen) {raise ArgumentError}
|
101
|
-
subject.transform
|
102
|
-
end
|
55
|
+
it "should create a temp file for the html" do
|
56
|
+
file = Object.new
|
57
|
+
expect(subject).to receive(:html_file){file}
|
58
|
+
allow(file).to receive(:path){html_path}
|
59
|
+
expect(file).to receive(:unlink)
|
60
|
+
subject.transform
|
61
|
+
end
|
103
62
|
|
63
|
+
it "should create a temp file for the js" do
|
64
|
+
file = Object.new
|
65
|
+
expect(subject).to receive(:js_file){file}
|
66
|
+
allow(file).to receive(:path){js_path}
|
67
|
+
expect(file).to receive(:unlink)
|
68
|
+
subject.transform
|
104
69
|
end
|
105
70
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
71
|
+
it "should call IO.popen with arguments" do
|
72
|
+
html_file = Object.new
|
73
|
+
expect(subject).to receive(:html_file){html_file}
|
74
|
+
allow(html_file).to receive(:path){html_path}
|
75
|
+
allow(html_file).to receive(:unlink)
|
76
|
+
|
77
|
+
js_file = Object.new
|
78
|
+
expect(subject).to receive(:js_file){js_file}
|
79
|
+
allow(js_file).to receive(:path){js_path}
|
80
|
+
allow(js_file).to receive(:unlink)
|
81
|
+
|
82
|
+
expect(IO).to receive(:popen).with([
|
83
|
+
GhostInThePost.phantomjs_path,
|
84
|
+
GhostInThePost::PhantomTransform::PHANTOMJS_SCRIPT,
|
85
|
+
html_path,
|
86
|
+
GhostInThePost.remove_js_tags.to_s,
|
87
|
+
js_path,
|
88
|
+
"1000",
|
89
|
+
"ghost_in_the_post:done",
|
90
|
+
])
|
91
|
+
|
92
|
+
subject.transform
|
93
|
+
end
|
128
94
|
|
95
|
+
it "should return the result of IO.popen with arguments" do
|
96
|
+
allow(IO).to receive(:popen) {"this is the end"}
|
97
|
+
expect(subject.transform).to eq("this is the end")
|
129
98
|
end
|
130
|
-
end
|
131
99
|
|
100
|
+
it "should unlink file even if there was an error" do
|
101
|
+
html_file = Object.new
|
102
|
+
expect(subject).to receive(:html_file){html_file}
|
103
|
+
allow(html_file).to receive(:path){html_path}
|
104
|
+
expect(html_file).to receive(:unlink)
|
105
|
+
|
106
|
+
js_file = Object.new
|
107
|
+
expect(subject).to receive(:js_file){js_file}
|
108
|
+
allow(js_file).to receive(:path){js_path}
|
109
|
+
expect(js_file).to receive(:unlink)
|
110
|
+
|
111
|
+
allow(IO).to receive(:popen) {raise ArgumentError}
|
112
|
+
|
113
|
+
expect{subject.transform}.to raise_error ArgumentError
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
132
117
|
end
|
133
118
|
end
|
134
119
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghost_in_the_post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Anema
|
@@ -118,14 +118,19 @@ files:
|
|
118
118
|
- spec/dummy/log/development.log
|
119
119
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/1hVihiFdBkDBsuCvA1I2vuFa9N6p-5zQ-qKvf4vz7jA.cache
|
120
120
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/23mzeUAO-pIzGJ1n84Dbg25udWeSiBcd6e_QsDihWQc.cache
|
121
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/4PgfVpd4CZQ0vAsVTl2KDb1z4f6GLl4mXIc3jSrahHM.cache
|
121
122
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/6544SZAu2zCeDrdro4h3izdKNXVvHzstwz12UxeiJoA.cache
|
123
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/6wWiAXBcdY6PLKOIhXQ6c8h9UtViuvdLcEO6wXK3mh0.cache
|
122
124
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/BMI0IB92xLhvUPcr_K0JuSk8zczmrEEbJCd3qwHauhQ.cache
|
123
125
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/GtqgDsC0JMsKfj0x5uQrbPcSS3QIPIzLKrq2fGJDBf0.cache
|
124
126
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/IFLV6zTaBXU1ccodbD3QJ4xUIOEix_Fbb7j8wsxrHw8.cache
|
127
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/J_D4gpddr1KPVysTvEE48iHsNzrL5Pbj8S5ZNt3PhA4.cache
|
125
128
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/Lc8lcXR-AibSZCIbx_imdfIOmD-zbZ_pwSNMs0o0Dos.cache
|
126
129
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/O9gjtBITAGlfzUwc2DT5N0GW2bo2b2yQ64gnQljLogM.cache
|
127
130
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/OQXwnC5z5STtd87Tr2dz1QBt4iZ8PoZTH8KBtBlUGnE.cache
|
128
131
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/OZ04c215C4Euu3scfhmxmte0o_tZOVWTqrv61cpy7H4.cache
|
132
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/UbKcvOd2xh3MJoKxz4l4RHMy5IupdsiDoSllZDvYCZA.cache
|
133
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/XuOqk2dVOcltjkihZ8J_u5Pbcm9Of5KFkjyihP6-5tc.cache
|
129
134
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/_Bn81xMZj4dS_W5s9uSDhtEdpRZtsc21rcKEYAPCsZY.cache
|
130
135
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/_Cw52w24AWZEbxLmduyWBMA6Y1OmJiEm1VNn7pY4rtk.cache
|
131
136
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/_HO5Nyj_TzTxVwa4OOf_0UJfBCmjgkv7NsRU29AD5Oo.cache
|
@@ -138,7 +143,10 @@ files:
|
|
138
143
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/oB1njyQ78MOMRf_5TvuYzHleeI8eke5-FDIIVl7qas0.cache
|
139
144
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache
|
140
145
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/qxbw0jMkxTNeM5T2QovOD9vTyvjHVjBN5tZdwBf519A.cache
|
146
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/xstXMnjOlL2Ynn6MaI9bxlRnhTPYdgCIeOWnWphFSlA.cache
|
141
147
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/y98HqYF9nxOk8t_j3BKv9Nc4LuSAEzhER7rCCvOM6xI.cache
|
148
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/zRSH1x7PsiRf9MSILPhc4GKDjRo4xaFNd41wHFCtJSo.cache
|
149
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/zUYxDxkUr_FKBi6fF7kellqyG52AoZbYItHMUq17DJo.cache
|
142
150
|
- spec/lib/ghost_in_the_post/automatic_spec.rb
|
143
151
|
- spec/lib/ghost_in_the_post/ghost_on_command_spec.rb
|
144
152
|
- spec/lib/ghost_in_the_post/mail_ghost_spec.rb
|
@@ -206,7 +214,9 @@ test_files:
|
|
206
214
|
- spec/dummy/log/development.log
|
207
215
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/1hVihiFdBkDBsuCvA1I2vuFa9N6p-5zQ-qKvf4vz7jA.cache
|
208
216
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/23mzeUAO-pIzGJ1n84Dbg25udWeSiBcd6e_QsDihWQc.cache
|
217
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/4PgfVpd4CZQ0vAsVTl2KDb1z4f6GLl4mXIc3jSrahHM.cache
|
209
218
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/6544SZAu2zCeDrdro4h3izdKNXVvHzstwz12UxeiJoA.cache
|
219
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/6wWiAXBcdY6PLKOIhXQ6c8h9UtViuvdLcEO6wXK3mh0.cache
|
210
220
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/_Bn81xMZj4dS_W5s9uSDhtEdpRZtsc21rcKEYAPCsZY.cache
|
211
221
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/_Cw52w24AWZEbxLmduyWBMA6Y1OmJiEm1VNn7pY4rtk.cache
|
212
222
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/_HO5Nyj_TzTxVwa4OOf_0UJfBCmjgkv7NsRU29AD5Oo.cache
|
@@ -217,6 +227,7 @@ test_files:
|
|
217
227
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/GtqgDsC0JMsKfj0x5uQrbPcSS3QIPIzLKrq2fGJDBf0.cache
|
218
228
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache
|
219
229
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/IFLV6zTaBXU1ccodbD3QJ4xUIOEix_Fbb7j8wsxrHw8.cache
|
230
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/J_D4gpddr1KPVysTvEE48iHsNzrL5Pbj8S5ZNt3PhA4.cache
|
220
231
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/Lc8lcXR-AibSZCIbx_imdfIOmD-zbZ_pwSNMs0o0Dos.cache
|
221
232
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/n6_6RjvPX2rCv5dytbSnnDrGwAj1ZcPfninuNUeP_iE.cache
|
222
233
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/nXo-w2o4zQBM_uSUnniuP53t5erBbSZPecMED9YnzQI.cache
|
@@ -226,7 +237,12 @@ test_files:
|
|
226
237
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/OZ04c215C4Euu3scfhmxmte0o_tZOVWTqrv61cpy7H4.cache
|
227
238
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache
|
228
239
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/qxbw0jMkxTNeM5T2QovOD9vTyvjHVjBN5tZdwBf519A.cache
|
240
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/UbKcvOd2xh3MJoKxz4l4RHMy5IupdsiDoSllZDvYCZA.cache
|
241
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/xstXMnjOlL2Ynn6MaI9bxlRnhTPYdgCIeOWnWphFSlA.cache
|
242
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/XuOqk2dVOcltjkihZ8J_u5Pbcm9Of5KFkjyihP6-5tc.cache
|
229
243
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/y98HqYF9nxOk8t_j3BKv9Nc4LuSAEzhER7rCCvOM6xI.cache
|
244
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/zRSH1x7PsiRf9MSILPhc4GKDjRo4xaFNd41wHFCtJSo.cache
|
245
|
+
- spec/dummy/tmp/cache/assets/sprockets/v3.0/zUYxDxkUr_FKBi6fF7kellqyG52AoZbYItHMUq17DJo.cache
|
230
246
|
- spec/lib/ghost_in_the_post/automatic_spec.rb
|
231
247
|
- spec/lib/ghost_in_the_post/ghost_on_command_spec.rb
|
232
248
|
- spec/lib/ghost_in_the_post/mail_ghost_spec.rb
|