@@ -8,12 +8,45 @@ defmodule ExDoc.Formatter.HTML.Assets do
88 |> Enum . map ( & { Path . basename ( & 1 ) , File . read! ( & 1 ) } )
99 end
1010
11- def dist ( proglang ) , do: dist_js ( ) ++ dist_css ( proglang ) ++ dist_license ( )
12-
13- defp dist_js ( ) , do: embed_pattern ( "dist/*.js" )
11+ defp dist_js ( ) , do: embed_pattern ( "dist/html-*.js" )
12+ defp dist_inline_js ( ) , do: embed_pattern ( "dist/inline_html-*.js" )
1413 defp dist_css ( :elixir ) , do: embed_pattern ( "dist/html-elixir-*.css" )
1514 defp dist_css ( :erlang ) , do: embed_pattern ( "dist/html-erlang-*.css" )
1615 defp dist_license ( ) , do: embed_pattern ( "dist/*.LICENSE.txt" )
1716
17+ ## Assets
18+
19+ def dist ( proglang ) , do: dist_js ( ) ++ dist_css ( proglang ) ++ dist_license ( )
1820 def fonts , do: embed_pattern ( "dist/*.woff2" )
21+
22+ ## Sources
23+
24+ def inline_js_source ( ) , do: dist_inline_js ( ) |> extract_source! ( )
25+
26+ ## Filenames
27+
28+ def js_filename ( ) , do: dist_js ( ) |> extract_filename! ( )
29+ def css_filename ( language ) , do: dist_css ( language ) |> extract_filename! ( )
30+
31+ ## Helpers
32+
33+ @ doc """
34+ Some assets are generated automatically, so we find the revision at runtime.
35+ """
36+ def rev ( output , pattern ) do
37+ output = Path . expand ( output )
38+
39+ matches =
40+ output
41+ |> Path . join ( pattern )
42+ |> Path . wildcard ( )
43+
44+ case matches do
45+ [ ] -> raise ( "could not find matching #{ output } /#{ pattern } " )
46+ [ asset | _ ] -> Path . relative_to ( asset , output )
47+ end
48+ end
49+
50+ defp extract_filename! ( [ { location , _ } ] ) , do: location
51+ defp extract_source! ( [ { _ , source } ] ) , do: source
1952end
0 commit comments