Skip to content

Commit

Permalink
Load plugins after loading serum.exs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalgona committed Apr 11, 2019
1 parent 35675b8 commit a40873b
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions lib/serum/site_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Serum.SiteBuilder do

use GenServer
alias Serum.Build
alias Serum.Plugin
alias Serum.Project
alias Serum.Result

Expand Down Expand Up @@ -91,12 +92,13 @@ defmodule Serum.SiteBuilder do
def handle_call(msg, from, state)

def handle_call(:load_info, _from, state) do
case Project.Loader.load(state.src, state.dest) do
{:ok, proj} ->
{:reply, {:ok, proj}, %{state | project_info: proj}}
with {:ok, proj} <- Project.Loader.load(state.src, state.dest),
{:ok, plugins} <- Plugin.load_plugins(proj.plugins) do
print_plugins(plugins)

{:error, _} = error ->
{:reply, error, state}
{:reply, {:ok, proj}, %{state | project_info: proj}}
else
{:error, _} = error -> {:reply, error, state}
end
end

Expand All @@ -114,4 +116,23 @@ defmodule Serum.SiteBuilder do
def handle_cast(:stop, _state) do
exit(:normal)
end

@spec print_plugins([Plugin.t()]) :: :ok
defp print_plugins([]), do: :ok

defp print_plugins(plugins) do
IO.puts("\x1b[93m=== Loaded Plugins ===\x1b[0m")

Enum.each(plugins, fn plugin ->
mod_name =
plugin.module
|> to_string()
|> String.replace_prefix("Elixir.", "")

IO.puts("\x1b[1m#{plugin.name} v#{plugin.version}\x1b[0m (#{mod_name})")
IO.puts(" " <> plugin.description)
end)

IO.puts("")
end
end

0 comments on commit a40873b

Please sign in to comment.