Skip to content

Commit 3c7048b

Browse files
Refactor css_path logic into it’s own method
Remove a few unnecessary comments in the penthouse config
1 parent 4c7f6c8 commit 3c7048b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/critical_path_css/css_fetcher.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,21 @@ def initialize(config)
1010
end
1111

1212
def fetch
13-
@config.routes.map.with_index { |route, index|
14-
css_path = @config.css_paths[index].present? ? @config.css_paths[index] : @config.css_path
15-
[route, css_for_route(route, css_path)]
16-
}.to_h
13+
@config.routes.map { |route| [route, fetch_route(route)] }.to_h
1714
end
1815

1916
def fetch_route(route)
20-
css_for_route route
21-
end
22-
23-
protected
24-
25-
def css_for_route(route, css_path)
2617
options = {
2718
'url' => @config.base_url + route,
28-
'css' => css_path,
29-
## optional params
30-
# viewport dimensions
19+
'css' => fetch_css_path_for_route(route), #implement
3120
'width' => 1300,
3221
'height' => 900,
22+
'timeout' => 30_000,
3323
# CSS selectors to always include, e.g.:
3424
'forceInclude' => [
3525
# '.keepMeEvenIfNotSeenInDom',
3626
# '^\.regexWorksToo'
3727
],
38-
# ms; abort critical CSS generation after this timeout
39-
'timeout' => 30_000,
4028
# set to true to throw on CSS errors (will run faster if no errors)
4129
'strict' => false,
4230
# characters; strip out inline base64 encoded resources larger than this
@@ -63,5 +51,17 @@ def css_for_route(route, css_path)
6351
end
6452
out
6553
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
6666
end
6767
end

0 commit comments

Comments
 (0)