commit 2cbeb5efcdadfe1414a844959e77ada2f23dc741
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 15 Jul 2025 18:52:06 +0100
initial commit: makefile, nix files and test harness
Diffstat:
8 files changed, 148 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,22 @@
+FENNEL?=fennel
+PREFIX?=/usr/local
+NAME?=cripslock
+
+MODULES=main.fnl textile.fnl
+
+%.lua : %.fnl
+ $(FENNEL) --compile $< > $@
+
+$(NAME): $(patsubst %.fnl,%.lua,$(MODULES)) Makefile
+ (echo -e "#!/usr/bin/env lua\n" ; cat main.lua ) > $@
+ chmod +x $@
+
+run:
+ fennel -e '((. (require :main) :run) )'
+
+test:
+ fennel run-tests.fnl $(MODULES)
+
+install:
+ mkdir -p $(PREFIX)/bin $(PREFIX)/
+ cp $(NAME) $(PREFIX)/bin
diff --git a/README.md b/README.md
@@ -0,0 +1,25 @@
+
+read a directory full of markdown files
+https://github.com/jgm/lunamark/blob/master/README.markdown
+
+
+index them by title
+make slugs from titles
+make summaries from frontmatter or first para
+for each hashtag in each file, add it to a list
+
+answer requests:
+
+https://github.com/daurnimator/lua-http/blob/master/examples/serve_dir.lua
+
+
+
+
+- for /, paginate files in rev date order and show summary
+- for /slug, that page
+- for /#tagname, search hashtags for files, paginate summaries
+
+- for /edit/slug, an edit form
+- for /new/, also the edit form but slug is editable as well
+
+- ?content-type=rss on any page produces an rss version of that page
diff --git a/assert.fnl b/assert.fnl
@@ -0,0 +1,32 @@
+;; these are macros; this module should be imported
+;; using import-macros
+
+;; e.g. (import-macros { : expect= } :anoia.assert)
+
+(fn expect [assertion]
+ (let [msg (.. "expectation failed: " (view assertion))]
+ `(when (not ,assertion)
+ (assert false ,msg))))
+
+(fn expect= [actual expected]
+ `(let [view# (. (require :fennel) :view)
+ ve# (view# ,expected)
+ va# (view# ,actual)]
+ (when (not (= ve# va#))
+ (assert false
+ (.. "\nexpected " ve# "\ngot " va#)
+ ))))
+
+(fn expect-near [actual expected]
+ `(let [delta# (math.abs (- ,actual ,expected))
+ e# ,expected
+ a# ,actual]
+ (assert (< delta# 0.00000001)
+ (.. "expected " e# " to be approximately " a#))))
+
+
+(fn define-tests [& body]
+ (when _G.RUNNING_TESTS
+ `(do ,(unpack body))))
+
+{ : define-tests : expect : expect= : expect-near }
diff --git a/default.nix b/default.nix
@@ -0,0 +1,43 @@
+{ stdenv
+, pkg-config
+, buildPackages
+, callPackage
+, fetchFromGitHub
+, fetchurl
+, lib
+, lua53Packages
+, lua5_3
+, makeWrapper
+, writeText
+}:
+let
+ luaPackages = lua53Packages;
+ fennel = luaPackages.fennel;
+ lua = lua5_3.withPackages (ps: with ps; [
+ luafilesystem
+ luaposix
+ readline
+ http
+ markdown
+ ]);
+ pname = "cripslock";
+in stdenv.mkDerivation {
+ inherit pname;
+ version = "0.1";
+ src =./.;
+
+ buildInputs = [
+ lua
+ ];
+ nativeBuildInputs = [
+ makeWrapper
+ fennel
+ ];
+
+ makeFlags = [ "PREFIX=${placeholder "out"}" "NAME=${pname}" ];
+
+ passthru = {
+ inherit lua luaPackages;
+ };
+
+}
diff --git a/main.fnl b/main.fnl
@@ -0,0 +1 @@
+{}
diff --git a/run-tests.fnl b/run-tests.fnl
@@ -0,0 +1,10 @@
+(local fennel (require :fennel))
+(local specials (require :fennel.specials))
+
+(local compiler-env
+ (doto (. (specials.make-compiler-env) :_G)
+ (tset "RUNNING_TESTS" true)))
+
+(each [_ f (ipairs arg)]
+ (print :testing f)
+ (fennel.dofile f { :correlate true :compilerEnv compiler-env }))
diff --git a/shell.nix b/shell.nix
@@ -0,0 +1,9 @@
+with import <nixpkgs> {};
+let
+ package = pkgs.callPackage ./. {};
+in
+package.overrideAttrs(o: {
+ nativeBuildInputs = [ entr ] ++ o.nativeBuildInputs;
+ shellHook = ''
+ '';
+})
diff --git a/textile.fnl b/textile.fnl
@@ -0,0 +1,6 @@
+(import-macros { : define-tests : expect : expect= } :assert)
+
+
+
+
+{}