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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4854e245fe24316010a61d16bb6d8708be6bb54d
4
- data.tar.gz: f57f1f1b55eb911f65a1d5691705bc38b12ee7af
3
+ metadata.gz: 5501b582bfdb4c2800ebd28be0b3560c2d4f5ca1
4
+ data.tar.gz: 061c884ae5fc118175284fa4fd2db7704f7288c1
5
5
  SHA512:
6
- metadata.gz: 7b211875500f8abf390e22245b4d893b83c8bf03d30e5074bd73f32c9cdf8fedf21530a9235c8ce9a765d3e7d94fa4470f1afda9b9635a44fc9b22840892a093
7
- data.tar.gz: 39dec3a48fa5eaaba2c385093a6973e795c5a3052d2405eddfda6159229410340008434790d8612d7a286acbe7c74b1cf9aefd61fd97e934b607754fc3583da4
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
- @inliner.remove_all_script if GhostInThePost.remove_js_tags
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
 
@@ -1,3 +1,3 @@
1
1
  module GhostInThePost
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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
- @@phantomjs_path = new_config[:phantomjs_path]
31
- @@includes = Array(new_config[:includes])
32
- @@remove_js_tags = new_config[:remove_js_tags].nil? ? true : new_config[:remove_js_tags]
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)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- ghost_in_the_post (0.0.13)
4
+ ghost_in_the_post (0.0.14)
5
5
  nokogiri
6
6
  rails (~> 4.2.3)
7
7
 
@@ -659,3 +659,6 @@ Mailer#normal: processed outbound mail in 20.2ms
659
659
  Rendered mailer/normal.html.erb (240.5ms)
660
660
 
661
661
  Mailer#normal: processed outbound mail in 518.2ms
662
+ Rendered mailer/timeout.html.erb (224.5ms)
663
+
664
+ Mailer#timeout: processed outbound mail in 474.3ms
@@ -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.14
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-05 00:00:00.000000000 Z
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails