Skip to content

Commit 57113a8

Browse files
authored
Merge pull request #67 from Blond11516/feat/embed-config
feat: Add config option to embed stylesheets by default
2 parents 4afd6dd + 4f8ab59 commit 57113a8

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
@@ -89,3 +89,7 @@ def cell() do
8989
end
9090
end
9191
```
92+
93+
### Configuration options
94+
95+
- `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)