Permalink
Browse files

Merge pull request #12 from lest/patch-1

output directory can be set
  • Loading branch information...
2 parents 5b644ec + 3e00f37 commit 174ea7c7bf929254b5b422c58e0e0ebfa625fb54 @rafaelfranca rafaelfranca committed Apr 26, 2012
Showing with 27 additions and 25 deletions.
  1. +17 −17 lib/exdoc.ex
  2. +1 −5 lib/exdoc/html_formatter.ex
  3. +3 −3 test/exdoc/html_formatter_test.exs
  4. +6 −0 test/exdoc_test.exs
View
@@ -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
@@ -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
@@ -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)
@@ -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)
View
@@ -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

0 comments on commit 174ea7c

Please sign in to comment.