Create library to find and read the docspec file
This commit is contained in:
parent
a6f4748435
commit
7ec68e3713
|
@ -0,0 +1,8 @@
|
||||||
|
(defsystem docspec
|
||||||
|
:version "0.0.1"
|
||||||
|
:serial t
|
||||||
|
:license "Unlicense"
|
||||||
|
:author "contrapunctus <contrapunctus at disroot dot org>"
|
||||||
|
:description "A standard, predictable interface to acces the four types of documentation for a project."
|
||||||
|
:defsystem-depends-on ("literate-lisp")
|
||||||
|
:components ((:org "lib/docspec")))
|
|
@ -0,0 +1,50 @@
|
||||||
|
# -*- mode: poly-org; -*-
|
||||||
|
#+TITLE: DocSpec
|
||||||
|
#+SUBTITLE: Library to parse docspec files
|
||||||
|
|
||||||
|
#+BEGIN_SRC lisp
|
||||||
|
(in-package :cl)
|
||||||
|
(defpackage :docspec
|
||||||
|
(:use :cl)
|
||||||
|
(:import-from :uiop
|
||||||
|
:directory-files
|
||||||
|
:read-file-string
|
||||||
|
:pathname-parent-directory-pathname
|
||||||
|
:pathname-root)
|
||||||
|
(:export :*preferred-formats*
|
||||||
|
:*docspec-file-name*
|
||||||
|
:list-entries))
|
||||||
|
(in-package :docspec)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC lisp
|
||||||
|
(defvar *preferred-formats* '(:html :pdf :info :org :md :txt)
|
||||||
|
"List of keywords representing user's preferred formats.")
|
||||||
|
|
||||||
|
(defvar *docspec-file-name* "docspec.lisp")
|
||||||
|
|
||||||
|
(defun find-docspec-file ()
|
||||||
|
"Starting from the current directory and descending upwards, find `*docspec-file-name*'."
|
||||||
|
(loop
|
||||||
|
with dir = *default-pathname-defaults*
|
||||||
|
while (not (equal (pathname-root dir) dir))
|
||||||
|
when
|
||||||
|
(loop for file in (directory-files dir)
|
||||||
|
if (and (equal (pathname-name *docspec-file-name*) (pathname-name file))
|
||||||
|
(equal (pathname-type *docspec-file-name*) (pathname-type file)))
|
||||||
|
return file)
|
||||||
|
return it
|
||||||
|
else do (setf dir (pathname-parent-directory-pathname dir))))
|
||||||
|
|
||||||
|
(defun parse (file)
|
||||||
|
(read-from-string (read-file-string file)))
|
||||||
|
|
||||||
|
(defun list-entries (doc-type)
|
||||||
|
"Return a list of entries for DOC-TYPE from FILE.
|
||||||
|
DOC-TYPE must be one of the symbols TUTORIAL, HOWTO, EXPLANATION, or REFERENCE."
|
||||||
|
(rest (assoc doc-type (parse (find-docspec-file)))))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# my-org-src-default-lang: "lisp"
|
||||||
|
# End:
|
Loading…
Reference in New Issue