Public archive for the Return to Ritherdon project.
https://www.nicolaellisandritherdon.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
(in-package #:cl-user) |
|
(defpackage #:ritherdon-archive.view |
|
(:use #:cl) |
|
(:import-from #:ritherdon-archive.config |
|
#:*template-directory*) |
|
(:import-from #:caveman2 |
|
#:*response* |
|
#:response-headers) |
|
(:import-from #:djula |
|
#:add-template-directory |
|
#:compile-template* |
|
#:render-template* |
|
#:*djula-execute-package*) |
|
(:import-from #:datafly |
|
:encode-json) |
|
(:export #:render |
|
#:render-json)) |
|
(in-package #:ritherdon-archive.view) |
|
|
|
(djula:add-template-directory *template-directory*) |
|
|
|
(defparameter *template-registry* (make-hash-table :test 'equal)) |
|
|
|
(defun render (template-path &optional env) |
|
(let ((template (gethash template-path *template-registry*))) |
|
(unless template |
|
(setf template (djula:compile-template* (princ-to-string template-path))) |
|
(setf (gethash template-path *template-registry*) template)) |
|
(apply #'djula:render-template* |
|
template nil |
|
env))) |
|
|
|
(defun render-json (object) |
|
(setf (getf (response-headers *response*) :content-type) "application/json") |
|
(encode-json object)) |
|
|
|
|
|
;; |
|
;; Execute package definition |
|
|
|
(defpackage ritherdon-archive.djula |
|
(:use :cl) |
|
(:import-from :ritherdon-archive.config |
|
:config |
|
:appenv |
|
:developmentp |
|
:productionp) |
|
(:import-from :caveman2 |
|
:url-for)) |
|
|
|
(setf djula:*djula-execute-package* (find-package :ritherdon-archive.djula)) |
|
|
|
;; Custom filters and template code added below... |
|
;; ============================================================================= |
|
|
|
;; This filter is for converting Integers used to store Boolean values |
|
;; in a SQLite database. The intended place you will use this filter |
|
;; is in the /software section. The most notable parts being the /add |
|
;; and /edit sections. In the SQLite database, I have set: |
|
;; - 0 => false |
|
;; - 1 => true. |
|
;; In this case, if the `VALUE' is not 1, it is always false (I.E. 0). |
|
(djula::def-filter :integer-to-checkbox (value) |
|
(format nil "~S" (if (= 1 value) "on" "off")))
|
|
|