Skip to content

Commit c373212

Browse files
committed
add a nice error if the application doesn't have a configured assets module
1 parent de8b1be commit c373212

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

lib/scenic/assets/static.ex

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,37 @@ defmodule Scenic.Assets.Static do
295295
# ===========================================================================
296296

297297
# --------------------------------------------------------
298-
# internal config sugar
299-
defp config(), do: Application.get_env(:scenic, :assets)
300-
301298
@doc """
302299
Return the configured asset library module.
303300
"""
304-
def module(), do: config()[:module]
301+
def module() do
302+
with {:ok, config} <- Application.fetch_env(:scenic, :assets),
303+
{:ok, module} <- Keyword.fetch(config, :module) do
304+
module
305+
else
306+
_ ->
307+
raise """
308+
No assets module is configured.
309+
You need to create an assets modulein your application.
310+
Then connect it to Scenic with some config.
311+
312+
Example assets module that includes an optional alias:
313+
314+
defmodule MyApplication.Assets do
315+
use Scenic.Assets.Static,
316+
otp_app: :my_application,
317+
alias: [
318+
my_parrot: "images/my_parrot.jpg"
319+
]
320+
end
321+
322+
Example configuration script (this goes in your config.exs file):
323+
324+
config :scenic, :assets,
325+
module: MyApplication.Assets
326+
"""
327+
end
328+
end
305329

306330
@doc "Return the compiled asset library."
307331
def library(), do: module().library()

0 commit comments

Comments
 (0)