mirror of
https://github.com/janet-lang/janet
synced 2025-01-12 00:20:26 +00:00
Add docs target to generate documentation.
This commit is contained in:
parent
05a957c524
commit
131ee29190
12
Makefile
12
Makefile
@ -159,6 +159,15 @@ build/janet-%.tar.gz: $(JANET_TARGET) src/include/janet/janet.h \
|
||||
janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) README.md $(wildcard doc/*)
|
||||
tar -czvf $@ $^
|
||||
|
||||
#########################
|
||||
##### Documentation #####
|
||||
#########################
|
||||
|
||||
docs: build/doc.html
|
||||
|
||||
build/doc.html: $(JANET_TARGET) doc/gendoc.janet
|
||||
$(JANET_TARGET) doc/gendoc.janet > build/doc.html
|
||||
|
||||
#################
|
||||
##### Other #####
|
||||
#################
|
||||
@ -183,5 +192,6 @@ uninstall:
|
||||
-rm -rf $(INCLUDEDIR)
|
||||
$(LDCONFIG)
|
||||
|
||||
.PHONY: clean install repl debug valgrind test valtest emscripten dist uninstall \
|
||||
.PHONY: clean install repl debug valgrind test \
|
||||
valtest emscripten dist uninstall docs \
|
||||
$(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)
|
||||
|
@ -1,20 +1,25 @@
|
||||
# Generate documentation
|
||||
|
||||
(def- prelude
|
||||
```
|
||||
<!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.">
|
||||
</head>
|
||||
```)
|
||||
```
|
||||
<!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>
|
||||
p {
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
```)
|
||||
|
||||
(def- postlude
|
||||
```
|
||||
</html>
|
||||
```)
|
||||
```
|
||||
</html>
|
||||
```)
|
||||
|
||||
(def- escapes
|
||||
{10 "<br>"
|
||||
@ -43,21 +48,24 @@
|
||||
(buffer/push-byte buf byte)))
|
||||
buf)
|
||||
|
||||
(defn- gen-one
|
||||
"Generate documentation for a binding. Returns an
|
||||
html fragment."
|
||||
[key docstring]
|
||||
(if-let [index (string/find "\n" docstring)]
|
||||
(let [first-line (html-escape (string/slice docstring 0 index))
|
||||
rest (html-escape (trim-lead (string/slice docstring (inc index))))]
|
||||
(string "<h2>" first-line "</h2>\n"
|
||||
"<p>" rest "</p>\n"))
|
||||
(string "<h2>" (html-escape key) "</h2>\n"
|
||||
"<p>" (html-escape docstring) "</p>\n")))
|
||||
(defn- emit-item
|
||||
"Generate documentation for one entry."
|
||||
[key env-entry]
|
||||
(let [{:macro macro
|
||||
:value val
|
||||
:ref ref
|
||||
:doc docstring} env-entry
|
||||
binding-type (cond
|
||||
macro :macro
|
||||
ref (string :var " (" (type ref.0) ")")
|
||||
(type val))]
|
||||
(string "<h2>" (html-escape key) "</h2>"
|
||||
"<span style=\"color:blue;\">" binding-type "</span>"
|
||||
"<p>" (trim-lead (html-escape docstring)) "</p>")))
|
||||
|
||||
# Generate parts and print them to stdout
|
||||
(def parts (seq [[k {:doc d :private p}]
|
||||
(def parts (seq [[k entry]
|
||||
:in (sort (pairs (table/getproto _env)))
|
||||
:when (and d (not p))]
|
||||
(gen-one k d)))
|
||||
(print prelude ;parts postlude)
|
||||
:when (and entry:doc (not entry:private))]
|
||||
(emit-item k entry)))
|
||||
(print prelude ;(interpose "<hr>" parts) postlude)
|
||||
|
@ -1074,8 +1074,18 @@ value, one key will be ignored."
|
||||
(if (not x)
|
||||
(print "symbol " sym " not found.")
|
||||
(do
|
||||
(def bind-type
|
||||
(string " "
|
||||
(cond
|
||||
x:ref (string :var " (" (type (get x:ref 0)) ")")
|
||||
x:macro :macro
|
||||
(type x:value))
|
||||
"\n"))
|
||||
(def d x:doc)
|
||||
(print "\n\n" (if d (doc-format d) "no documentation found.") "\n\n"))))
|
||||
(print "\n\n"
|
||||
(if d bind-type "")
|
||||
(if d (doc-format d) "no documentation found.")
|
||||
"\n\n"))))
|
||||
|
||||
(defmacro doc
|
||||
"Shows documentation for the given symbol."
|
||||
@ -1176,15 +1186,15 @@ value, one key will be ignored."
|
||||
ret)
|
||||
|
||||
(defn all
|
||||
[pred xs]
|
||||
"Returns true if all xs are truthy, otherwise the first false or nil value."
|
||||
[pred xs]
|
||||
(var ret true)
|
||||
(loop [x :in xs :while ret] (set ret (pred x)))
|
||||
ret)
|
||||
|
||||
(defn some
|
||||
[pred xs]
|
||||
"Returns false if all xs are false or nil, otherwise returns the first true value."
|
||||
[pred xs]
|
||||
(var ret nil)
|
||||
(loop [x :in xs :while (not ret)] (if-let [y (pred x)] (set ret y)))
|
||||
ret)
|
||||
|
@ -47,7 +47,7 @@ struct IOFile {
|
||||
static int janet_io_gc(void *p, size_t len);
|
||||
|
||||
JanetAbstractType janet_io_filetype = {
|
||||
":core.file",
|
||||
":core/file",
|
||||
janet_io_gc,
|
||||
NULL
|
||||
};
|
||||
|
@ -609,7 +609,7 @@ static int parsergc(void *p, size_t size) {
|
||||
}
|
||||
|
||||
static JanetAbstractType janet_parse_parsertype = {
|
||||
":core.parser",
|
||||
":core/parser",
|
||||
parsergc,
|
||||
parsermark
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user