Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ def cell() do
end
end
```

### Configuration options

- `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.
12 changes: 10 additions & 2 deletions lib/ex_css_modules/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ defmodule ExCSSModules.View do
Use the ExCSSModules.View on a view which defines the JSON for CSS Modules
as an external resource.

To embed the stylesheet in the file set :embed_stylesheet to true.
To embed the stylesheet in the file set :embed_stylesheet to true. This can
also be enabled through the `:embed_by_default` config option.

If adds the following functions to the View:
- stylesheet/0 - same as ExCSSModules.stylesheet/1 with the stylesheet predefined
Expand All @@ -19,7 +20,14 @@ defmodule ExCSSModules.View do

defmacro __using__(opts \\ []) do
{filename, [file: relative_to]} = Code.eval_quoted(opts[:stylesheet], file: __CALLER__.file)
{embed, _} = Code.eval_quoted(opts[:embed_stylesheet])

embed =
Keyword.get(
opts,
:embed_stylesheet,
Application.get_env(:ex_css_modules, :embed_by_default, false)
)
Comment on lines +24 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we'd want to have this inside the quote block, so it can retrieve the Application.env value at runtime (to support runtime configs in pre-compiled Mix Release / Distillery apps)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the point of the embed option to compile the stylesheet into the module?

I'm having trouble seeing how this could work at runtime short of having some sort of external cache like an agent or something 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you're right, doesn't make much sense indeed. Been working too much on compile time vs runtime config issues lately, my head was somewhere else :P

I'll test this PR in our own app somewhere this week and will get back to you.


filename = Path.expand(filename, Path.dirname(relative_to))

quote do
Expand Down