Skip to content

Commit 1498712

Browse files
committed
fixup! fixup! fixup! feat: RSS extension
1 parent 2d670d7 commit 1498712

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

config/test.exs

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ import Config
33
config :logger, level: :warning
44

55
config :tableau, :config, url: "http://localhost:4999"
6+
config :tableau, Tableau.RSSExtension, enabled: false
7+
config :tableau, Tableau.PostExtension, enabled: false
8+
config :tableau, Mix.Tasks.Tableau.LogExtension, enabled: true
9+
config :tableau, Mix.Tasks.Tableau.FailExtension, enabled: true

lib/mix/tasks/tableau.build.ex

+38-24
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,28 @@ defmodule Mix.Tasks.Tableau.Build do
2525
token ->
2626
config_mod = Module.concat([module, Config])
2727

28-
{:ok, config} =
29-
Application.get_env(:tableau, module, %{}) |> Map.new() |> config_mod.new()
28+
raw_config =
29+
Application.get_env(:tableau, module, %{}) |> Map.new()
3030

31-
{:ok, key} = Tableau.Extension.key(module)
31+
if raw_config[:enabled] do
32+
{:ok, config} =
33+
raw_config
34+
|> config_mod.new()
3235

33-
token = put_in(token[key], config)
36+
{:ok, key} = Tableau.Extension.key(module)
3437

35-
case module.run(token) do
36-
{:ok, token} ->
37-
token
38+
token = put_in(token[key], config)
3839

39-
:error ->
40-
Logger.error("#{inspect(module)} failed to run")
41-
token
40+
case module.run(token) do
41+
{:ok, token} ->
42+
token
43+
44+
:error ->
45+
Logger.error("#{inspect(module)} failed to run")
46+
token
47+
end
48+
else
49+
token
4250
end
4351
end
4452

@@ -73,29 +81,36 @@ defmodule Mix.Tasks.Tableau.Build do
7381
token ->
7482
config_mod = Module.concat([module, Config])
7583

76-
{:ok, config} =
77-
Application.get_env(:tableau, module, %{}) |> Map.new() |> config_mod.new()
84+
raw_config =
85+
Application.get_env(:tableau, module, %{}) |> Map.new()
86+
87+
if raw_config[:enabled] do
88+
{:ok, config} =
89+
raw_config
90+
|> config_mod.new()
7891

79-
{:ok, key} = Tableau.Extension.key(module)
92+
{:ok, key} = Tableau.Extension.key(module)
8093

81-
token = put_in(token[key], config)
94+
token = put_in(token[key], config)
8295

83-
case module.run(token) do
84-
{:ok, token} ->
85-
token
96+
case module.run(token) do
97+
{:ok, token} ->
98+
token
8699

87-
:error ->
88-
Logger.error("#{inspect(module)} failed to run")
89-
token
100+
:error ->
101+
Logger.error("#{inspect(module)} failed to run")
102+
token
103+
end
104+
else
105+
token
90106
end
91107
end
92108
end
93109

94110
defp pre_build_extensions(modules) do
95111
for {mod, _, _} <- modules,
96112
mod = Module.concat([to_string(mod)]),
97-
match?({:ok, :pre_build}, Tableau.Extension.type(mod)),
98-
Tableau.Extension.enabled?(mod) do
113+
match?({:ok, :pre_build}, Tableau.Extension.type(mod)) do
99114
mod
100115
end
101116
|> Enum.sort_by(& &1.__tableau_extension_priority__())
@@ -104,8 +119,7 @@ defmodule Mix.Tasks.Tableau.Build do
104119
defp post_write_extensions(modules) do
105120
for {mod, _, _} <- modules,
106121
mod = Module.concat([to_string(mod)]),
107-
match?({:ok, :post_write}, Tableau.Extension.type(mod)),
108-
Tableau.Extension.enabled?(mod) do
122+
match?({:ok, :post_write}, Tableau.Extension.type(mod)) do
109123
mod
110124
end
111125
|> Enum.sort_by(& &1.__tableau_extension_priority__())

lib/tableau/extensions/post_extension.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ defmodule Tableau.PostExtension do
8383

8484
@config config
8585

86-
use Tableau.Extension, key: :posts, enabled: @config.enabled, type: :pre_build, priority: 100
86+
use Tableau.Extension, key: :posts, type: :pre_build, priority: 100
8787

8888
def run(token) do
8989
Module.create(

0 commit comments

Comments
 (0)