critical-path-css-rails 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/critical-path-css-rails.gemspec +2 -1
- data/lib/critical_path_css/configuration.rb +4 -4
- data/lib/critical_path_css/css_fetcher.rb +1 -13
- data/lib/critical_path_css/rails/config_loader.rb +5 -8
- data/lib/critical_path_css/rails/version.rb +1 -1
- data/spec/fixtures/files/config/mutliple-css-paths.yml +14 -0
- data/spec/fixtures/files/config/no-paths-specified.yml +11 -0
- data/spec/fixtures/files/config/paths-and-routes-not-same-length.yml +15 -0
- data/spec/fixtures/files/config/paths-both-specified.yml +15 -0
- data/spec/fixtures/files/config/single-css-path.yml +11 -0
- data/spec/lib/critical_path_css/css_fetcher_spec.rb +26 -19
- data/spec/lib/critical_path_css/rails/config_loader_spec.rb +10 -103
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e92d5a4e4eb1085188e1dca05213f8504ce59f0
|
4
|
+
data.tar.gz: 0f1062681151f332c692501e502de54132639706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fad3f39638e25d2877acc81e8ebf9e6a486d80314426c7dc1a7020a4d12a23b1fc5461d83a4faa7bbf406e7804d06dbd28f1830a60e6c756d6e7088f0c4bf39
|
7
|
+
data.tar.gz: 37d31f7976f968c21eb433aaada848e2d64f35fa48d9ea27caa0b1e368922a7dd994966a4e0361a30d0f723fe8f1dda3006cc73e49d459bc969c36649f8dfbe7
|
@@ -9,12 +9,13 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.summary = 'Critical Path CSS for Rails!'
|
10
10
|
gem.description = 'Only load the CSS you need for the initial viewport in Rails!'
|
11
11
|
gem.license = 'MIT'
|
12
|
+
gem.homepage = 'https://rubygems.org/gems/critical-path-css-rails'
|
12
13
|
|
13
14
|
gem.files = `git ls-files`.split("\n")
|
14
15
|
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
15
16
|
gem.require_path = 'lib'
|
16
17
|
|
17
|
-
gem.add_development_dependency 'combustion', '~> 1.1.0'
|
18
|
+
gem.add_development_dependency 'combustion', '~> 1.1', '>= 1.1.0'
|
18
19
|
|
19
20
|
gem.extensions = ['ext/npm/extconf.rb']
|
20
21
|
end
|
@@ -9,10 +9,6 @@ module CriticalPathCss
|
|
9
9
|
@config['base_url']
|
10
10
|
end
|
11
11
|
|
12
|
-
def css_path
|
13
|
-
@config['css_path']
|
14
|
-
end
|
15
|
-
|
16
12
|
def css_paths
|
17
13
|
@config['css_paths']
|
18
14
|
end
|
@@ -28,5 +24,9 @@ module CriticalPathCss
|
|
28
24
|
def penthouse_options
|
29
25
|
@config['penthouse_options'] || {}
|
30
26
|
end
|
27
|
+
|
28
|
+
def path_for_route(route)
|
29
|
+
css_paths[routes.index(route)] || css_paths.first
|
30
|
+
end
|
31
31
|
end
|
32
32
|
end
|
@@ -16,7 +16,7 @@ module CriticalPathCss
|
|
16
16
|
def fetch_route(route)
|
17
17
|
options = {
|
18
18
|
'url' => @config.base_url + route,
|
19
|
-
'css' =>
|
19
|
+
'css' => @config.path_for_route(route),
|
20
20
|
'width' => 1300,
|
21
21
|
'height' => 900,
|
22
22
|
'timeout' => 30_000,
|
@@ -51,17 +51,5 @@ module CriticalPathCss
|
|
51
51
|
end
|
52
52
|
out
|
53
53
|
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def fetch_css_path_for_route(route)
|
58
|
-
index_for_route = @config.routes.index(route)
|
59
|
-
|
60
|
-
if index_for_route && @config.css_paths[index_for_route]
|
61
|
-
@config.css_paths[index_for_route]
|
62
|
-
else
|
63
|
-
@config.css_path
|
64
|
-
end
|
65
|
-
end
|
66
54
|
end
|
67
55
|
end
|
@@ -19,15 +19,12 @@ module CriticalPathCss
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def format_css_paths
|
22
|
-
if config['css_path']
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
config['css_path'] = ''
|
27
|
-
config['css_paths'] = config['css_paths'].collect { |path| format_path(path) }
|
22
|
+
config['css_paths'] = [config['css_path']] if config['css_path']
|
23
|
+
|
24
|
+
if config['css_paths']
|
25
|
+
config['css_paths'].map! { |path| format_path(path) }
|
28
26
|
else
|
29
|
-
config['
|
30
|
-
config['css_paths'] = []
|
27
|
+
config['css_paths'] = [ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '')]
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
@@ -1,27 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe 'CssFetcher' do
|
4
|
-
|
4
|
+
subject { CriticalPathCss::CssFetcher.new(config) }
|
5
|
+
|
6
|
+
let(:base_url) { 'http://0.0.0.0:9292' }
|
5
7
|
let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] }
|
6
|
-
let(:routes)
|
8
|
+
let(:routes) { ['/', '/new_route'] }
|
7
9
|
let(:config) do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
CriticalPathCss::Configuration.new(
|
11
|
+
OpenStruct.new(
|
12
|
+
base_url: base_url,
|
13
|
+
css_paths: css_paths,
|
14
|
+
penthouse_options: {},
|
15
|
+
routes: routes
|
16
|
+
)
|
14
17
|
)
|
15
18
|
end
|
16
19
|
|
17
20
|
describe '#fetch_route' do
|
18
21
|
context 'when a single css_path is configured' do
|
19
|
-
let(:
|
20
|
-
let(:css_paths) { [] }
|
22
|
+
let(:css_paths) { ['/test.css'] }
|
21
23
|
|
22
24
|
it 'generates css for the single route' do
|
23
25
|
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
24
26
|
options = JSON.parse(arg3)
|
27
|
+
|
25
28
|
expect(options['css']).to eq '/test.css'
|
26
29
|
end.once.and_return(response)
|
27
30
|
|
@@ -32,44 +35,48 @@ RSpec.describe 'CssFetcher' do
|
|
32
35
|
|
33
36
|
describe '#fetch' do
|
34
37
|
context 'when a single css_path is configured' do
|
35
|
-
let(:
|
36
|
-
let(:css_paths) { [] }
|
38
|
+
let(:css_paths) { ['/test.css'] }
|
37
39
|
|
38
40
|
it 'generates css for each route from the same file' do
|
39
41
|
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
40
42
|
options = JSON.parse(arg3)
|
43
|
+
|
41
44
|
expect(options['css']).to eq '/test.css'
|
42
45
|
end.twice.and_return(response)
|
46
|
+
|
43
47
|
subject.fetch
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
51
|
context 'when multiple css_paths are configured' do
|
48
|
-
let(:css_path) { '' }
|
49
52
|
let(:css_paths) { ['/test.css', '/test2.css'] }
|
50
53
|
|
51
54
|
it 'generates css for each route from the respective file' do
|
52
55
|
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
53
56
|
options = JSON.parse(arg3)
|
54
|
-
|
55
|
-
|
57
|
+
|
58
|
+
css_paths.each_with_index do |path, index|
|
59
|
+
expect(options['css']).to eq path if options['url'] == "#{base_url}/#{routes[index]}"
|
60
|
+
end
|
56
61
|
end.twice.and_return(response)
|
62
|
+
|
57
63
|
subject.fetch
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
61
67
|
context 'when same css file applies to multiple routes' do
|
62
|
-
let(:css_path) { '' }
|
63
68
|
let(:css_paths) { ['/test.css', '/test2.css', '/test.css'] }
|
64
69
|
let(:routes) { ['/', '/new_route', '/newer_route'] }
|
65
70
|
|
66
71
|
it 'generates css for each route from the respective file' do
|
67
72
|
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
68
73
|
options = JSON.parse(arg3)
|
69
|
-
|
70
|
-
|
71
|
-
|
74
|
+
|
75
|
+
css_paths.each_with_index do |path, index|
|
76
|
+
expect(options['css']).to eq path if options['url'] == "#{base_url}/#{routes[index]}"
|
77
|
+
end
|
72
78
|
end.thrice.and_return(response)
|
79
|
+
|
73
80
|
subject.fetch
|
74
81
|
end
|
75
82
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe 'ConfigLoader' do
|
4
|
-
|
4
|
+
subject { CriticalPathCss::Rails::ConfigLoader.new }
|
5
5
|
|
6
6
|
describe '#load' do
|
7
7
|
before do
|
@@ -9,54 +9,15 @@ RSpec.describe 'ConfigLoader' do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'when single css_path is specified' do
|
12
|
-
let(:config_file) {
|
13
|
-
<<~CONFIG
|
14
|
-
defaults: &defaults
|
15
|
-
base_url: http://0.0.0.0:9292
|
16
|
-
css_path: /test.css
|
17
|
-
routes:
|
18
|
-
- /
|
12
|
+
let(:config_file) { file_fixture('config/single-css-path.yml').read }
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
test:
|
24
|
-
<<: *defaults
|
25
|
-
CONFIG
|
26
|
-
}
|
27
|
-
|
28
|
-
it 'sets css_path with the path' do
|
29
|
-
expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'leaves css_paths empty' do
|
33
|
-
expect(subject.config['css_paths']).to eq []
|
14
|
+
it 'sets css_paths with the lone path' do
|
15
|
+
expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css']
|
34
16
|
end
|
35
17
|
end
|
36
18
|
|
37
19
|
context 'when multiple css_paths are specified' do
|
38
|
-
let(:config_file) {
|
39
|
-
<<~CONFIG
|
40
|
-
defaults: &defaults
|
41
|
-
base_url: http://0.0.0.0:9292
|
42
|
-
css_paths:
|
43
|
-
- /test.css
|
44
|
-
- /test2.css
|
45
|
-
routes:
|
46
|
-
- /
|
47
|
-
- /new_route
|
48
|
-
|
49
|
-
development:
|
50
|
-
<<: *defaults
|
51
|
-
|
52
|
-
test:
|
53
|
-
<<: *defaults
|
54
|
-
CONFIG
|
55
|
-
}
|
56
|
-
|
57
|
-
it 'sets css_path to empty string' do
|
58
|
-
expect(subject.config['css_path']).to eq ''
|
59
|
-
end
|
20
|
+
let(:config_file) { file_fixture('config/mutliple-css-paths.yml').read }
|
60
21
|
|
61
22
|
it 'leaves css_paths to an array of paths' do
|
62
23
|
expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css']
|
@@ -64,51 +25,15 @@ RSpec.describe 'ConfigLoader' do
|
|
64
25
|
end
|
65
26
|
|
66
27
|
context 'when no paths are specified' do
|
67
|
-
let(:config_file) {
|
68
|
-
<<~CONFIG
|
69
|
-
defaults: &defaults
|
70
|
-
base_url: http://0.0.0.0:9292
|
71
|
-
manifest_name: application
|
72
|
-
routes:
|
73
|
-
- /
|
28
|
+
let(:config_file) { file_fixture('config/no-paths-specified.yml').read }
|
74
29
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
test:
|
79
|
-
<<: *defaults
|
80
|
-
CONFIG
|
81
|
-
}
|
82
|
-
|
83
|
-
it 'sets css_path with the path' do
|
84
|
-
expect(subject.config['css_path']).to eq '/stylesheets/application.css'
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'leaves css_paths empty' do
|
88
|
-
expect(subject.config['css_paths']).to eq []
|
30
|
+
it 'sets css_paths with the lone manifest path' do
|
31
|
+
expect(subject.config['css_paths']).to eq ['/stylesheets/application.css']
|
89
32
|
end
|
90
33
|
end
|
91
34
|
|
92
35
|
context 'when single css_path and multiple css_paths are both specified' do
|
93
|
-
let(:config_file) {
|
94
|
-
<<~CONFIG
|
95
|
-
defaults: &defaults
|
96
|
-
base_url: http://0.0.0.0:9292
|
97
|
-
css_path: /test.css
|
98
|
-
css_paths:
|
99
|
-
- /test.css
|
100
|
-
- /test2.css
|
101
|
-
routes:
|
102
|
-
- /
|
103
|
-
- /new_route
|
104
|
-
|
105
|
-
development:
|
106
|
-
<<: *defaults
|
107
|
-
|
108
|
-
test:
|
109
|
-
<<: *defaults
|
110
|
-
CONFIG
|
111
|
-
}
|
36
|
+
let(:config_file) { file_fixture('config/paths-both-specified.yml').read }
|
112
37
|
|
113
38
|
it 'raises an error' do
|
114
39
|
expect { subject }.to raise_error LoadError, 'Cannot specify both css_path and css_paths'
|
@@ -116,25 +41,7 @@ RSpec.describe 'ConfigLoader' do
|
|
116
41
|
end
|
117
42
|
|
118
43
|
context 'when css_paths and routes are not the same length' do
|
119
|
-
let(:config_file) {
|
120
|
-
<<~CONFIG
|
121
|
-
defaults: &defaults
|
122
|
-
base_url: http://0.0.0.0:9292
|
123
|
-
css_paths:
|
124
|
-
- /test.css
|
125
|
-
- /test2.css
|
126
|
-
routes:
|
127
|
-
- /
|
128
|
-
- /new_route
|
129
|
-
- /newer_route
|
130
|
-
|
131
|
-
development:
|
132
|
-
<<: *defaults
|
133
|
-
|
134
|
-
test:
|
135
|
-
<<: *defaults
|
136
|
-
CONFIG
|
137
|
-
}
|
44
|
+
let(:config_file) { file_fixture('config/paths-and-routes-not-same-length.yml').read }
|
138
45
|
|
139
46
|
it 'raises an error' do
|
140
47
|
expect { subject }.to raise_error LoadError, 'Must specify css_paths for each route'
|
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: critical-path-css-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Misshore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: combustion
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 1.1.0
|
20
23
|
type: :development
|
@@ -22,6 +25,9 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 1.1.0
|
27
33
|
description: Only load the CSS you need for the initial viewport in Rails!
|
@@ -62,6 +68,11 @@ files:
|
|
62
68
|
- package-lock.json
|
63
69
|
- package.json
|
64
70
|
- spec/features/generate_and_fetch_critical_css_spec.rb
|
71
|
+
- spec/fixtures/files/config/mutliple-css-paths.yml
|
72
|
+
- spec/fixtures/files/config/no-paths-specified.yml
|
73
|
+
- spec/fixtures/files/config/paths-and-routes-not-same-length.yml
|
74
|
+
- spec/fixtures/files/config/paths-both-specified.yml
|
75
|
+
- spec/fixtures/files/config/single-css-path.yml
|
65
76
|
- spec/internal/app/controllers/root_controller.rb
|
66
77
|
- spec/internal/app/views/layouts/application.html.erb
|
67
78
|
- spec/internal/app/views/root/index.html.erb
|
@@ -75,7 +86,7 @@ files:
|
|
75
86
|
- spec/lib/critical_path_css/css_fetcher_spec.rb
|
76
87
|
- spec/lib/critical_path_css/rails/config_loader_spec.rb
|
77
88
|
- spec/spec_helper.rb
|
78
|
-
homepage:
|
89
|
+
homepage: https://rubygems.org/gems/critical-path-css-rails
|
79
90
|
licenses:
|
80
91
|
- MIT
|
81
92
|
metadata: {}
|