Skip to content

Commit 9532921

Browse files
author
Étienne Lévesque
committed
feat: Add config option to embed stylesheets by default
1 parent b3ff31b commit 9532921

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ def cell() do
8585
end
8686
end
8787
```
88+
89+
### Configuration options
90+
91+
- `embed_by_default`: Global configuration for the `:embed_stylesheet` option of [ExCssModules.View](./lib/view.ex). Can still be overridden by the use option. Useful for configuring different defaults in development and production. Defaults to false.

lib/ex_css_modules/view.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ defmodule ExCSSModules.View do
77
Use the ExCSSModules.View on a view which defines the JSON for CSS Modules
88
as an external resource.
99
10-
To embed the stylesheet in the file set :embed_stylesheet to true.
10+
To embed the stylesheet in the file set :embed_stylesheet to true. This can
11+
also be enabled through the `:embed_by_default` config option.
1112
1213
If adds the following functions to the View:
1314
- stylesheet/0 - same as ExCSSModules.stylesheet/1 with the stylesheet predefined
@@ -19,7 +20,14 @@ defmodule ExCSSModules.View do
1920

2021
defmacro __using__(opts \\ []) do
2122
{filename, [file: relative_to]} = Code.eval_quoted(opts[:stylesheet], file: __CALLER__.file)
22-
{embed, _} = Code.eval_quoted(opts[:embed_stylesheet])
23+
24+
embed =
25+
Keyword.get(
26+
opts,
27+
:embed_stylesheet,
28+
Application.get_env(:ex_css_modules, :embed_by_default, false)
29+
)
30+
2331
filename = Path.expand(filename, Path.dirname(relative_to))
2432

2533
quote do

0 commit comments

Comments
 (0)