Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pandoc.ex')
-rw-r--r--lib/pandoc.ex56
1 files changed, 35 insertions, 21 deletions
diff --git a/lib/pandoc.ex b/lib/pandoc.ex
index 336aeec..1c3970d 100644
--- a/lib/pandoc.ex
+++ b/lib/pandoc.ex
@@ -3,32 +3,16 @@ defmodule Pandoc do
Documentation for `Pandoc`.
"""
- def install_and_run(path) do
- System.cmd("pandoc", [
- "--mathjax",
- path,
- "-o",
- Path.join(
- "priv/static/posts",
- Path.basename(path)
- |> String.replace_suffix(".md", ".html")
- |> String.slice(11..-1//1)
- )
- ])
- end
-
- def install_and_run(profile, ["--watch"]) do
- # Application.get_env(:pandoc, a1) |> inspect(pretty: true) |> IO.puts
- IO.puts(
- "Pandoc watcher starting, env: #{Application.get_env(:pandoc, profile) |> inspect(pretty: true)}"
- )
+ def run(profile, ["--watch"]) do
+ IO.puts("""
- # Application.get_env(:pandoc, profile) |> inspect(pretty: true) |> IO.puts()
+ Pandoc watcher starting, env: #{Application.get_env(:pandoc, profile) |> inspect(pretty: true)}
+ """)
ref =
__MODULE__.Supervisor
|> Supervisor.start_child(
- Supervisor.child_spec({Pandoc.Watcher, [profile, dirs: ["priv/posts"]]},
+ Supervisor.child_spec({Pandoc.Watcher, [profile, dirs: ["documents"]]},
restart: :transient,
id: __MODULE__.Watcher
)
@@ -43,4 +27,34 @@ defmodule Pandoc do
{:DOWN, ^ref, _, _, _} -> :ok
end
end
+
+ def run(profile, extra_args) do
+ config = Application.get_env(:pandoc, profile)
+ args = config[:args] || []
+
+ opts = [
+ cd: config[:cd] || File.cwd!(),
+ into: IO.stream(:stdio, :line),
+ stderr_to_stdout: true
+ ]
+
+ [path] = extra_args
+
+ args =
+ List.update_at(args, -1, fn v ->
+ Path.join(
+ v,
+ path
+ |> Path.basename()
+ |> String.replace_suffix(".md", ".html")
+ |> String.slice(11..-1//1)
+ )
+ end)
+
+ IO.puts("""
+ System command running: #{inspect(Enum.join(["pandoc" | args ++ extra_args], " "))}
+ """)
+
+ "pandoc" |> System.cmd(args ++ extra_args, opts) |> elem(1)
+ end
end