Skip to content

Commit fbb2621

Browse files
committed
fix: refresh graph after running extensions
1 parent 34c9b09 commit fbb2621

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

lib/mix/tasks/tableau.build.ex

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ defmodule Mix.Tasks.Tableau.Build do
1515
{opts, _argv} = OptionParser.parse!(argv, strict: [out: :string])
1616

1717
out = Keyword.get(opts, :out, "_site")
18+
1819
mods = :code.all_available()
19-
graph = Tableau.Graph.new(mods)
20-
File.mkdir_p!(out)
2120

22-
for module <- pre_write_extensions(mods) do
23-
with :error <- module.run(graph, %{site: %{}}) do
21+
for module <- pre_build_extensions(mods) do
22+
with :error <- module.run(%{site: %{}}) do
2423
Logger.error("#{inspect(module)} failed to run")
2524
end
2625
end
2726

27+
mods = :code.all_available()
28+
graph = Tableau.Graph.new(mods)
29+
File.mkdir_p!(out)
30+
2831
for mod <- Graph.vertices(graph), {:ok, :page} == Tableau.Graph.Node.type(mod) do
2932
content = Tableau.Document.render(graph, mod, %{site: %{}})
3033
permalink = mod.__tableau_permalink__()
@@ -40,7 +43,7 @@ defmodule Mix.Tasks.Tableau.Build do
4043
end
4144
end
4245

43-
defp pre_write_extensions(modules) do
46+
defp pre_build_extensions(modules) do
4447
for {mod, _, _} <- modules,
4548
mod = Module.concat([to_string(mod)]),
4649
match?({:ok, :pre_build}, Tableau.Extension.type(mod)) do

lib/mix/tasks/tableau.server.ex

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule Mix.Tasks.Tableau.Server do
99
@impl Mix.Task
1010
def run(_args) do
1111
Application.put_env(:tableau, :server, true)
12+
Code.put_compiler_option(:ignore_module_conflict, true)
1213

1314
Logger.debug("server started on http://localhost:4999")
1415

lib/tableau/extension.ex

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Tableau.Extension do
1212
defmodule MySite.PostsExtension do
1313
use Tableau.Extension, type: :pre_build
1414
15-
def run(_graph, _site) do
15+
def run(_site) do
1616
posts = Path.wildcard("_posts/**/*.md")
1717
1818
for post <- post do
@@ -32,11 +32,9 @@ defmodule Tableau.Extension do
3232
@doc """
3333
The extension entry point.
3434
35-
The function is passed the layout graph and a set of default assigns.
36-
37-
The graph is an instance of a [Graph.t](https://hexdocs.pm/libgraph/0.16.0/Graph.html#t:t/0) from the library `libgraph`.
35+
The function is passed the a set of default assigns.
3836
"""
39-
@callback run(Graph.t(), map()) :: :ok | :error
37+
@callback run(map()) :: :ok | :error
4038

4139
defmacro __using__(opts) do
4240
opts = Keyword.validate!(opts, [:type])

test/mix/tasks/tableau.build_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Mix.Tasks.Tableau.LogExtension do
22
use Tableau.Extension, type: :pre_build
33

4-
def run(_graph, _site) do
4+
def run(_site) do
55
IO.puts("hi!")
66
:ok
77
end
@@ -10,7 +10,7 @@ end
1010
defmodule Mix.Tasks.Tableau.FailExtension do
1111
use Tableau.Extension, type: :pre_build
1212

13-
def run(_graph, _site) do
13+
def run(_site) do
1414
:error
1515
end
1616
end

0 commit comments

Comments
 (0)