From 7ec68e371395db613c853146872b294008cd0391 Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Sat, 22 Jan 2022 20:19:31 +0530 Subject: [PATCH] Create library to find and read the docspec file --- docspec.asd | 8 ++++++++ lib/docspec.org | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 docspec.asd create mode 100644 lib/docspec.org diff --git a/docspec.asd b/docspec.asd new file mode 100644 index 0000000..6f71ed0 --- /dev/null +++ b/docspec.asd @@ -0,0 +1,8 @@ +(defsystem docspec + :version "0.0.1" + :serial t + :license "Unlicense" + :author "contrapunctus " + :description "A standard, predictable interface to acces the four types of documentation for a project." + :defsystem-depends-on ("literate-lisp") + :components ((:org "lib/docspec"))) diff --git a/lib/docspec.org b/lib/docspec.org new file mode 100644 index 0000000..a7da66d --- /dev/null +++ b/lib/docspec.org @@ -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: