Skip to content

Commit a8068f1

Browse files
committed
Fix #10: source link template
1 parent 362f065 commit a8068f1

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

API.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ API namespace for quickdoc.
2121
Generate API docs. Options:
2222
* `:github/repo` - a link like `https://github.com/borkdude/quickdoc`
2323
* `:git/branch` - branch name for source links, default to `"main"`
24+
* `:source-uri` - source link template. Supports `{row}`, `{end-row}`, `{col}`, `{end-col}`, `{filename}`, `{branch}`.
2425
* `:outfile` - file where API docs are written, or falsey if you don't need a file. Defaults to `"API.md"`
2526
* `:source-paths` - sources that are scanned for vars. Defaults to `["src"]`.
2627
* `:toc` - generate table of contents. Defaults to `true`.
2728
* `:var-links` - generate links to vars within the same namespace. Defauls to `true`.
2829
* `:overrides` - overrides in the form `{namespace {:no-doc true var {:no-doc true :doc ...}}}`.
2930

3031
Returns a map containing the generated markdown string under the key `:markdown`.
31-
<br><sub>[source](https://github.com/borkdude/quickdoc/blob/main/src/quickdoc/api.cljc#L9-L66)</sub>
32+
<br><sub>[source](https://github.com/borkdude/quickdoc/blob/main/src/quickdoc/api.cljc#L9-L76)</sub>

bb.edn

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
{:pods {clj-kondo/clj-kondo {:version "2022.02.09"}}
1+
{:pods {clj-kondo/clj-kondo {:version "2022.05.31"}}
22
:paths ["src"]
33
:tasks {quickdoc {:requires ([quickdoc.api :as api])
44
:task (api/quickdoc {:git/branch "main"
55
:github/repo "https://github.com/borkdude/quickdoc"
6-
:toc true})}}}
6+
:toc true})}
7+
test {:requires ([quickdoc.api :as api])
8+
:task (api/quickdoc {:git/branch "main"
9+
:source-uri "https://dev.azure.com/company/_git/project?path={filename}&version=GBmain&_a=contents&line={row}&lineEnd={end-row}&lineStartColumn={col}&lineEndColumn={end-col}&lineStyle=plain"
10+
:toc true
11+
:outfile "API2.md"})}}}

src/quickdoc/api.cljc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"Generate API docs. Options:
1111
* `:github/repo` - a link like `https://github.com/borkdude/quickdoc`
1212
* `:git/branch` - branch name for source links, default to `\"main\"`
13+
* `:source-uri` - source link template. Supports `{row}`, `{end-row}`, `{col}`, `{end-col}`, `{filename}`, `{branch}`.
1314
* `:outfile` - file where API docs are written, or falsey if you don't need a file. Defaults to `\"API.md\"`
1415
* `:source-paths` - sources that are scanned for vars. Defaults to `[\"src\"]`.
1516
* `:toc` - generate table of contents. Defaults to `true`.

src/quickdoc/impl.clj

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,25 @@
2525
(let [first-sentence (-> (str/split first-line #"\. ") first)]
2626
(mini-markdown (subs first-sentence 0 (min (count first-sentence) 80))))))
2727

28-
(defn var-source [var {:keys [github/repo git/branch]}]
29-
(format
30-
"<sub>[source](%s/blob/%s/%s#L%s-L%s)</sub>"
31-
repo
32-
branch
33-
(:filename var)
34-
(:row var)
35-
(:end-row var)))
28+
(defn var-source [var {:keys [github/repo git/branch
29+
source-uri]}]
30+
(cond repo
31+
(format
32+
"<sub>[source](%s/blob/%s/%s#L%s-L%s)</sub>"
33+
repo
34+
branch
35+
(:filename var)
36+
(:row var)
37+
(:end-row var))
38+
source-uri
39+
(->
40+
source-uri
41+
(str/replace "{filename}" (:filename var))
42+
(str/replace "{branch}" branch)
43+
(str/replace "{row}" (str (:row var)))
44+
(str/replace "{col}" (str (:col var)))
45+
(str/replace "{end-row}" (str (:end-row var)))
46+
(str/replace "{end-col}" (str (:end-col var))))))
3647

3748
(defn print-var [var _source {:keys [collapse-vars] :as opts}]
3849
(when (var-filter var)

0 commit comments

Comments
 (0)