|
72 | 72 | (string "https://github.com/janet-lang/janet/blob/" ver "/"
|
73 | 73 | (if (= "boot.janet" file) "src/boot/boot.janet" file) "#L" line))
|
74 | 74 |
|
| 75 | +(def splitter |
| 76 | + (peg/compile '{ |
| 77 | + :ws (any (set " \t")) |
| 78 | + :nl (any (set "\r\n")) |
| 79 | + :main (* :ws :signature :ws :nl :ws :body) |
| 80 | + :signature (* (? "(") :ws :mod :sym :ws :args :ws (? ")")) |
| 81 | + :identifier (some (* (not (set " \r\n/)")) 1)) |
| 82 | + :mod (<- (any (* :identifier "/"))) |
| 83 | + :sym (<- :identifier) |
| 84 | + :args (<- (any (* (not (set "\n\r)" )) 1))) |
| 85 | + :body (<- (any 1)) |
| 86 | + })) |
| 87 | + |
| 88 | +(defn- split [key docstring] |
| 89 | + (def key-parts (peg/match splitter key)) |
| 90 | + (def docstring-parts (peg/match splitter docstring)) |
| 91 | + (def module (get key-parts 0)) |
| 92 | + (def symbol (get key-parts 1)) |
| 93 | + (def args (if docstring-parts (docstring-parts 2) "")) |
| 94 | + (def usage (if docstring-parts (docstring-parts 3) docstring)) |
| 95 | + [module symbol args usage]) |
| 96 | + |
75 | 97 | (defn- emit-item
|
76 | 98 | "Generate documentation for one entry."
|
77 | 99 | [key env-entry]
|
|
86 | 108 | (type val))
|
87 | 109 | docstring (remove-extra-spaces docstring)
|
88 | 110 | source-linker (dyn :source-linker janet-source-linker)
|
89 |
| - example (check-example key)] |
| 111 | + example (check-example key) |
| 112 | + [module symbol args docstring] (split key docstring)] |
| 113 | + (print ">> " module " " symbol) |
90 | 114 | {:tag "div" "class" "binding"
|
91 |
| - :content [{:tag "span" "class" "binding-sym" "id" key :content key} " " |
| 115 | + :content [ |
92 | 116 | {:tag "span" "class" "binding-type" :content binding-type} " "
|
93 |
| - ;(if sm [{:tag "span" "class" "binding-type" |
94 |
| - :content {:tag "a" |
95 |
| - "href" (source-linker (sm 0) (sm 1)) |
96 |
| - :content "source"}}] []) " " |
| 117 | + {:tag "span" "class" "binding-signature" "id" key :content [ |
| 118 | + module {:tag "span" "class" "binding-key" :content symbol} " " args]} |
97 | 119 | {:tag "pre" "class" "binding-text" :content (or docstring "")}
|
98 |
| - ;(if example [{:tag "div" "class" "example-title" :content "EXAMPLES"} |
| 120 | + ;(if example [{:tag "div" "class" "example-title" :content "Example:"} |
99 | 121 | {:tag "pre" "class" "mendoza-codeblock"
|
100 | 122 | :content {:tag "code" :language (require "janet.syntax") :content (string example)}}] [])
|
101 | 123 |
|
102 |
| - {:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"}]})) |
| 124 | + {:tag "span" "class" "binding-links" :content [ |
| 125 | + {:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"} |
| 126 | + " / " |
| 127 | + ;(if sm [{:tag "a" "href" (source-linker (sm 0) (sm 1)) :content "source"}] []) ]} |
| 128 | + ]})) |
103 | 129 |
|
104 | 130 | (defn- all-entries
|
105 | 131 | [&opt env]
|
|
137 | 163 | [{:tag "a" "href" (string "#" k) :content k} " "]))
|
138 | 164 | (def bindings
|
139 | 165 | (seq [[k entry] :in entries]
|
140 |
| - [{:tag "hr" :no-close true} (emit-item k entry)])) |
| 166 | + [(emit-item k entry)])) |
141 | 167 | [{:tag "p" :content index} bindings])
|
142 | 168 |
|
143 | 169 | (defn gen-prefix
|
|
0 commit comments