Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions lib/exdoc.ex
Original file line number Diff line number Diff line change
@@ -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

####
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions lib/exdoc/html_formatter.ex
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/exdoc/html_formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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/<title>XPTOModule<\/title>/, content)
Expand All @@ -30,7 +30,7 @@ defmodule ExDoc.HTMLFormatterTest do
file = "#{input_path}/CompiledWithDocs.beam"

[docs] = ExDoc.Retriever.get_docs [file], input_path
ExDoc.HTMLFormatter.format_docs(docs)
ExDoc.HTMLFormatter.format_docs(docs, output_dir)

content = File.read!("#{output_dir}/CompiledWithDocs.html")
assert Regex.match?(%r/<title>CompiledWithDocs<\/title>/, content)
Expand Down
6 changes: 6 additions & 0 deletions test/exdoc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ defmodule ExDocTest do
assert Regex.match?(%r/<li class='level_0 closed'>.*'..\/ExDocTest\.Nested\.html'.*ExDocTest\.Nested.*<\/li>/m, content)
assert Regex.match?(%r/<li class='level_1 closed'>.*'..\/ExDocTest\.Nested\.html#example\/2'.*example\/2.*<\/li>/m, content)
end

test "generate_docs generates in specified output directory" do
ExDoc.generate_docs "tmp", "#{output_dir}/docs"

assert :filelib.is_file("#{output_dir}/docs/CompiledWithDocs.html")
end
end