Skip to content

Commit 58d909a

Browse files
committed
Get rid of the 'extras-' prefix
1 parent 62857db commit 58d909a

File tree

5 files changed

+71
-28
lines changed

5 files changed

+71
-28
lines changed

lib/ex_doc/cli.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ defmodule ExDoc.CLI do
107107
-u, --source-url URL to the source code
108108
--source-ref Branch/commit/tag used for source link inference, default: "master"
109109
-m, --main The main, entry-point module in docs,
110-
default: "extra-api-reference" when --formatter is "html"
110+
default: "api-reference" when --formatter is "html"
111111
-p, --homepage-url URL to link to for the site name
112112
-e, --extra Allow users to include additional Markdown files
113113
May be given multiple times

lib/ex_doc/formatter/html.ex

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule ExDoc.Formatter.HTML do
66
alias ExDoc.Formatter.HTML.Templates
77
alias ExDoc.Formatter.HTML.Autolink
88

9-
@main "extra-api-reference"
9+
@main "api-reference"
1010

1111
@doc """
1212
Generate HTML documentation for the given modules
@@ -56,7 +56,7 @@ defmodule ExDoc.Formatter.HTML do
5656

5757
defp generate_api_reference(modules, exceptions, protocols, output, config) do
5858
content = Templates.api_reference_template(config, modules, exceptions, protocols)
59-
File.write!("#{output}/extra-api-reference.html", content)
59+
File.write!("#{output}/api-reference.html", content)
6060
end
6161

6262
defp generate_not_found(modules, exceptions, protocols, output, config) do
@@ -100,35 +100,74 @@ defmodule ExDoc.Formatter.HTML do
100100
generate_extra(&1, output, module_nodes, modules, exceptions, protocols, config)
101101
end))
102102
|> Enum.map(&Task.await/1)
103-
[{"extra-api-reference", "API Reference", []}|extras]
103+
[{"api-reference", "API Reference", []}|extras]
104+
end
105+
106+
defp generate_extra({input_file, output_file_name}, output, module_nodes, modules, exceptions, protocols, config) do
107+
title = input_to_title(output_file_name)
108+
109+
options = %{
110+
title: title,
111+
output_file_name: title,
112+
input: to_string(input_file),
113+
output: output
114+
}
115+
116+
create_extra_files(module_nodes, modules, exceptions, protocols, config, options)
104117
end
105118

106119
defp generate_extra(input, output, module_nodes, modules, exceptions, protocols, config) do
107-
file_ext =
108-
input
109-
|> Path.extname()
110-
|> String.downcase()
120+
title = input_to_title(input)
121+
output_file_name = title_to_filename(title)
122+
123+
options = %{
124+
title: title,
125+
output_file_name: output_file_name,
126+
input: input,
127+
output: output
128+
}
111129

112-
if file_ext in [".md"] do
113-
title = Path.rootname(Path.basename(input))
114-
file_name = title_to_filename(title)
130+
create_extra_files(module_nodes, modules, exceptions, protocols, config, options)
131+
end
115132

133+
defp create_extra_files(module_nodes, modules, exceptions, protocols, config, options) do
134+
if valid_extension_name?(options.input) do
116135
content =
117-
input
136+
options.input
118137
|> File.read!()
119138
|> Autolink.project_doc(module_nodes)
120139

121-
html = Templates.extra_template(config, title, modules,
140+
html = Templates.extra_template(config, options.title, modules,
122141
exceptions, protocols, link_headers(content))
123142

124-
File.write!("#{output}/#{file_name}.html", html)
125-
{file_name, title, extract_headers(content)}
143+
output = "#{options.output}/#{options.output_file_name}.html"
144+
145+
if File.regular? output do
146+
IO.puts "warning: file #{Path.basename output} already exists"
147+
end
148+
149+
File.write!(output, html)
150+
151+
{options.output_file_name, options.title, extract_headers(content)}
126152
else
127153
raise ArgumentError, "file format not recognized, allowed format is: .md"
128154
end
129155
end
130156

131-
@h2_regex ~r/^##([^#].*)$/m
157+
defp valid_extension_name?(input) do
158+
file_ext =
159+
input
160+
|> Path.extname()
161+
|> String.downcase()
162+
163+
if file_ext in [".md"] do
164+
true
165+
else
166+
false
167+
end
168+
end
169+
170+
@h2_regex ~r/^##([^#].*)\n$/m
132171

133172
defp extract_headers(content) do
134173
@h2_regex
@@ -143,8 +182,12 @@ defmodule ExDoc.Formatter.HTML do
143182
end)
144183
end
145184

185+
defp input_to_title(input) do
186+
input |> Path.basename() |> Path.rootname()
187+
end
188+
146189
defp title_to_filename(title) do
147-
"extra-" <> (title |> String.replace(" ", "-") |> String.downcase)
190+
title |> String.replace(" ", "-") |> String.downcase()
148191
end
149192

150193
defp header_to_id(header) do

lib/ex_doc/formatter/html/templates/not_found_template.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<p>Sorry, but the page you were trying to get to, does not exist. You
77
may want to try searching this site using the sidebar or using our
8-
<a href="extra-api-reference.html" title="API Reference">API Reference</a> page to find what
8+
<a href="api-reference.html" title="API Reference">API Reference</a> page to find what
99
you were looking for.</p>
1010

1111
<%= footer_template(config) %>

lib/mix/tasks/docs.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ defmodule Mix.Tasks.Docs do
4040
Ignored if `:source_url_pattern` is provided; default: master.
4141
4242
* `:main` - main page of the documentation. It may be a module or a
43-
generated page, like "Plug" or "extra-api-reference";
44-
default: "extra-api-reference" when --formatter is "html".
43+
generated page, like "Plug" or "api-reference";
44+
default: "api-reference" when --formatter is "html".
4545
4646
* `:logo` - Path to the image logo of the project (only PNG or JPEG accepted)
4747
The image size will be 64x64 when --formatter is "html".

test/ex_doc/formatter/html_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ defmodule ExDoc.Formatter.HTMLTest do
5656
assert File.regular?("#{output_dir}/CompiledWithDocs.Nested.html")
5757

5858
content = File.read!("#{output_dir}/index.html")
59-
assert content =~ ~r{<meta http-equiv="refresh" content="0; url=extra-api-reference.html">}
59+
assert content =~ ~r{<meta http-equiv="refresh" content="0; url=api-reference.html">}
6060
end
6161

6262
test "check headers for index.html and module pages" do
@@ -139,14 +139,14 @@ defmodule ExDoc.Formatter.HTMLTest do
139139
assert content =~ ~s("modules":[])
140140
assert content =~ ~s("exceptions":[])
141141
assert content =~ ~s("protocols":[])
142-
assert content =~ ~s("extras":[{"id":"extra-api-reference","title":"API Reference","headers":[]},)
143-
assert content =~ ~s({"id":"extra-readme","title":"README","headers":[{"id":" Header sample","anchor":"Header-sample"}]})
142+
assert content =~ ~s("extras":[{"id":"api-reference","title":"API Reference","headers":[]},)
143+
assert content =~ ~s({"id":"readme","title":"README","headers":[{"id":" Header sample","anchor":"Header-sample"}]})
144144
end
145145

146146
test "run generates the api reference file" do
147147
generate_docs(doc_config)
148148

149-
content = File.read!("#{output_dir}/extra-api-reference.html")
149+
content = File.read!("#{output_dir}/api-reference.html")
150150
assert content =~ ~r{<a href="CompiledWithDocs.html">CompiledWithDocs</a>}
151151
assert content =~ ~r{<p>moduledoc</p>}
152152
assert content =~ ~r{<a href="CompiledWithDocs.Nested.html">CompiledWithDocs.Nested</a>}
@@ -159,7 +159,7 @@ defmodule ExDoc.Formatter.HTMLTest do
159159
content = File.read!("#{output_dir}/index.html")
160160
assert content =~ ~r{<meta http-equiv="refresh" content="0; url=README.html">}
161161

162-
content = File.read!("#{output_dir}/extra-readme.html")
162+
content = File.read!("#{output_dir}/readme.html")
163163
assert content =~ ~r{<title>README [^<]*</title>}
164164
assert content =~ ~r{<h2 id="Header-sample"> Header sample</h2>}
165165
assert content =~ ~r{<a href="RandomError.html"><code>RandomError</code>}
@@ -176,12 +176,12 @@ defmodule ExDoc.Formatter.HTMLTest do
176176

177177
test "run normalizes options" do
178178
# 1. Check for output dir having trailing "/" stripped
179-
# 2. Check for default [main: "extra-api-reference"]
179+
# 2. Check for default [main: "api-reference"]
180180
generate_docs doc_config(output: "#{output_dir}//", main: nil)
181181

182182
content = File.read!("#{output_dir}/index.html")
183-
assert content =~ ~r{<meta http-equiv="refresh" content="0; url=extra-api-reference.html">}
184-
assert File.regular?("#{output_dir}/extra-api-reference.html")
183+
assert content =~ ~r{<meta http-equiv="refresh" content="0; url=api-reference.html">}
184+
assert File.regular?("#{output_dir}/api-reference.html")
185185

186186
# 3. main as index is not allowed
187187
config = doc_config([main: "index"])

0 commit comments

Comments
 (0)