Skip to content

Commit 51bb069

Browse files
Merge pull request #48 from mudbugmedia/add-manifest-path-exception
Add exception to prevent invalid configuration
2 parents c56e0f5 + 1371f5e commit 51bb069

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ The generator adds the following files:
5252

5353
First, you'll need to configue a few things in the YAML file: `config/critical_path_css.yml`
5454

55+
**Note** that `manifest_name`, `css_path`, `css_paths` are all **mutually exclusive**; if using `css_path`, configuration for `manifest_name` AND `css_paths` should be omitted.
56+
5557
* `manifest_name`: If you're using the asset pipeline, add the manifest name.
5658
* `css_path`: If you're not using the asset pipeline, you'll need to define the path to the application's main CSS. The gem assumes your CSS lives in `RAILS_ROOT/public`. If your main CSS file is in `RAILS_ROOT/public/assets/main.css`, you would set the variable to `/assets/main.css`.
57-
* `css_paths`: If you have the need to specify multiple CSS source files, you can do so with `css_paths`. Note that `css_path` and `css_paths` are **mutually exclusive**; if using `css_path`, configuration for `css_paths` should be omitted, and vice versa. When using this option, a separate CSS path must be specified for each route, and they will be matched based on the order specified (the first CSS path will be applied to the first route, the second CSS path to the second route, etc).
59+
* `css_paths`: If you have the need to specify multiple CSS source files, you can do so with `css_paths`. When using this option, a separate CSS path must be specified for each route, and they will be matched based on the order specified (the first CSS path will be applied to the first route, the second CSS path to the second route, etc).
5860
* `routes`: List the routes that you would like to generate the critical CSS for. (i.e. /resources, /resources/show/1, etc.)
5961
* `base_url`: Add your application's URL for the necessary environments.
6062

lib/critical_path_css/rails/config_loader.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def format_path(path)
3333
end
3434

3535
def validate_css_paths
36-
if config['css_path'] && config['css_paths']
36+
if config['manifest_name'] && (config['css_path'] || config['css_paths'])
37+
raise LoadError, 'Cannot specify both manifest_name and css_path(s)'
38+
elsif config['css_path'] && config['css_paths']
3739
raise LoadError, 'Cannot specify both css_path and css_paths'
3840
elsif config['css_paths'] && config['css_paths'].length != config['routes'].length
3941
raise LoadError, 'Must specify css_paths for each route'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module CriticalPathCSS
22
module Rails
3-
VERSION = '4.0.0'.freeze
3+
VERSION = '4.0.1'.freeze
44
end
55
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
manifest_name: application
4+
css_path: /test.css
5+
6+
development:
7+
<<: *defaults
8+
9+
test:
10+
<<: *defaults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
manifest_name: application
4+
css_paths:
5+
- /test.css
6+
- /test2.css
7+
routes:
8+
- /
9+
- /new_route
10+
11+
development:
12+
<<: *defaults
13+
14+
test:
15+
<<: *defaults

spec/lib/critical_path_css/rails/config_loader_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@
3232
end
3333
end
3434

35+
context 'when manifest name and css path are both specified' do
36+
let(:config_file) { file_fixture('config/manifest-and-path-both-specified.yml').read }
37+
38+
it 'raises an error' do
39+
expect { subject }.to raise_error LoadError, 'Cannot specify both manifest_name and css_path(s)'
40+
end
41+
end
42+
43+
context 'when manifest name and css paths are both specified' do
44+
let(:config_file) { file_fixture('config/manifest-and-paths-both-specified.yml').read }
45+
46+
it 'raises an error' do
47+
expect { subject }.to raise_error LoadError, 'Cannot specify both manifest_name and css_path(s)'
48+
end
49+
end
50+
3551
context 'when single css_path and multiple css_paths are both specified' do
3652
let(:config_file) { file_fixture('config/paths-both-specified.yml').read }
3753

0 commit comments

Comments
 (0)