2018-12-16 04:19:28 +00:00
|
|
|
# Generate documentation
|
|
|
|
|
|
|
|
(def- prelude
|
2018-12-17 06:41:11 +00:00
|
|
|
```
|
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Janet Language Documentation</title>
|
|
|
|
<meta name="description" content="API Documentation for the janet programming language.">
|
|
|
|
<style>
|
2018-12-17 17:06:50 +00:00
|
|
|
.docstring {
|
2018-12-17 06:41:11 +00:00
|
|
|
font-family: monospace;
|
|
|
|
}
|
2018-12-17 17:06:50 +00:00
|
|
|
.binding-type {
|
|
|
|
color: blue;
|
|
|
|
}
|
|
|
|
.source-map {
|
|
|
|
color: steelblue;
|
|
|
|
font-size: 0.8em;
|
|
|
|
}
|
2018-12-17 06:41:11 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
```)
|
2018-12-16 04:19:28 +00:00
|
|
|
|
|
|
|
(def- postlude
|
2018-12-17 06:41:11 +00:00
|
|
|
```
|
|
|
|
</html>
|
|
|
|
```)
|
2018-12-16 04:19:28 +00:00
|
|
|
|
|
|
|
(def- escapes
|
|
|
|
{10 "<br>"
|
|
|
|
09 " "
|
|
|
|
38 "&"
|
|
|
|
60 "<"
|
|
|
|
62 ">"
|
|
|
|
34 """
|
|
|
|
39 "'"
|
|
|
|
47 "/"})
|
|
|
|
|
|
|
|
(defn- trim-lead
|
|
|
|
"Trim leading newlines"
|
|
|
|
[str]
|
|
|
|
(var i 0)
|
2019-01-07 00:33:27 +00:00
|
|
|
(while (= 10 (get str i)) (++ i))
|
2018-12-16 04:19:28 +00:00
|
|
|
(string/slice str i))
|
|
|
|
|
|
|
|
(defn- html-escape
|
|
|
|
"Escape special characters for HTML encoding."
|
|
|
|
[str]
|
|
|
|
(def buf @"")
|
|
|
|
(loop [byte :in str]
|
2019-01-07 00:33:27 +00:00
|
|
|
(if-let [rep (get escapes byte)]
|
2018-12-16 04:19:28 +00:00
|
|
|
(buffer/push-string buf rep)
|
|
|
|
(buffer/push-byte buf byte)))
|
|
|
|
buf)
|
|
|
|
|
2019-02-16 23:35:29 +00:00
|
|
|
(def- months '("January" "February" "March" "April" "May" "June" "July" "August" "September"
|
|
|
|
"October" "November" "December"))
|
|
|
|
(defn nice-date
|
|
|
|
"Get the current date nicely formatted"
|
|
|
|
[]
|
|
|
|
(let [date (os/date)
|
|
|
|
M (months (date :month))
|
|
|
|
D (+ (date :month-day) 1)
|
|
|
|
Y (date :year)
|
|
|
|
HH (date :hours)
|
|
|
|
MM (date :minutes)
|
|
|
|
SS (date :seconds)]
|
|
|
|
(string/format "%s %d, %d at %.2d:%.2d:%.2d"
|
|
|
|
M D Y HH MM SS)))
|
|
|
|
|
2018-12-17 06:57:09 +00:00
|
|
|
(defn- make-title
|
|
|
|
"Generate title"
|
|
|
|
[]
|
|
|
|
(string "<h1>Janet Core API</h1>"
|
2019-04-01 15:11:15 +00:00
|
|
|
"<p>Version " janet/version "-" janet/build "</p>"
|
2019-02-16 23:38:34 +00:00
|
|
|
"<p>Generated "
|
2019-02-16 23:35:29 +00:00
|
|
|
(nice-date)
|
2019-02-16 23:39:44 +00:00
|
|
|
"</p>"
|
2018-12-17 06:57:09 +00:00
|
|
|
"<hr>"))
|
|
|
|
|
2018-12-17 06:41:11 +00:00
|
|
|
(defn- emit-item
|
|
|
|
"Generate documentation for one entry."
|
|
|
|
[key env-entry]
|
|
|
|
(let [{:macro macro
|
|
|
|
:value val
|
|
|
|
:ref ref
|
2018-12-17 17:06:50 +00:00
|
|
|
:source-map sm
|
2018-12-17 06:41:11 +00:00
|
|
|
:doc docstring} env-entry
|
2019-01-26 15:12:33 +00:00
|
|
|
html-key (html-escape key)
|
2018-12-17 06:41:11 +00:00
|
|
|
binding-type (cond
|
|
|
|
macro :macro
|
2018-12-29 18:07:18 +00:00
|
|
|
ref (string :var " (" (type (get ref 0)) ")")
|
2018-12-17 17:06:50 +00:00
|
|
|
(type val))
|
|
|
|
source-ref (if-let [[path start end] sm]
|
|
|
|
(string "<span class=\"source-map\">" path " (" start ":" end ")</span>")
|
|
|
|
"")]
|
2019-01-26 15:12:33 +00:00
|
|
|
(string "<h2 class=\"binding\"><a id=\"" key "\">" html-key "</a></h2>\n"
|
2018-12-17 17:06:50 +00:00
|
|
|
"<span class=\"binding-type\">" binding-type "</span>\n"
|
|
|
|
"<p class=\"docstring\">" (trim-lead (html-escape docstring)) "</p>\n"
|
|
|
|
source-ref)))
|
2018-12-16 04:19:28 +00:00
|
|
|
|
2018-12-16 18:17:30 +00:00
|
|
|
# Generate parts and print them to stdout
|
2018-12-17 06:41:11 +00:00
|
|
|
(def parts (seq [[k entry]
|
2019-04-16 19:41:45 +00:00
|
|
|
:in (sort (pairs (table/getproto (fiber/getenv (fiber/current)))))
|
2019-01-07 00:33:27 +00:00
|
|
|
:when (and (get entry :doc) (not (get entry :private)))]
|
2018-12-17 06:41:11 +00:00
|
|
|
(emit-item k entry)))
|
2018-12-17 06:57:09 +00:00
|
|
|
(print
|
|
|
|
prelude
|
|
|
|
(make-title)
|
2018-12-17 17:06:50 +00:00
|
|
|
;(interpose "<hr>\n" parts)
|
2018-12-17 06:57:09 +00:00
|
|
|
postlude)
|