Skip to content

Commit 7e9c8cc

Browse files
committed
small change to API layouting; better use of vertical screen space
1 parent c7a606c commit 7e9c8cc

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

content/api/gen-docs.janet

+34-9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@
7272
(string "https://github.com/janet-lang/janet/blob/" ver "/"
7373
(if (= "boot.janet" file) "src/boot/boot.janet" file) "#L" line))
7474

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+
7597
(defn- emit-item
7698
"Generate documentation for one entry."
7799
[key env-entry]
@@ -86,20 +108,23 @@
86108
(type val))
87109
docstring (remove-extra-spaces docstring)
88110
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)]
90113
{:tag "div" "class" "binding"
91-
:content [{:tag "span" "class" "binding-sym" "id" key :content key} " "
114+
:content [
92115
{: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"}}] []) " "
116+
{:tag "span" "class" "binding-signature" "id" key :content [
117+
"(" module {:tag "span" "class" "binding-key" :content symbol} " " args ")"]}
97118
{:tag "pre" "class" "binding-text" :content (or docstring "")}
98-
;(if example [{:tag "div" "class" "example-title" :content "EXAMPLES"}
119+
;(if example [{:tag "div" "class" "example-title" :content "Example:"}
99120
{:tag "pre" "class" "mendoza-codeblock"
100121
:content {:tag "code" :language (require "janet.syntax") :content (string example)}}] [])
101122

102-
{:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"}]}))
123+
{:tag "span" "class" "binding-links" :content [
124+
{:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"}
125+
" / "
126+
;(if sm [{:tag "a" "href" (source-linker (sm 0) (sm 1)) :content "source"}] []) ]}
127+
]}))
103128

104129
(defn- all-entries
105130
[&opt env]
@@ -137,7 +162,7 @@
137162
[{:tag "a" "href" (string "#" k) :content k} " "]))
138163
(def bindings
139164
(seq [[k entry] :in entries]
140-
[{:tag "hr" :no-close true} (emit-item k entry)]))
165+
[(emit-item k entry)]))
141166
[{:tag "p" :content index} bindings])
142167

143168
(defn gen-prefix

static/css/docpage.css

+21-4
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,46 @@
103103
.binding {
104104
margin: 10px;
105105
font-size: 1rem;
106+
margin-top: 2em;
107+
margin-bottom: 2em;
106108
}
107109

108110
.binding-type {
109-
display: block;
111+
display: inline-block;
110112
font-size: 0.8em;
111113
color: #888;
114+
float: right;
112115
}
113116

114-
.binding-sym {
117+
.binding-signature {
115118
font-family: serif;
116-
font-weight: 600;
119+
display: block;
120+
color: #557;
121+
font-weight: normal;
122+
}
123+
124+
.binding-key {
125+
font-weight: bolder;
126+
color: #000;
117127
}
118128

119129
.binding-text {
120130
color: #444;
121-
margin-top: 14px;
131+
margin-top: 0.5em;
122132
font-family: 'Dosis','Helvetica', sans-serif;
133+
padding-left: 30px;
134+
}
135+
136+
.binding-links {
137+
font-size: 0.8em;
138+
padding-left: 30px;
123139
}
124140

125141
.example-title {
126142
margin-top: 28px;
127143
color: #888;
128144
font-family: 'Dosis','Helvetica', sans-serif;
145+
padding-left: 2em;
129146
}
130147

131148
/* Toc Toggle */

0 commit comments

Comments
 (0)