Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small change to API layouting; better use of vertical screen space #184

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions content/api/gen-docs.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down
25 changes: 21 additions & 4 deletions static/css/docpage.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down