Skip to content

Commit 6aee91f

Browse files
committed
feat(abbr): overwrite search abbreviation, default to first two chars of project name
1 parent 080280c commit 6aee91f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ Options:
6767
- `--name`: Overwrite the project name when naming the docset.
6868
The name defaults to the project name, or for umbrella apps,
6969
the name of the directory.
70+
- `--abbr`: Overwrite the abbreviation for searching the docs.
71+
Defaults to the first two characters of the project name.
72+
Note that changing the abbreviation of the app requires
73+
deleting the docset entirely from Dash (via the preferneces pane)
74+
and likely running `mix docs.dash --open` to force the docset to re-index.
7075

7176
# Hacking ExDocs into Dash Docs
7277

lib/docset.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ defmodule ExDash.Docset do
120120
<dict>
121121
<key>CFBundleIdentifier</key> <string>{{CONFIG_PROJECT}}-{{CONFIG_VERSION}}</string>
122122
<key>CFBundleName</key> <string>{{CONFIG_PROJECT}} {{CONFIG_VERSION}}</string>
123-
<key>DocSetPlatformFamily</key> <string>{{CONFIG_PROJECT}}</string>
123+
<key>DocSetPlatformFamily</key> <string>{{CONFIG_PROJECT_ABBREV}}</string>
124124
<key>isDashDocset</key> <true/>
125125
<key>isJavaScriptEnabled</key> <true/>
126126
<key>dashIndexFilePath</key> <string>index.html</string>
@@ -138,9 +138,19 @@ defmodule ExDash.Docset do
138138
version
139139
end
140140

141+
abbreviation =
142+
case Store.get(:abbreviation) do
143+
nil ->
144+
name |> String.slice(0, 2)
145+
146+
abbr ->
147+
abbr
148+
end
149+
141150
@info_plist_template
142151
|> String.replace("{{CONFIG_PROJECT}}", name)
143152
|> String.replace("{{CONFIG_VERSION}}", version)
153+
|> String.replace("{{CONFIG_PROJECT_ABBREV}}", abbreviation)
144154
end
145155

146156
end

lib/mix/tasks/dash.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ defmodule Mix.Tasks.Docs.Dash do
1919
Defaults to true unless the docset exists in the `/doc` dir before the run.
2020
* `--name NAME`: names the docset something other than the app name.
2121
Defaults to the project name, or (if an umbrella app) the `cwd` of the mix task
22+
* `--abbr ABBREVIATION`: the default abbreviation to search for your docs with.
23+
Default: first two characters of the project name. (i.e. `ex` for `ex_dash`).
2224
2325
"""
2426
@spec run(args) :: String.t
@@ -29,9 +31,13 @@ defmodule Mix.Tasks.Docs.Dash do
2931
name =
3032
Keyword.get(opts, :name)
3133

34+
abbr =
35+
Keyword.get(opts, :abbr)
36+
3237
Store.start_link()
3338

3439
Store.set(:name, name)
40+
Store.set(:abbreviation, abbr)
3541

3642
[doc_set_path] =
3743
Docs.run(["-f", ExDash])

0 commit comments

Comments
 (0)