mirror of
https://github.com/janet-lang/janet
synced 2025-01-26 23:24:44 +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/*)
|
janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) README.md $(wildcard doc/*)
|
||||||
tar -czvf $@ $^
|
tar -czvf $@ $^
|
||||||
|
|
||||||
|
#########################
|
||||||
|
##### Documentation #####
|
||||||
|
#########################
|
||||||
|
|
||||||
|
docs: build/doc.html
|
||||||
|
|
||||||
|
build/doc.html: $(JANET_TARGET) doc/gendoc.janet
|
||||||
|
$(JANET_TARGET) doc/gendoc.janet > build/doc.html
|
||||||
|
|
||||||
#################
|
#################
|
||||||
##### Other #####
|
##### Other #####
|
||||||
#################
|
#################
|
||||||
@ -183,5 +192,6 @@ uninstall:
|
|||||||
-rm -rf $(INCLUDEDIR)
|
-rm -rf $(INCLUDEDIR)
|
||||||
$(LDCONFIG)
|
$(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)
|
$(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)
|
||||||
|
@ -1,20 +1,25 @@
|
|||||||
# Generate documentation
|
# Generate documentation
|
||||||
|
|
||||||
(def- prelude
|
(def- prelude
|
||||||
```
|
```
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Janet Language Documentation</title>
|
<title>Janet Language Documentation</title>
|
||||||
<meta name="description" content="API Documentation for the janet programming language.">
|
<meta name="description" content="API Documentation for the janet programming language.">
|
||||||
</head>
|
<style>
|
||||||
```)
|
p {
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
```)
|
||||||
|
|
||||||
(def- postlude
|
(def- postlude
|
||||||
```
|
```
|
||||||
</html>
|
</html>
|
||||||
```)
|
```)
|
||||||
|
|
||||||
(def- escapes
|
(def- escapes
|
||||||
{10 "<br>"
|
{10 "<br>"
|
||||||
@ -43,21 +48,24 @@
|
|||||||
(buffer/push-byte buf byte)))
|
(buffer/push-byte buf byte)))
|
||||||
buf)
|
buf)
|
||||||
|
|
||||||
(defn- gen-one
|
(defn- emit-item
|
||||||
"Generate documentation for a binding. Returns an
|
"Generate documentation for one entry."
|
||||||
html fragment."
|
[key env-entry]
|
||||||
[key docstring]
|
(let [{:macro macro
|
||||||
(if-let [index (string/find "\n" docstring)]
|
:value val
|
||||||
(let [first-line (html-escape (string/slice docstring 0 index))
|
:ref ref
|
||||||
rest (html-escape (trim-lead (string/slice docstring (inc index))))]
|
:doc docstring} env-entry
|
||||||
(string "<h2>" first-line "</h2>\n"
|
binding-type (cond
|
||||||
"<p>" rest "</p>\n"))
|
macro :macro
|
||||||
(string "<h2>" (html-escape key) "</h2>\n"
|
ref (string :var " (" (type ref.0) ")")
|
||||||
"<p>" (html-escape docstring) "</p>\n")))
|
(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
|
# 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)))
|
:in (sort (pairs (table/getproto _env)))
|
||||||
:when (and d (not p))]
|
:when (and entry:doc (not entry:private))]
|
||||||
(gen-one k d)))
|
(emit-item k entry)))
|
||||||
(print prelude ;parts postlude)
|
(print prelude ;(interpose "<hr>" parts) postlude)
|
||||||
|
@ -1074,8 +1074,18 @@ value, one key will be ignored."
|
|||||||
(if (not x)
|
(if (not x)
|
||||||
(print "symbol " sym " not found.")
|
(print "symbol " sym " not found.")
|
||||||
(do
|
(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)
|
(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
|
(defmacro doc
|
||||||
"Shows documentation for the given symbol."
|
"Shows documentation for the given symbol."
|
||||||
@ -1176,15 +1186,15 @@ value, one key will be ignored."
|
|||||||
ret)
|
ret)
|
||||||
|
|
||||||
(defn all
|
(defn all
|
||||||
[pred xs]
|
|
||||||
"Returns true if all xs are truthy, otherwise the first false or nil value."
|
"Returns true if all xs are truthy, otherwise the first false or nil value."
|
||||||
|
[pred xs]
|
||||||
(var ret true)
|
(var ret true)
|
||||||
(loop [x :in xs :while ret] (set ret (pred x)))
|
(loop [x :in xs :while ret] (set ret (pred x)))
|
||||||
ret)
|
ret)
|
||||||
|
|
||||||
(defn some
|
(defn some
|
||||||
[pred xs]
|
|
||||||
"Returns false if all xs are false or nil, otherwise returns the first true value."
|
"Returns false if all xs are false or nil, otherwise returns the first true value."
|
||||||
|
[pred xs]
|
||||||
(var ret nil)
|
(var ret nil)
|
||||||
(loop [x :in xs :while (not ret)] (if-let [y (pred x)] (set ret y)))
|
(loop [x :in xs :while (not ret)] (if-let [y (pred x)] (set ret y)))
|
||||||
ret)
|
ret)
|
||||||
|
@ -47,7 +47,7 @@ struct IOFile {
|
|||||||
static int janet_io_gc(void *p, size_t len);
|
static int janet_io_gc(void *p, size_t len);
|
||||||
|
|
||||||
JanetAbstractType janet_io_filetype = {
|
JanetAbstractType janet_io_filetype = {
|
||||||
":core.file",
|
":core/file",
|
||||||
janet_io_gc,
|
janet_io_gc,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
@ -609,7 +609,7 @@ static int parsergc(void *p, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static JanetAbstractType janet_parse_parsertype = {
|
static JanetAbstractType janet_parse_parsertype = {
|
||||||
":core.parser",
|
":core/parser",
|
||||||
parsergc,
|
parsergc,
|
||||||
parsermark
|
parsermark
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user