A website for producing interactive charts without writing a single line of code. Built with Common Lisp and Python. https://charts.craigoates.net
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.
 
 
 
 

73 lines
2.3 KiB

;; (in-package :cl-user)
(defpackage hot-line.view
(:use :cl)
(:import-from :hot-line.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 :hot-line.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 hot-line.djula
(:use :cl)
(:import-from :hot-line.config
:config
:appenv
:developmentp
:productionp)
(:import-from :caveman2
:url-for))
;;; '(in-package' line added after default Caveman set-up. Needed for
;;; custom filters and functions. Not part of default Caveman set-up.
(in-package #:hot-line.djula)
(setf djula:*djula-execute-package* (find-package :hot-line.djula))
(defun insert-umami-script ()
"Outputs the script for my Umami instance (stats.abbether.net).
It provides either the dev. or prod. tracker depending on the
environment this website is running in."
(cond ((equal t (hot-line.config:productionp))
(format
nil
"<script async defer data-website-id=\"ea4c9748-aa78-445e-a0af-f4943f3c16cb\" src=\"https://stats.abbether.net/umami.js\"></script>"))
(t (format nil "<!-- Umami has not been set-up -->"))))
(djula::def-filter :chart-icon (filename)
(if (null filename)
(format nil "/images/file.png")
(let ((chart-type
(subseq filename 0 (search "_" filename))))
(format nil "/images/~a.png" chart-type))))