diff --git a/lib/ex_doc/formatter/epub.ex b/lib/ex_doc/formatter/epub.ex index 2db45ba35..a70e360a9 100644 --- a/lib/ex_doc/formatter/epub.ex +++ b/lib/ex_doc/formatter/epub.ex @@ -10,14 +10,9 @@ defmodule ExDoc.Formatter.EPUB do """ @spec run([ExDoc.ModuleNode.t()], [ExDoc.ModuleNode.t()], ExDoc.Config.t()) :: String.t() def run(project_nodes, filtered_modules, config) when is_map(config) do - parent = config.output config = normalize_config(config) - - HTML.setup_output( - parent, - &cleanup_output_dir(&1, config), - &create_output_dir(&1, config) - ) + File.rm_rf!(config.output) + File.mkdir_p!(Path.join(config.output, "OEBPS")) project_nodes = HTML.render_all(project_nodes, filtered_modules, ".xhtml", config, highlight_tag: "samp") @@ -50,16 +45,6 @@ defmodule ExDoc.Formatter.EPUB do Path.relative_to_cwd(epub) end - defp create_output_dir(root, config) do - File.mkdir_p!(Path.join(config.output, "OEBPS")) - File.touch!(Path.join(root, ".build")) - end - - defp cleanup_output_dir(docs_root, config) do - File.rm_rf!(config.output) - create_output_dir(docs_root, config) - end - defp normalize_config(config) do output = config.output diff --git a/lib/ex_doc/formatter/html.ex b/lib/ex_doc/formatter/html.ex index 75f7c323b..89f59cbde 100644 --- a/lib/ex_doc/formatter/html.ex +++ b/lib/ex_doc/formatter/html.ex @@ -16,7 +16,7 @@ defmodule ExDoc.Formatter.HTML do config = %{config | output: Path.expand(config.output)} build = Path.join(config.output, ".build") - setup_output(config.output, &cleanup_output_dir(&1, config), &create_output_dir(&1, config)) + output_setup(build, config) project_nodes = render_all(project_nodes, filtered_modules, ".html", config, []) extras = build_extras(config, ".html") @@ -148,53 +148,18 @@ defmodule ExDoc.Formatter.HTML do |> ExDoc.DocAST.highlight(language, opts) end - def setup_output(root, cleanup, create) do - safety_path = Path.join(root, ".build") - - cond do - File.exists?(safety_path) and File.exists?(root) -> - cleanup.(root) - - not File.exists?(root) -> - create.(root) - - File.ls!(root) == [] -> - add_safety_file(root) - :ok - - true -> - IO.warn( - "ExDoc is outputting to an existing directory. " <> - "Beware documentation output may be mixed with other entries" - ) - - create.(root) - end - end - - defp create_output_dir(root, _config) do - File.mkdir_p!(root) - add_safety_file(root) - end - - defp add_safety_file(root) do - File.touch!(Path.join(root, ".build")) - end - - defp cleanup_output_dir(docs_root, config) do - build = Path.join(docs_root, ".build") - + defp output_setup(build, config) do if File.exists?(build) do build |> File.read!() |> String.split("\n", trim: true) - |> Enum.map(&Path.join(docs_root, &1)) + |> Enum.map(&Path.join(config.output, &1)) |> Enum.each(&File.rm/1) File.rm(build) else - File.rm_rf!(docs_root) - create_output_dir(docs_root, config) + File.rm_rf!(config.output) + File.mkdir_p!(config.output) end end diff --git a/test/ex_doc/formatter/epub_io_test.exs b/test/ex_doc/formatter/epub_io_test.exs deleted file mode 100644 index 086374790..000000000 --- a/test/ex_doc/formatter/epub_io_test.exs +++ /dev/null @@ -1,38 +0,0 @@ -defmodule ExDoc.Formatter.EPUBIOTest do - use ExUnit.Case, async: false - - @moduletag :tmp_dir - - test "succeeds if trying to write into an empty existing directory", %{tmp_dir: tmp_dir} do - File.mkdir!("#{tmp_dir}/doc") - - assert ExUnit.CaptureIO.capture_io(:stderr, fn -> - generate_docs(tmp_dir) - end) == "" - end - - test "warns if trying to write into existing directory with files", %{tmp_dir: tmp_dir} do - File.mkdir!("#{tmp_dir}/doc") - File.touch!("#{tmp_dir}/doc/foo.txt") - - assert ExUnit.CaptureIO.capture_io(:stderr, fn -> - generate_docs(tmp_dir) - end) =~ "ExDoc is outputting to an existing directory" - - # Warn only once - assert ExUnit.CaptureIO.capture_io(:stderr, fn -> - generate_docs(tmp_dir) - end) == "" - end - - defp generate_docs(tmp_dir) do - config = [ - app: :foo, - formatter: "epub", - output: "#{tmp_dir}/doc", - source_beam: "#{tmp_dir}/ebin" - ] - - ExDoc.generate_docs("Foo", "1.0.0", config) - end -end diff --git a/test/ex_doc/formatter/html/erlang_test.exs b/test/ex_doc/formatter/html/erlang_test.exs index 6de81f149..92556efc2 100644 --- a/test/ex_doc/formatter/html/erlang_test.exs +++ b/test/ex_doc/formatter/html/erlang_test.exs @@ -5,12 +5,6 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do @moduletag :otp_eep48 @moduletag :tmp_dir - setup %{tmp_dir: tmp_dir} do - output = tmp_dir <> "/doc" - File.mkdir!(output) - File.touch!("#{output}/.build") - end - test "smoke test", c do erlc(c, :foo, ~S""" %% @doc diff --git a/test/ex_doc/formatter/html/search_data_test.exs b/test/ex_doc/formatter/html/search_data_test.exs index b2ee448e0..a04af1f67 100644 --- a/test/ex_doc/formatter/html/search_data_test.exs +++ b/test/ex_doc/formatter/html/search_data_test.exs @@ -4,12 +4,6 @@ defmodule ExDoc.Formatter.HTML.SearchDataTest do @moduletag :tmp_dir - setup %{tmp_dir: tmp_dir} do - output = tmp_dir <> "/doc" - File.mkdir!(output) - File.touch!("#{output}/.build") - end - test "Elixir module", c do modules = elixirc(c, ~S''' diff --git a/test/ex_doc/formatter/html_io_test.exs b/test/ex_doc/formatter/html_io_test.exs deleted file mode 100644 index 8da38c2b2..000000000 --- a/test/ex_doc/formatter/html_io_test.exs +++ /dev/null @@ -1,38 +0,0 @@ -defmodule ExDoc.Formatter.HtmlIOTest do - use ExUnit.Case, async: false - - @moduletag :tmp_dir - - test "succeeds if trying to write into an empty existing directory", %{tmp_dir: tmp_dir} do - File.mkdir!("#{tmp_dir}/doc") - - assert ExUnit.CaptureIO.capture_io(:stderr, fn -> - generate_docs(tmp_dir) - end) == "" - end - - test "warns if trying to write into existing directory with files", %{tmp_dir: tmp_dir} do - File.mkdir!("#{tmp_dir}/doc") - File.touch!("#{tmp_dir}/doc/foo.txt") - - assert ExUnit.CaptureIO.capture_io(:stderr, fn -> - generate_docs(tmp_dir) - end) =~ "ExDoc is outputting to an existing directory" - - # Warn only once - assert ExUnit.CaptureIO.capture_io(:stderr, fn -> - generate_docs(tmp_dir) - end) == "" - end - - defp generate_docs(tmp_dir) do - config = [ - app: :foo, - formatter: "html", - output: "#{tmp_dir}/doc", - source_beam: "#{tmp_dir}/ebin" - ] - - ExDoc.generate_docs("Foo", "1.0.0", config) - end -end diff --git a/test/ex_doc/formatter/html_test.exs b/test/ex_doc/formatter/html_test.exs index 1e37c4874..f4e2f7382 100644 --- a/test/ex_doc/formatter/html_test.exs +++ b/test/ex_doc/formatter/html_test.exs @@ -6,12 +6,6 @@ defmodule ExDoc.Formatter.HTMLTest do @moduletag :tmp_dir - setup %{tmp_dir: tmp_dir} do - output = tmp_dir <> "/html" - File.mkdir_p!(output) - File.touch!(output <> "/.build") - end - defp read_wildcard!(path) do [file] = Path.wildcard(path) File.read!(file) diff --git a/test/test_helper.exs b/test/test_helper.exs index c67b891ad..9ce5e3e4b 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -22,10 +22,6 @@ defmodule TestHelper do def elixirc(context, filename \\ "nofile", code) do dir = context.tmp_dir - output_dir = context.tmp_dir <> "/html" - File.mkdir_p!(output_dir) - File.write!(output_dir <> "/.build", "") - src_path = Path.join([dir, filename]) src_path |> Path.dirname() |> File.mkdir_p!() File.write!(src_path, code)