Skip to content

Commit 3423dee

Browse files
committed
Tests
1 parent f3ee30e commit 3423dee

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

lib/ex_doc/config.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule ExDoc.Config do
4545
project: nil,
4646
redirects: %{},
4747
retriever: ExDoc.Retriever,
48-
search: [%{name: "Default", help: "Search in browser", url: "search.html?q="}],
48+
search: [%{name: "Default", help: "In-browser search", url: "search.html?q="}],
4949
skip_undefined_reference_warnings_on:
5050
&__MODULE__.skip_undefined_reference_warnings_on/1,
5151
skip_code_autolink_to: &__MODULE__.skip_code_autolink_to/1,
@@ -314,7 +314,7 @@ defmodule ExDoc.Config do
314314
end
315315

316316
defp normalize_search([]) do
317-
[%{name: "Default", help: "Search in browser", url: "search.html?q="}]
317+
[%{name: "Default", help: "In-browser search", url: "search.html?q="}]
318318
end
319319

320320
defp normalize_search(search) when is_list(search) do

lib/mix/tasks/docs.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ defmodule Mix.Tasks.Docs do
164164
value is the path to redirect to. The extension is omitted in both cases, i.e `%{"old-readme" => "readme"}`.
165165
See the "Changing documentation over time" section below for more.
166166
167+
* `:search` - A list of search engine configurations. Each search engine is a map with the following keys:
168+
169+
* `:name` - The display name of the search engine (required)
170+
* `:help` - A help text describing what the search engine does (required)
171+
* `:url` - The optional search URL template, usually ending with `q=`
172+
The default uses ExDoc built-in Lunr's search engine
173+
174+
When multiple search engines are configured, a dropdown selector will appear next to the search bar
175+
allowing users to choose which engine to use. For example:
176+
177+
search: [
178+
%{name: "FooBar", help: "Search on FooBar", url: "https://example.com/?q="},
179+
%{name: "Local", help: "In-browser search"}
180+
]
181+
182+
By default, the built-in Lunr's search engine is configured. If only one search engine
183+
is configured, the dropdown selector will be hidden.
184+
167185
* `:skip_undefined_reference_warnings_on` - ExDoc warns when it can't create a `Mod.fun/arity`
168186
reference in the current project docs (for example, because of a typo). This option controls when to
169187
skip such warnings. This option can be a list of strings that will be checked for exact matches,

test/ex_doc/config_test.exs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,38 @@ defmodule ExDoc.ConfigTest do
166166
describe "normalizes search" do
167167
test "defaults to local search" do
168168
config = build([])
169-
assert config.search == [%{name: "Default", help: "Search in browser", url: "search.html?q="}]
169+
170+
assert config.search == [
171+
%{name: "Default", help: "In-browser search", url: "search.html?q="}
172+
]
170173
end
171174

172175
test "accepts list of maps with name, help, and url" do
173-
config = build(search: [
174-
%{name: "Google", help: "Search using Google", url: "https://google.com/?q="},
175-
%{name: "Local", help: "Search locally", url: "search.html?q="}
176-
])
176+
config =
177+
build(
178+
search: [
179+
%{name: "Google", help: "Search using Google", url: "https://google.com/?q="},
180+
%{name: "Local", help: "Search locally", url: "search.html?q="}
181+
]
182+
)
177183

178184
assert config.search == [
179-
%{name: "Google", help: "Search using Google", url: "https://google.com/?q="},
180-
%{name: "Local", help: "Search locally", url: "search.html?q="}
181-
]
185+
%{name: "Google", help: "Search using Google", url: "https://google.com/?q="},
186+
%{name: "Local", help: "Search locally", url: "search.html?q="}
187+
]
182188
end
183189

184190
test "defaults url to search.html?q= when not provided" do
185-
config = build(search: [
186-
%{name: "Default", help: "Search in browser"}
187-
])
191+
config =
192+
build(
193+
search: [
194+
%{name: "Default", help: "In-browser search"}
195+
]
196+
)
188197

189-
assert config.search == [%{name: "Default", help: "Search in browser", url: "search.html?q="}]
198+
assert config.search == [
199+
%{name: "Default", help: "In-browser search", url: "search.html?q="}
200+
]
190201
end
191202

192203
test "raises on invalid search config" do

test/ex_doc/formatter/html/templates_test.exs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do
8181

8282
describe "sidebar" do
8383
test "renders search engines when multiple are configured", context do
84-
config = doc_config(context, search: [
85-
%{name: "Google", help: "Search using Google", url: "https://google.com/?q="},
86-
%{name: "Local", help: "Search locally", url: "search.html?q="}
87-
])
84+
config =
85+
doc_config(context,
86+
search: [
87+
%{name: "Google", help: "Search using Google", url: "https://google.com/?q="},
88+
%{name: "Local", help: "Search locally", url: "search.html?q="}
89+
]
90+
)
8891

8992
content = Templates.sidebar_template(config, :extra)
9093

@@ -96,9 +99,12 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do
9699
end
97100

98101
test "renders search engine when only one is configured", context do
99-
config = doc_config(context, search: [
100-
%{name: "Default", help: "Search in browser", url: "search.html?q="}
101-
])
102+
config =
103+
doc_config(context,
104+
search: [
105+
%{name: "Default", help: "In-browser search", url: "search.html?q="}
106+
]
107+
)
102108

103109
content = Templates.sidebar_template(config, :extra)
104110

0 commit comments

Comments
 (0)