Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-12-11 16:59:15 -0800
committerCatalin Mititiuc <webdevcat@proton.me>2024-12-11 16:59:15 -0800
commit9e8392a939825a8920004922d51b123b1a92b6b9 (patch)
tree5ac4028d1838275ae1b917d72852e8f5e5fd7842 /lib
parent9d9a9bb13e99332a1fbe65d807b83bd1824eda5f (diff)
Get path from config in mix task
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/tasks/pandoc.ex18
-rw-r--r--lib/pandoc.ex6
-rw-r--r--lib/pandoc/watcher.ex2
3 files changed, 14 insertions, 12 deletions
diff --git a/lib/mix/tasks/pandoc.ex b/lib/mix/tasks/pandoc.ex
index 4da8bf1..94d7dd5 100644
--- a/lib/mix/tasks/pandoc.ex
+++ b/lib/mix/tasks/pandoc.ex
@@ -1,6 +1,8 @@
defmodule Mix.Tasks.Pandoc do
use Mix.Task
+ @ext ".md"
+
@impl true
def run(args) do
switches = [runtime_config: :boolean]
@@ -17,15 +19,17 @@ defmodule Mix.Tasks.Pandoc do
install_and_run(remaining_args)
end
- defp install_and_run([profile | args] = _all) do
- IO.puts("mix task args #{inspect(args)}")
+ defp install_and_run([profile | _args] = all) do
+ IO.puts("Converting markdown...")
- "documents"
- |> File.ls!()
- |> Enum.each(fn path ->
- all = [profile, path]
+ profile = String.to_atom(profile)
+ config = Application.get_env(:pandoc, profile)
- case Pandoc.run(String.to_atom(profile), [path]) do
+ (config[:cd] || File.cwd!())
+ |> Path.join("*#{@ext}")
+ |> Path.wildcard()
+ |> Enum.each(fn path ->
+ case Pandoc.run(profile, Path.basename(path)) do
0 -> :ok
status -> Mix.raise("`mix pandoc #{Enum.join(all, " ")}` exited with #{status}")
end
diff --git a/lib/pandoc.ex b/lib/pandoc.ex
index 57606da..882d772 100644
--- a/lib/pandoc.ex
+++ b/lib/pandoc.ex
@@ -23,7 +23,7 @@ defmodule Pandoc do
end
end
- def run(profile, extra_args) do
+ def run(profile, path) do
config = Application.get_env(:pandoc, profile)
args = config[:args] || []
@@ -33,8 +33,6 @@ defmodule Pandoc do
stderr_to_stdout: true
]
- [path] = extra_args
-
args =
List.update_at(args, -1, fn v ->
Path.join(
@@ -46,6 +44,6 @@ defmodule Pandoc do
)
end)
- "pandoc" |> System.cmd(args ++ extra_args, opts) |> elem(1)
+ "pandoc" |> System.cmd(args ++ [path], opts) |> elem(1)
end
end
diff --git a/lib/pandoc/watcher.ex b/lib/pandoc/watcher.ex
index c67ae26..304bb50 100644
--- a/lib/pandoc/watcher.ex
+++ b/lib/pandoc/watcher.ex
@@ -15,7 +15,7 @@ defmodule Pandoc.Watcher do
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
case {Path.extname(path), :closed in events} do
- {@ext, true} -> Pandoc.run(state[:profile], [path])
+ {@ext, true} -> Pandoc.run(state[:profile], path)
_ -> nil
end