diff --git a/content/api/gen-docs.janet b/content/api/gen-docs.janet index af064c33..ffa7c496 100644 --- a/content/api/gen-docs.janet +++ b/content/api/gen-docs.janet @@ -72,6 +72,28 @@ (string "https://github.com/janet-lang/janet/blob/" ver "/" (if (= "boot.janet" file) "src/boot/boot.janet" file) "#L" line)) +(def splitter + (peg/compile '{ + :ws (any (set " \t")) + :nl (any (set "\r\n")) + :main (* :ws :signature :ws :nl :ws :body) + :signature (* (? "(") :ws :mod :sym :ws :args :ws (? ")")) + :identifier (some (* (not (set " \r\n/)")) 1)) + :mod (<- (any (* :identifier "/"))) + :sym (<- :identifier) + :args (<- (any (* (not (set "\n\r)" )) 1))) + :body (<- (any 1)) + })) + +(defn- split [key docstring] + (def key-parts (peg/match splitter key)) + (def docstring-parts (peg/match splitter docstring)) + (def module (get key-parts 0)) + (def symbol (get key-parts 1)) + (def args (if docstring-parts (docstring-parts 2) "")) + (def usage (if docstring-parts (docstring-parts 3) docstring)) + [module symbol args usage]) + (defn- emit-item "Generate documentation for one entry." [key env-entry] @@ -86,20 +108,30 @@ (type val)) docstring (remove-extra-spaces docstring) source-linker (dyn :source-linker janet-source-linker) - example (check-example key)] + example (check-example key) + callable (or (= :macro binding-type) + (= :function binding-type) + (= :cfunction binding-type)) + [module symbol args docstring] (if callable + (split key docstring) + [nil key nil docstring])] {:tag "div" "class" "binding" - :content [{:tag "span" "class" "binding-sym" "id" key :content key} " " + :content [ {:tag "span" "class" "binding-type" :content binding-type} " " - ;(if sm [{:tag "span" "class" "binding-type" - :content {:tag "a" - "href" (source-linker (sm 0) (sm 1)) - :content "source"}}] []) " " + {:tag "span" "class" "binding-signature" "id" key + :content [(when callable "(") module + {:tag "span" "class" "binding-key" :content symbol} " " args + (when callable ")")]} {:tag "pre" "class" "binding-text" :content (or docstring "")} - ;(if example [{:tag "div" "class" "example-title" :content "EXAMPLES"} + ;(if example [{:tag "div" "class" "example-title" :content "Example:"} {:tag "pre" "class" "mendoza-codeblock" :content {:tag "code" :language (require "janet.syntax") :content (string example)}}] []) - {:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"}]})) + {:tag "span" "class" "binding-links" :content [ + {:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"} + " / " + ;(if sm [{:tag "a" "href" (source-linker (sm 0) (sm 1)) :content "source"}] []) ]} + ]})) (defn- all-entries [&opt env] @@ -137,7 +169,7 @@ [{:tag "a" "href" (string "#" k) :content k} " "])) (def bindings (seq [[k entry] :in entries] - [{:tag "hr" :no-close true} (emit-item k entry)])) + [(emit-item k entry)])) [{:tag "p" :content index} bindings]) (defn gen-prefix diff --git a/static/css/docpage.css b/static/css/docpage.css index 6c38019b..03338bae 100644 --- a/static/css/docpage.css +++ b/static/css/docpage.css @@ -103,29 +103,46 @@ .binding { margin: 10px; font-size: 1rem; + margin-top: 2em; + margin-bottom: 2em; } .binding-type { - display: block; + display: inline-block; font-size: 0.8em; color: #888; + float: right; } -.binding-sym { +.binding-signature { font-family: serif; - font-weight: 600; + display: block; + color: #557; + font-weight: normal; +} + +.binding-key { + font-weight: bolder; + color: #000; } .binding-text { color: #444; - margin-top: 14px; + margin-top: 0.5em; font-family: 'Dosis','Helvetica', sans-serif; + padding-left: 30px; +} + +.binding-links { + font-size: 0.8em; + padding-left: 30px; } .example-title { margin-top: 28px; color: #888; font-family: 'Dosis','Helvetica', sans-serif; + padding-left: 2em; } /* Toc Toggle */