ghost_in_the_post 0.0.14 → 0.1.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 +4 -4
- data/lib/ghost_in_the_post/js_inline.rb +6 -1
- data/lib/ghost_in_the_post/phantom_transform.rb +5 -1
- data/lib/ghost_in_the_post/version.rb +1 -1
- data/lib/ghost_in_the_post.rb +7 -8
- data/spec/dummy/Gemfile.lock +1 -1
- data/spec/dummy/log/development.log +3 -0
- data/spec/lib/ghost_in_the_post/js_inline_spec.rb +9 -0
- data/spec/lib/ghost_in_the_post/phantom_transform_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5501b582bfdb4c2800ebd28be0b3560c2d4f5ca1
|
4
|
+
data.tar.gz: 061c884ae5fc118175284fa4fd2db7704f7288c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac27f06ac531d4e71b7ade96b4bf7e6598aa5dfc64cccec3af8d40d4ce112ca934757cab2cc261ca11b74c6b747a63cc399b2bfc23a2663690f30c1889f3d4c5
|
7
|
+
data.tar.gz: 1cb9c7bda38950e0533838743b85d9dec865c33e64e8feaca4b213f7a76138545d7de01757ddd3402ccc07bb2817b81723bba3ffb524ce65f09d80027abe9aaf
|
@@ -5,6 +5,7 @@ module GhostInThePost
|
|
5
5
|
class AssetNotFoundError < StandardError; end
|
6
6
|
|
7
7
|
class JsInline
|
8
|
+
SCRIPT_ID = "ghost_in_the_post_script_container"
|
8
9
|
|
9
10
|
def initialize(html, included_scripts=[])
|
10
11
|
self.html = html
|
@@ -12,13 +13,17 @@ module GhostInThePost
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def inline
|
15
|
-
@dom.at_xpath('html/body').add_child("<script>#{generate_flat_js}</script>")
|
16
|
+
@dom.at_xpath('html/body').add_child("<script id='#{SCRIPT_ID}'>#{generate_flat_js}</script>")
|
16
17
|
end
|
17
18
|
|
18
19
|
def remove_all_script
|
19
20
|
@dom.css('script').map(&:remove)
|
20
21
|
end
|
21
22
|
|
23
|
+
def remove_inlined
|
24
|
+
@dom.css("##{SCRIPT_ID}").map(&:remove)
|
25
|
+
end
|
26
|
+
|
22
27
|
def html=(html)
|
23
28
|
@dom = Nokogiri::HTML.parse(html, nil, Encoding::UTF_8.to_s)
|
24
29
|
end
|
@@ -24,7 +24,11 @@ module GhostInThePost
|
|
24
24
|
htmlfile.unlink
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
if GhostInThePost.remove_js_tags
|
28
|
+
@inliner.remove_all_script
|
29
|
+
else
|
30
|
+
@inliner.remove_inlined
|
31
|
+
end
|
28
32
|
@inliner.html
|
29
33
|
end
|
30
34
|
|
data/lib/ghost_in_the_post.rb
CHANGED
@@ -27,14 +27,9 @@ module GhostInThePost
|
|
27
27
|
|
28
28
|
def self.config=(new_config={})
|
29
29
|
self.complain_about_unknown_keys(new_config.keys)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@@raise_js_errors = new_config[:raise_js_errors].nil? ? true : new_config[:raise_js_errors]
|
34
|
-
@@raise_asset_errors = new_config[:raise_asset_errors].nil? ? true : new_config[:raise_asset_errors]
|
35
|
-
@@timeout = new_config[:timeout] || DEFAULT_TIMEOUT
|
36
|
-
@@wait_event = new_config[:wait_event] || DEFAULT_WAIT_EVENT
|
37
|
-
@@debug = new_config[:debug].nil? ? false : new_config[:debug]
|
30
|
+
new_config.each do |key, value|
|
31
|
+
self.send("#{key}=", value)
|
32
|
+
end
|
38
33
|
raise ArgumentError, "GhostInThePost.config.phantomjs_path is not set" if self.phantomjs_path.nil?
|
39
34
|
end
|
40
35
|
|
@@ -42,6 +37,10 @@ module GhostInThePost
|
|
42
37
|
@@phantomjs_path or raise ArgumentError, "GhostInThePost.config.phantomjs_path is not set"
|
43
38
|
end
|
44
39
|
|
40
|
+
def self.includes= to_include
|
41
|
+
@@includes = Array(to_include)
|
42
|
+
end
|
43
|
+
|
45
44
|
private
|
46
45
|
|
47
46
|
def self.complain_about_unknown_keys(keys)
|
data/spec/dummy/Gemfile.lock
CHANGED
@@ -33,6 +33,7 @@ module GhostInThePost
|
|
33
33
|
it "should inline js" do
|
34
34
|
subject.inline
|
35
35
|
expect(subject.html).to include(js)
|
36
|
+
expect(subject.html).to include("<script id=\"#{JsInline::SCRIPT_ID}\"")
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -43,6 +44,14 @@ module GhostInThePost
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
describe "#remove_inlined" do
|
48
|
+
it "should remove just the inlined js" do
|
49
|
+
subject.remove_inlined
|
50
|
+
expect(subject.html).to include("<script")
|
51
|
+
expect(subject.html).not_to include("<script id=\"#{JsInline::SCRIPT_ID}\"")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
46
55
|
describe "#html=" do
|
47
56
|
it "should parse the html" do
|
48
57
|
subject.html #initialize first so that it only receives once
|
@@ -74,6 +74,13 @@ module GhostInThePost
|
|
74
74
|
subject.transform
|
75
75
|
end
|
76
76
|
|
77
|
+
it "should remove just inlined js if config not set" do
|
78
|
+
GhostInThePost.config = {phantomjs_path: "this/is/path", remove_js_tags: false}
|
79
|
+
allow(IO).to receive(:popen).and_return ""
|
80
|
+
expect(@inliner).to receive(:remove_inlined)
|
81
|
+
subject.transform
|
82
|
+
end
|
83
|
+
|
77
84
|
it "should create a temp file for the html" do
|
78
85
|
allow(IO).to receive(:popen).and_return ""
|
79
86
|
file = Object.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Anema
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|