ghost_in_the_post 0.1.3 → 0.1.4

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: fe35d98b561a58b1bdde7d2d0b737ed63596af75
4
- data.tar.gz: 8d413849005f47c94d89b730aed26ff88ab68577
3
+ metadata.gz: 9882b7c81a059e680ca7aaae7e0b8bd2bf23863f
4
+ data.tar.gz: 7e7384c6fb80fee05d43839605778697b9063889
5
5
  SHA512:
6
- metadata.gz: 873e278bb471b1fe87495da70f9cbd7a9fa6a4f7c4d84aa770ea8458c90376a4386640f5cedfa0c9ce004738473536c57c553811771970d6d32e39c28edf47e7
7
- data.tar.gz: eab19b013fb94fae08245ea262f128d004eb8f834f42414544aad051b44c8d242ad6d621eef70ff803f49bece7cdfc5d38d08e0b8860c2af8d2a6c50f5bdbabd
6
+ metadata.gz: 6b01c14bc2d83a7c82dffdcff158b0d2e6b6199bc02dead5343c40521898dd71a9058be94df6f5b5aad1ccc00827b5a576c0adc160b03c0c45a8e721dacf051c
7
+ data.tar.gz: ec44cfc2541d9c8cc631cc3622827c394a22a6ac2433ce7df430389cd2ebfb26fb748d897e7b50b011c1d1ab9ee7b83c82543f81d8456a27d6cd7099c8586730
@@ -30,9 +30,10 @@ module GhostInThePost
30
30
  new_config.each do |key, value|
31
31
  self.send("#{key}=", value)
32
32
  end
33
- raise ArgumentError, "GhostInThePost.config.phantomjs_path is not set" if self.phantomjs_path.nil?
33
+ raise ArgumentError, "phantomjs not found at path `#{@@phantomjs_path}` provided to GhostInThePost" unless File.exist?(phantomjs_path)
34
34
  end
35
35
 
36
+
36
37
  def self.phantomjs_path
37
38
  @@phantomjs_path or raise ArgumentError, "GhostInThePost.config.phantomjs_path is not set"
38
39
  end
@@ -47,7 +47,10 @@ module GhostInThePost
47
47
  if GhostInThePost.raise_asset_errors and asset.nil?
48
48
  raise AssetNotFoundError.new("cannot find asset #{normalize_asset_name(script)}")
49
49
  end
50
- asset.to_s unless asset.nil?
50
+ unless asset.nil?
51
+ GhostInThePost::JSLoaders::CacheLoader.store(script, asset.to_s)
52
+ asset.to_s
53
+ end
51
54
  end.compact.join("\n")
52
55
  end
53
56
 
@@ -16,11 +16,20 @@ module GhostInThePost
16
16
  ::Rails.application.respond_to?(:assets) &&
17
17
  ::Rails.application.assets
18
18
  end
19
+
20
+ DIGEST_PATTERN = /
21
+ - # Digest comes after a dash
22
+ (?:
23
+ [a-z0-9]{32} | # Old style is 32 character hash
24
+ [a-z0-9]{64} # New style is 64 characters
25
+ )
26
+ \. # Dot for the file extension
27
+ /x.freeze
19
28
 
20
29
  def file_name(url)
21
30
  URI(url).path
22
31
  .sub("#{::Rails.configuration.assets.prefix}/", '')
23
- .sub(/-(\h{32}|\h{64})\.js$/, '.js')
32
+ .gsub(DIGEST_PATTERN, '.')
24
33
  end
25
34
  end
26
35
  end
@@ -4,7 +4,6 @@ module GhostInThePost
4
4
 
5
5
  class PhantomTransform
6
6
  PHANTOMJS_SCRIPT = File.expand_path('../phantom/staticize.js', __FILE__)
7
- TAG = "[GHOSTINTHEPOST-STATICIZE]"
8
7
  ERROR_TAG = "[GHOSTINTHEPOST-STATICIZE-ERROR]"
9
8
 
10
9
  def initialize(html, timeout=nil, wait_event=nil, included_scripts=nil)
@@ -18,7 +17,6 @@ module GhostInThePost
18
17
  begin
19
18
  htmlfile = html_file(@inliner.html)
20
19
  @inliner.html = checkError(IO.popen(command(htmlfile)){|io| io.read})
21
- p "#{TAG} #{@inliner.html}" if GhostInThePost.debug
22
20
  ensure
23
21
  if GhostInThePost.debug and @has_error
24
22
  p "Generated html can be found at #{htmlfile.path}"
@@ -1,3 +1,3 @@
1
1
  module GhostInThePost
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -10,6 +10,10 @@ module GhostInThePost
10
10
  let(:included_scripts){["application.js"]}
11
11
  subject {JsInline.new(html, included_scripts)}
12
12
 
13
+ before :each do
14
+ allow(File).to receive(:exist?){true}
15
+ end
16
+
13
17
  describe "#initialize" do
14
18
  it "should assign html" do
15
19
  expect(Nokogiri::HTML).to receive(:parse)
@@ -27,7 +31,7 @@ module GhostInThePost
27
31
 
28
32
  describe "#inline" do
29
33
  before :each do
30
- allow(subject).to receive(:find_asset_in_pipeline).with("application.js").and_return(js)
34
+ allow(subject).to receive(:find_js).with("application.js").and_return(js)
31
35
  end
32
36
 
33
37
  it "should inline js" do
@@ -35,6 +39,11 @@ module GhostInThePost
35
39
  expect(subject.html).to include(js)
36
40
  expect(subject.html).to include("<script id=\"#{JsInline::SCRIPT_ID}\"")
37
41
  end
42
+
43
+ it "should cache the script" do
44
+ expect(GhostInThePost::JSLoaders::CacheLoader).to receive(:store).with("application.js", js)
45
+ subject.inline
46
+ end
38
47
  end
39
48
 
40
49
  describe "#remove_all_script" do
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe GhostInThePost::JSLoaders::AssetPipelineLoader do
4
+ before do
5
+ assets = double(prefix: '/assets')
6
+ config = double(assets: assets)
7
+ allow(Rails).to receive(:configuration).and_return(config)
8
+ end
9
+
10
+ describe "#file_name" do
11
+ subject do
12
+ GhostInThePost::JSLoaders::AssetPipelineLoader.file_name(asset)
13
+ end
14
+
15
+ context "when asset file path contains prefix" do
16
+ let(:asset) { '/assets/application.css' }
17
+ it { is_expected.to eq('application.css') }
18
+ end
19
+
20
+ context "when asset file path contains 32 chars fingerprint" do
21
+ let(:asset) { 'application-6776f581a4329e299531e1d52aa59832.css' }
22
+ it { is_expected.to eq('application.css') }
23
+ end
24
+
25
+ context "when asset file path contains 64 chars fingerprint" do
26
+ let(:asset) { 'application-02275ccb3fd0c11615bbfb11c99ea123ca2287e75045fe7b72cefafb880dad2b.css' }
27
+ it { is_expected.to eq('application.css') }
28
+ end
29
+
30
+ context "when asset file page contains numbers, but not a fingerprint" do
31
+ let(:asset) { 'test/20130708152545-foo-bar.css' }
32
+ it { is_expected.to eq("test/20130708152545-foo-bar.css") }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe GhostInThePost::JSLoaders::NetworkLoader do
4
+ describe '#uri_for_url' do
5
+ subject { described_class.uri_for_url(url) }
6
+ let(:asset_host) { nil }
7
+
8
+ before do
9
+ action_controller = double(asset_host: asset_host)
10
+ config = double(action_controller: action_controller)
11
+ allow(Rails).to receive(:configuration).and_return(config)
12
+ end
13
+
14
+ context 'with a valid URL' do
15
+ let(:url) { 'http://example.com/test.css' }
16
+ it { is_expected.to eq(URI(url)) }
17
+ end
18
+
19
+ context 'with a protocol relative URL' do
20
+ let(:url) { '//example.com/test.css' }
21
+ it { is_expected.to eq(URI("http://#{url}")) }
22
+ end
23
+
24
+ context 'with a file path' do
25
+ let(:url) { '/assets/foo.css' }
26
+
27
+ context 'and a domain as asset host' do
28
+ let(:asset_host) { 'example.com' }
29
+ it { is_expected.to eq(URI("http://example.com#{url}")) }
30
+ end
31
+
32
+ context 'and a URL as asset host' do
33
+ let(:asset_host) { 'https://example.com' }
34
+ it { is_expected.to eq(URI("https://example.com/assets/foo.css")) }
35
+ end
36
+
37
+ context 'and a protocol relative URL as asset host' do
38
+ let(:asset_host) { '//example.com' }
39
+ it { is_expected.to eq(URI("http://example.com/assets/foo.css")) }
40
+ end
41
+
42
+ context 'and a proc as asset host' do
43
+ let(:asset_host) { ->{ 'example.com' } }
44
+ it { is_expected.to eq(URI("http://example.com/assets/foo.css")) }
45
+ end
46
+
47
+ context 'without an asset host' do
48
+ let(:asset_host) { nil }
49
+ it { is_expected.not_to be }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -9,6 +9,7 @@ module GhostInThePost
9
9
  subject {PhantomTransform.new(html, nil, nil,included_scripts)}
10
10
 
11
11
  before :each do
12
+ allow(File).to receive(:exist?).with("this/is/path"){true}
12
13
  GhostInThePost.config = {phantomjs_path: "this/is/path"}
13
14
  allow_message_expectations_on_nil
14
15
  end
@@ -5,6 +5,9 @@ describe GhostInThePost do
5
5
  before :each do
6
6
  #reload so that variables are set to initials values
7
7
  quiet_load 'ghost_in_the_post.rb'
8
+ allow(File).to receive(:exist?){|path|
9
+ path == "test_path"
10
+ }
8
11
  end
9
12
 
10
13
  describe "#create=" do
@@ -22,6 +25,11 @@ describe GhostInThePost do
22
25
  GhostInThePost.config = {}
23
26
  end.to raise_error(ArgumentError)
24
27
  end
28
+ it "should raise ArgumentError if path was set for phantom but it is not at that path" do
29
+ expect do
30
+ GhostInThePost.config = {phantomjs_path: "nope"}
31
+ end.to raise_error(ArgumentError)
32
+ end
25
33
  it "should set includes" do
26
34
  GhostInThePost.config = {phantomjs_path: "test_path", includes: ["test"]}
27
35
  expect(GhostInThePost.includes).to eq(["test"])
metadata CHANGED
@@ -1,86 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_in_the_post
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Anema
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: rails
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: 4.2.3
19
- name: rails
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.3
27
27
  - !ruby/object:Gem::Dependency
28
+ name: nokogiri
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
- name: nokogiri
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: bundler
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '1.6'
47
- name: bundler
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: rspec
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
61
  version: '3.0'
61
- name: rspec
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: rspec-rails
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Using phantomjs to pre-run javascript in emails. This is best if you have content that uses mustache templates that you would like to reuse in your emails.
83
+ description: Using phantomjs to pre-run javascript in emails. This is best if you
84
+ have content that uses mustache templates that you would like to reuse in your emails.
84
85
  email:
85
86
  - timanema@gmail.com
86
87
  executables: []
@@ -138,6 +139,8 @@ files:
138
139
  - spec/lib/ghost_in_the_post/automatic_spec.rb
139
140
  - spec/lib/ghost_in_the_post/ghost_on_command_spec.rb
140
141
  - spec/lib/ghost_in_the_post/js_inline_spec.rb
142
+ - spec/lib/ghost_in_the_post/js_loaders/asset_pipeline_loader_spec.rb
143
+ - spec/lib/ghost_in_the_post/js_loaders/network_loader_spec.rb
141
144
  - spec/lib/ghost_in_the_post/mail_ghost_spec.rb
142
145
  - spec/lib/ghost_in_the_post/mailer_spec.rb
143
146
  - spec/lib/ghost_in_the_post/phantom_transform_spec.rb
@@ -149,7 +152,7 @@ homepage: https://github.com/tanema/ghost_in_the_post
149
152
  licenses:
150
153
  - MIT
151
154
  metadata: {}
152
- post_install_message:
155
+ post_install_message:
153
156
  rdoc_options: []
154
157
  require_paths:
155
158
  - lib
@@ -164,16 +167,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  - !ruby/object:Gem::Version
165
168
  version: '0'
166
169
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.4.8
169
- signing_key:
170
+ rubyforge_project:
171
+ rubygems_version: 2.2.2
172
+ signing_key:
170
173
  specification_version: 4
171
174
  summary: Using phantomjs to pre-run javascript in emails
172
175
  test_files:
173
- - spec/spec_helper.rb
174
- - spec/dummy/config.ru
175
- - spec/dummy/Gemfile
176
- - spec/dummy/Gemfile.lock
177
176
  - spec/dummy/app/assets/javascripts/application.js
178
177
  - spec/dummy/app/assets/javascripts/test.js
179
178
  - spec/dummy/app/mailers/mailer.rb
@@ -188,8 +187,6 @@ test_files:
188
187
  - spec/dummy/config/application.rb
189
188
  - spec/dummy/config/boot.rb
190
189
  - spec/dummy/config/environment.rb
191
- - spec/dummy/config/routes.rb
192
- - spec/dummy/config/secrets.yml
193
190
  - spec/dummy/config/environments/development.rb
194
191
  - spec/dummy/config/initializers/assets.rb
195
192
  - spec/dummy/config/initializers/backtrace_silencers.rb
@@ -200,12 +197,20 @@ test_files:
200
197
  - spec/dummy/config/initializers/mime_types.rb
201
198
  - spec/dummy/config/initializers/session_store.rb
202
199
  - spec/dummy/config/initializers/wrap_parameters.rb
203
- - spec/lib/ghost_in_the_post_spec.rb
200
+ - spec/dummy/config/routes.rb
201
+ - spec/dummy/config/secrets.yml
202
+ - spec/dummy/config.ru
203
+ - spec/dummy/Gemfile
204
+ - spec/dummy/Gemfile.lock
204
205
  - spec/lib/ghost_in_the_post/automatic_spec.rb
205
206
  - spec/lib/ghost_in_the_post/ghost_on_command_spec.rb
206
207
  - spec/lib/ghost_in_the_post/js_inline_spec.rb
208
+ - spec/lib/ghost_in_the_post/js_loaders/asset_pipeline_loader_spec.rb
209
+ - spec/lib/ghost_in_the_post/js_loaders/network_loader_spec.rb
207
210
  - spec/lib/ghost_in_the_post/mail_ghost_spec.rb
208
211
  - spec/lib/ghost_in_the_post/mailer_spec.rb
209
212
  - spec/lib/ghost_in_the_post/phantom_transform_spec.rb
213
+ - spec/lib/ghost_in_the_post_spec.rb
214
+ - spec/spec_helper.rb
210
215
  - spec/support/mailer_support.rb
211
216
  - spec/support/quiet_load.rb