Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
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
parent9d9a9bb13e99332a1fbe65d807b83bd1824eda5f (diff)
Get path from config in mix task
-rw-r--r--lib/mix/tasks/pandoc.ex18
-rw-r--r--lib/pandoc.ex6
-rw-r--r--lib/pandoc/watcher.ex2
-rw-r--r--mix.exs5
-rw-r--r--mix.lock9
5 files changed, 26 insertions, 14 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
diff --git a/mix.exs b/mix.exs
index cdbe797..e124a56 100644
--- a/mix.exs
+++ b/mix.exs
@@ -8,7 +8,7 @@ defmodule Pandoc.MixProject do
elixir: "~> 1.14",
deps: deps(),
description: "Pandoc",
- package: []
+ package: [links: [], licenses: ["MIT"]]
]
end
@@ -23,7 +23,8 @@ defmodule Pandoc.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
- {:file_system, "~> 1.0"}
+ {:file_system, "~> 1.0"},
+ {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end
end
diff --git a/mix.lock b/mix.lock
new file mode 100644
index 0000000..d2090ab
--- /dev/null
+++ b/mix.lock
@@ -0,0 +1,9 @@
+%{
+ "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
+ "ex_doc": {:hex, :ex_doc, "0.35.1", "de804c590d3df2d9d5b8aec77d758b00c814b356119b3d4455e4b8a8687aecaf", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2121c6402c8d44b05622677b761371a759143b958c6c19f6558ff64d0aed40df"},
+ "file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
+ "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
+ "makeup_elixir": {:hex, :makeup_elixir, "1.0.0", "74bb8348c9b3a51d5c589bf5aebb0466a84b33274150e3b6ece1da45584afc82", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "49159b7d7d999e836bedaf09dcf35ca18b312230cf901b725a64f3f42e407983"},
+ "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
+ "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
+}