Recently Written · git

gendocs

Simple document generation library.

git clone https://github.com/equwal/gendocs

Log | Files | Refs


gendocs.lisp (1507 bytes)

1 (in-package :cl-user)
2 
3 (defpackage #:gendocs
4   (:use #:cl #:docparser)
5   (:export #:gendocs))
6 
7 (in-package #:gendocs)
8 
9 (define-symbol-macro nl (format nil "~%"))
10 (defun gendocs (package template output &optional (template-flag "<TEMPL>"))
11   (file-replace template-flag (md-docstrings package) template output))
12 (defun slurp (file)
13   (let ((str (make-array 0 :element-type 'character :adjustable t :fill-pointer 0)))
14     (with-open-file (i file)
15       (loop for x = #1=(read-line i nil nil) then #1#
16             do (when x (setf str (concatenate 'string str x nl)))
17             until (not x)))
18     str))
19 
20 (defun md-docstrings (package)
21   (let ((col nil))
22     (do-packages (package (parse package))
23       (do-nodes (n package)
24         (push (format nil "~%") col)
25         (push (node-docstring n) col)
26         (push (format nil "~%") col)
27         (push (format nil "~%") col)
28         (push "`" col)
29         (push (symbol-name (node-name n)) col)
30         (push "`" col)
31         (push (format nil "~%") col)))
32     (print col)
33     (apply #'concatenate 'string col)))
34 (defun file-replace (from to filein fileout)
35   (with-open-file (i filein)
36     (let ((str (slurp i)))
37       (with-open-file (o fileout :direction :output :if-exists :overwrite)
38         (write-string (str-replace from to str) o)))))
39 (defun str-replace (from to source)
40   (let ((loc (search from source)))
41     (concatenate 'string
42                  (subseq source 0 loc)
43                  to
44                  (subseq source (+ loc (length from))))))