diff --git a/lib/exdoc.ex b/lib/exdoc.ex index 0b898b84c..7754cf6f6 100644 --- a/lib/exdoc.ex +++ b/lib/exdoc.ex @@ -1,14 +1,14 @@ defmodule ExDoc do require Erlang.file, as: F - def generate_docs(path, formatter // ExDoc.HTMLFormatter) do + def generate_docs(path, output_path // "output", formatter // ExDoc.HTMLFormatter) do docs = ExDoc.Retriever.get_docs find_files(path), File.expand_path(path) - copy_index_files - copy_css_files - copy_javascript_files - copy_image_files - generate_seach_index docs - Enum.map docs, formatter.format_docs(&1) + copy_index_files output_path + copy_css_files output_path + copy_javascript_files output_path + copy_image_files output_path + generate_seach_index docs, output_path + Enum.map docs, formatter.format_docs(&1, output_path) end #### @@ -28,20 +28,20 @@ defmodule ExDoc do List.reverse(path) ++ '/**/*.beam' end - defp copy_index_files do - copy_file "../templates", "output", "index.html" + defp copy_index_files(output_path) do + copy_file "../templates", output_path, "index.html" end - defp copy_css_files do - copy_files "*.css", "../templates/css", "output/css" + defp copy_css_files(output_path) do + copy_files "*.css", "../templates/css", "#{output_path}/css" end - defp copy_javascript_files do - copy_files "*.js", "../templates/js", "output/js" + defp copy_javascript_files(output_path) do + copy_files "*.js", "../templates/js", "#{output_path}/js" end - defp copy_image_files do - copy_files "*.png", "../templates/i", "output/i" + defp copy_image_files(output_path) do + copy_files "*.png", "../templates/i", "#{output_path}/i" end defp copy_files(wildcard, input_path, output_path) do @@ -59,8 +59,8 @@ defmodule ExDoc do F.copy "#{input_path}/#{file}", "#{output_path}/#{file}" end - defp generate_seach_index(docs) do - output_path = File.expand_path "output/panel" + defp generate_seach_index(docs, base_output_path) do + output_path = File.expand_path "#{base_output_path}/panel" F.make_dir output_path names = Enum.map docs, get_names(&1) content = generate_html_from_names names diff --git a/lib/exdoc/html_formatter.ex b/lib/exdoc/html_formatter.ex index 89b984b8b..a6a83d74f 100644 --- a/lib/exdoc/html_formatter.ex +++ b/lib/exdoc/html_formatter.ex @@ -1,5 +1,5 @@ defmodule ExDoc.HTMLFormatter do - def format_docs({name,{ moduledoc, docs }}) do + def format_docs({name,{ moduledoc, docs }}, output_path) do docs = generate_html_for_docs(docs) moduledoc = generate_html_for_moduledoc(moduledoc) function_docs = Enum.filter_map docs, fn(x, do: filter_by_type(x, :def)), fn(x, do: get_content(x)) @@ -48,8 +48,4 @@ defmodule ExDoc.HTMLFormatter do defp template_path() do File.expand_path("../../templates", __FILE__) end - - defp output_path() do - File.expand_path "output" - end end diff --git a/test/exdoc/html_formatter_test.exs b/test/exdoc/html_formatter_test.exs index 3024c68e4..9e7f36c1d 100644 --- a/test/exdoc/html_formatter_test.exs +++ b/test/exdoc/html_formatter_test.exs @@ -12,11 +12,11 @@ defmodule ExDoc.HTMLFormatterTest do end defp output_dir do - File.expand_path "output" + File.expand_path "test/tmp/output" end test "format_docs generate only the module name when there's no more info" do - ExDoc.HTMLFormatter.format_docs({"XPTOModule", {{1, nil}, []}}) + ExDoc.HTMLFormatter.format_docs({"XPTOModule", {{1, nil}, []}}, output_dir) content = File.read!("#{output_dir}/XPTOModule.html") assert Regex.match?(%r/