Compare commits

...

9 Commits

Author SHA1 Message Date
TakeV 95c2843175
Add a useful links section to the readme 2024-01-21 18:07:22 -05:00
TakeV 77fc9f6c99
Remove guix from the manifest.scm file
We kinda have to have guix to run it in the first place, no?
2024-01-21 18:06:46 -05:00
TakeV bde327be02
Add get payload for path method 2024-01-04 16:42:15 -05:00
TakeV 6217b13504
Immedately launch web server 2024-01-04 16:41:15 -05:00
TakeV a537c855cf
Rename repl 2024-01-04 16:40:05 -05:00
TakeV 974363cf5a
Add guile utilities to manifest 2023-12-17 02:25:05 -05:00
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
8 changed files with 59 additions and 5 deletions

View File

@ -9,3 +9,6 @@ Like janetdocs or clojuredocs, but for guile!
Either run src_bash{scripts/launch-dev-shell} or run src_bash{guix shell -Df guix.scm -m manifest.scm} to get a developer environment.
manifest.scm is intended for dev tools related programs.
* Resources
** Useful Links
- https://systemreboot.net/post/live-hacking-a-guile-web-server

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))

View File

@ -37,6 +37,14 @@
(define (directory? file-name)
(eq? (stat:type (stat file-name)) 'directory))
(define (get-payload-for-path path routing-table)
"Returns the first payload that matches the routing-table path"
(let ((filtered-table
(filter (lambda (routing-entry)
(not (equal? path (uri-path (car routing-entry)))))
routing-table)))
(cdr (car filtered-table))))
(define (serve-file path)
(define %prefix `(,(getcwd) "public"))
(define (prepend-prefix path) (string-join (append %prefix `(,path)) file-name-separator-string))

View File

@ -2,4 +2,7 @@
;; You can store it in a file that you may then pass to any 'guix' command
;; that accepts a '--manifest' (or '-m') option.
(specifications->manifest (list "guile-hall" "guix" "git"))
(specifications->manifest (list "guile-colorized"
"guile-hall"
"guile-readline"
"git"))

3
scripts/dev-webserver Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
guile --listen -L . -c '((@ (guile-docs) launch-server))'

View File

@ -1,3 +0,0 @@
#!/bin/sh
guile --listen -L .