File tree 6 files changed +24
-54
lines changed
spec/lib/critical_path_css
6 files changed +24
-54
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,6 @@ def base_url
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 @@ def routes
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
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def fetch
16
16
def fetch_route ( route )
17
17
options = {
18
18
'url' => @config . base_url + route ,
19
- 'css' => fetch_css_path_for_route ( route ) ,
19
+ 'css' => @config . path_for_route ( route ) ,
20
20
'width' => 1300 ,
21
21
'height' => 900 ,
22
22
'timeout' => 30_000 ,
@@ -51,17 +51,5 @@ def fetch_route(route)
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
Original file line number Diff line number Diff line change @@ -19,15 +19,12 @@ def configuration_file_path
19
19
end
20
20
21
21
def format_css_paths
22
- if config [ 'css_path' ]
23
- config [ 'css_path' ] = format_path ( config [ 'css_path' ] )
24
- config [ 'css_paths' ] = [ ]
25
- elsif config [ 'css_paths' ]
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 [ 'css_path' ] = ActionController ::Base . helpers . stylesheet_path ( config [ 'manifest_name' ] , host : '' )
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
Original file line number Diff line number Diff line change 1
1
module CriticalPathCSS
2
2
module Rails
3
- VERSION = '3.0.2 ' . freeze
3
+ VERSION = '3.0.3 ' . freeze
4
4
end
5
5
end
Original file line number Diff line number Diff line change 7
7
let ( :response ) { [ 'foo' , '' , OpenStruct . new ( exitstatus : 0 ) ] }
8
8
let ( :routes ) { [ '/' , '/new_route' ] }
9
9
let ( :config ) do
10
- OpenStruct . new (
11
- base_url : base_url ,
12
- css_path : css_path ,
13
- css_paths : css_paths ,
14
- penthouse_options : { } ,
15
- routes : routes
10
+ CriticalPathCss ::Configuration . new (
11
+ OpenStruct . new (
12
+ base_url : base_url ,
13
+ css_paths : css_paths ,
14
+ penthouse_options : { } ,
15
+ routes : routes
16
+ )
16
17
)
17
18
end
18
19
19
20
describe '#fetch_route' do
20
21
context 'when a single css_path is configured' do
21
- let ( :css_path ) { '/test.css' }
22
- let ( :css_paths ) { [ ] }
22
+ let ( :css_paths ) { [ '/test.css' ] }
23
23
24
24
it 'generates css for the single route' do
25
25
expect ( Open3 ) . to receive ( :capture3 ) do |arg1 , arg2 , arg3 |
35
35
36
36
describe '#fetch' do
37
37
context 'when a single css_path is configured' do
38
- let ( :css_path ) { '/test.css' }
39
- let ( :css_paths ) { [ ] }
38
+ let ( :css_paths ) { [ '/test.css' ] }
40
39
41
40
it 'generates css for each route from the same file' do
42
41
expect ( Open3 ) . to receive ( :capture3 ) do |arg1 , arg2 , arg3 |
50
49
end
51
50
52
51
context 'when multiple css_paths are configured' do
53
- let ( :css_path ) { '' }
54
52
let ( :css_paths ) { [ '/test.css' , '/test2.css' ] }
55
53
56
54
it 'generates css for each route from the respective file' do
67
65
end
68
66
69
67
context 'when same css file applies to multiple routes' do
70
- let ( :css_path ) { '' }
71
68
let ( :css_paths ) { [ '/test.css' , '/test2.css' , '/test.css' ] }
72
69
let ( :routes ) { [ '/' , '/new_route' , '/newer_route' ] }
73
70
Original file line number Diff line number Diff line change 11
11
context 'when single css_path is specified' do
12
12
let ( :config_file ) { file_fixture ( 'config/single-css-path.yml' ) . read }
13
13
14
- it 'sets css_path with the path' do
15
- expect ( subject . config [ 'css_path' ] ) . to eq '/app/spec/internal/public/test.css'
16
- end
17
-
18
- it 'leaves css_paths empty' do
19
- 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' ]
20
16
end
21
17
end
22
18
23
19
context 'when multiple css_paths are specified' do
24
20
let ( :config_file ) { file_fixture ( 'config/mutliple-css-paths.yml' ) . read }
25
21
26
- it 'sets css_path to empty string' do
27
- expect ( subject . config [ 'css_path' ] ) . to eq ''
28
- end
29
-
30
22
it 'leaves css_paths to an array of paths' do
31
23
expect ( subject . config [ 'css_paths' ] ) . to eq [ '/app/spec/internal/public/test.css' , '/app/spec/internal/public/test2.css' ]
32
24
end
35
27
context 'when no paths are specified' do
36
28
let ( :config_file ) { file_fixture ( 'config/no-paths-specified.yml' ) . read }
37
29
38
- it 'sets css_path with the path' do
39
- expect ( subject . config [ 'css_path' ] ) . to eq '/stylesheets/application.css'
40
- end
41
-
42
- it 'leaves css_paths empty' do
43
- 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' ]
44
32
end
45
33
end
46
34
You can’t perform that action at this time.
0 commit comments