Compare commits

...

3 Commits

Author SHA1 Message Date
TakeV fc895ad637
Add rendering module for the server 2023-12-17 01:26:43 -05:00
TakeV 6e64bd9d2f
Add initial routing code generation 2023-12-17 00:53:25 -05:00
TakeV 0ad70e4ada
Add procedure to get the uri of a particular doc
My thinking is that we can generate the URIs for every doc,
then use that to wire up the logic for the routing table
2023-12-17 00:23:08 -05:00
3 changed files with 41 additions and 1 deletions

View File

@ -1,11 +1,13 @@
(define-module (guile-docs docs)
#:use-module (srfi srfi-9)
#:use-module (web uri)
#:export (make-doc
doc?
doc-module
doc-symbol
doc-documentation
docs-in-module))
docs-in-module
document-uri))
(define-record-type <doc>
(make-doc module symbol documentation)
@ -14,6 +16,15 @@
(symbol doc-symbol)
(documentation doc-documentation))
(define (document-uri doc)
"Returns the URI for the provided <doc> argument"
(when (doc? doc)
(let ((symbol-list (append (doc-module doc)
(list (doc-symbol doc)))))
(build-uri 'guiledoc
#:path (string-join (map (lambda (x) (symbol->string x))
symbol-list)
"/")))))
(define (docs-in-module module)
"Returns a list of <doc> for each symbol in module mod"

View File

@ -0,0 +1,16 @@
(define-module (guile-docs server rendering)
#:use-module (guile-docs docs)
#:use-module (guile-docs html templates)
#:use-module (haunt html)
#:export (get-renderer-for-data
render-html))
(define (get-renderer-for-data data-payload)
"Returns the renderer for the data-payload"
(cond ((doc? data-payload) render-doc)
(else index-page)))
(define (render-html data-payload)
"Renders the data-payload into HTML. The template used for rendering depends on the type of data-payload."
(let ((renderer (get-renderer-for-data data-payload)))
(sxml->html-string (overall-wrapper (renderer data-payload)))))

View File

@ -0,0 +1,13 @@
(define-module (guile-docs server routing)
#:use-module (guile-docs docs)
#:export (generate-routing-table
default-routing-table))
(define (generate-routing-table)
"Creates an alist of URIs and associated <doc> for the guile namespace"
(let* ((default-module (resolve-interface '(guile)))
(docs (docs-in-module default-module)))
(map (lambda (doc) `(,(document-uri doc) . ,doc))
docs)))
(define default-routing-table (generate-routing-table))