@@ -3,22 +3,13 @@ module Rails
33 class ConfigLoader
44 CONFIGURATION_FILENAME = 'critical_path_css.yml' . freeze
55
6- def load
7- config = YAML . safe_load ( ERB . new ( File . read ( configuration_file_path ) ) . result , [ ] , [ ] , true ) [ ::Rails . env ]
8- validate_css_path config
9- if config [ 'css_path' ]
10- config [ 'css_path' ] = "#{ ::Rails . root } /public" + (
11- config [ 'css_path' ] ||
12- ActionController ::Base . helpers . stylesheet_path (
13- config [ 'manifest_name' ] , host : ''
14- )
15- )
16- config [ 'css_paths' ] = [ ]
17- else
18- config [ 'css_path' ] = ''
19- config [ 'css_paths' ] = config [ 'css_paths' ] . collect { |path | "#{ ::Rails . root } /public#{ path } " }
20- end
21- config
6+ def initialize
7+ validate_css_paths
8+ format_css_paths
9+ end
10+
11+ def config
12+ @config ||= YAML . safe_load ( ERB . new ( File . read ( configuration_file_path ) ) . result , [ ] , [ ] , true ) [ ::Rails . env ]
2213 end
2314
2415 private
@@ -27,7 +18,21 @@ def configuration_file_path
2718 @configuration_file_path ||= ::Rails . root . join ( 'config' , CONFIGURATION_FILENAME )
2819 end
2920
30- def validate_css_path ( config )
21+ def format_css_paths
22+ if config [ 'css_path' ]
23+ config [ 'css_path' ] = format_path ( config [ 'css_path' ] )
24+ config [ 'css_paths' ] = [ ]
25+ else
26+ config [ 'css_path' ] = ''
27+ config [ 'css_paths' ] = config [ 'css_paths' ] . collect { |path | format_path ( path ) }
28+ end
29+ end
30+
31+ def format_path ( path )
32+ "#{ ::Rails . root } /public#{ path } "
33+ end
34+
35+ def validate_css_paths
3136 if config [ 'css_path' ] && config [ 'css_paths' ]
3237 raise LoadError , 'Cannot specify both css_path and css_paths'
3338 elsif config [ 'css_paths' ] && config [ 'css_paths' ] . length != config [ 'routes' ] . length
0 commit comments