defmodule ForageWeb.Assets do @moduledoc """ Utilities to deal with static assets required by Forage's more advanced widgets, namely the select widgets. Forage uses Bootstrap v4 instead of the newer Bootstrap v5. """ @external_resource "lib/forage_web/assets/activate-forage-select.js" # Extract the list of supported themes from the ones in the `priv/` directory bootswatch_themes = File.ls!("priv/static/themes") |> List.delete("default") |> Enum.sort() # Ensure the "default" theme comes first bootstrap_themes = ["default" | bootswatch_themes] for theme <- bootstrap_themes do path = "priv/static/themes/#{theme}/bootstrap.min.css" @external_resource path end for file <- File.ls!("priv/static/select/") do path = "priv/select/#{file}" @external_resource path end # Add the supported themes to a module attribute @bootstrap_themes bootstrap_themes url_for_theme = fn # Not strictly a Bootswatch theme, but including it here is useful "default" -> "https://getbootstrap.com/docs/4.6/getting-started/introduction/" # Link to Boostwatch v4 theme -> "https://bootswatch.com/4/#{theme}/" end # Build a markdown excerpt containing a list of suppoered theme # and their respective themes theme_list_markdown = bootstrap_themes |> Enum.map(fn theme -> " - [#{theme}](#{url_for_theme.(theme)})" end) |> Enum.join("\n") @activate_select ( "" ) @forage_select_assets_from_cdn """ """ @forage_select_assets_from_app """ """ @doc """ Adds a `