From 96fa9c7033dc86286badb644519e30b9398947fb Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Fri, 7 Jan 2022 11:59:53 +0000 Subject: [PATCH] Updated JS dependencies; fixed the problem with pluggable extensions. --- project.clj | 14 ++-- resources/public/content/Extensible Markup.md | 8 ++- src/smeagol/extensions/geocsv.clj | 3 +- src/smeagol/extensions/mermaid.clj | 3 +- src/smeagol/extensions/photoswipe.clj | 65 ++++++++++--------- src/smeagol/extensions/test.clj | 3 +- src/smeagol/extensions/vega.clj | 3 +- 7 files changed, 55 insertions(+), 44 deletions(-) diff --git a/project.clj b/project.clj index 1c61b1f..2d0f2e1 100644 --- a/project.clj +++ b/project.clj @@ -54,15 +54,15 @@ [lein-npm "0.6.2"] [lein-ring "0.12.5" :exclusions [org.clojure/clojure]]] - :npm {:dependencies [[simplemde "1.11.2"] - [vega "5.9.0"] - [vega-embed "6.2.2"] - [vega-lite "4.1.1"] - [mermaid "8.4.6"] + :npm {:dependencies [[geocsv-js "simon-brooke/geocsv-js#3a34ba7"] + [mermaid "8.13.8"] [photoswipe "4.1.3"] + [simplemde "1.11.2"] [showdown "1.9.1"] - [tablesort "5.2.0"] - [geocsv-js "simon-brooke/geocsv-js#3a34ba7"]] + [tablesort "5.3.0"] + [vega "5.21.0"] + [vega-embed "6.20.5"] + [vega-lite "5.2.0"]] :root "resources/public/vendor"} :docker {:image-name "simonbrooke/smeagol" diff --git a/resources/public/content/Extensible Markup.md b/resources/public/content/Extensible Markup.md index 2fa2c75..dae25d7 100644 --- a/resources/public/content/Extensible Markup.md +++ b/resources/public/content/Extensible Markup.md @@ -146,7 +146,9 @@ followed by three backticks on a line by themselves. There is an [[Example galle ## Writing your own custom formatters -A custom formatter is simply a Clojure function which takes a string and an integer as arguments and produces a string as output. The string is the text the user has typed into their markdown; the integer is simply a number you can use to keep track of which addition to the page this is, in order, for example, to fix up some JavaScript to render it. +A custom formatter is simply a Clojure function which takes a string and an integer as arguments and produces a string as output. The string argument is the text the user has typed into their markdown; the integer is simply a number you can use to keep track of which addition to the page this is, in order, for example, to fix up some JavaScript to render it. + +The string returned should just be the necessary HTML text to add to the page to invoke the formatter. For example, here's the formatter which handles the Vega charts: @@ -165,6 +167,10 @@ For example, here's the formatter which handles the Vega charts: "', vl" index ");\n//]]\n")) + +In order to allow pluggable extensions -- that is, extensions which are not compiled as part of Smeagol but are added as additional classes on the classpath at run time -- every extension function must be written in a namespace which has the `(:gen-class)` directive. + +In principal it should be possible to write extensions in Java, or in other languages which compile for the JVM, but this has not yet been demonstrated. ### Configuring Smeagol to use your formatter diff --git a/src/smeagol/extensions/geocsv.clj b/src/smeagol/extensions/geocsv.clj index 0442ced..101d93a 100644 --- a/src/smeagol/extensions/geocsv.clj +++ b/src/smeagol/extensions/geocsv.clj @@ -3,7 +3,8 @@ smeagol.extensions.geocsv (:require [smeagol.configuration :refer [config]] [smeagol.extensions.utils :refer [resource-url-or-data->data]] - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:gen-class)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; diff --git a/src/smeagol/extensions/mermaid.clj b/src/smeagol/extensions/mermaid.clj index be89f39..a94a305 100644 --- a/src/smeagol/extensions/mermaid.clj +++ b/src/smeagol/extensions/mermaid.clj @@ -2,7 +2,8 @@ :author "Simon Brooke"} smeagol.extensions.mermaid (:require [smeagol.extensions.utils :refer [resource-url-or-data->data]] - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:gen-class)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; diff --git a/src/smeagol/extensions/photoswipe.clj b/src/smeagol/extensions/photoswipe.clj index 6053e2a..8e9dd55 100644 --- a/src/smeagol/extensions/photoswipe.clj +++ b/src/smeagol/extensions/photoswipe.clj @@ -1,7 +1,7 @@ (ns ^{:doc "Photoswipe gallery formatter for Semagol's extendsible markdown format." :author "Simon Brooke"} - smeagol.extensions.photoswipe + smeagol.extensions.photoswipe (:require [clojure.data.json :as json] [clojure.java.io :as cio] [clojure.string :as cs] @@ -14,7 +14,8 @@ [smeagol.configuration :refer [config]] [smeagol.extensions.utils :refer [resource-url-or-data->data uploaded?]] [smeagol.util :refer [content-dir upload-dir]] - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:gen-class)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; @@ -68,11 +69,11 @@ "Simplify a parse-`tree` created by `simple-grammar`, q.v." [tree] (when - (coll? tree) + (coll? tree) (case (first tree) :SLIDES (cons - (simplify (first (rest tree))) - (first (simplify (rest (rest tree))))) + (simplify (first (rest tree))) + (first (simplify (rest (rest tree))))) :SLIDE (remove empty? (map simplify (rest tree))) :title tree :src tree @@ -90,12 +91,12 @@ dimensions (try (when (uploaded? url) (dimensions - (buffered-image - (cio/file upload-dir (fs/base-name url))))) + (buffered-image + (cio/file upload-dir (fs/base-name url))))) (catch Exception x (log/error - "Failed to fetch dimensions of image " - url (.getMessage x)) + "Failed to fetch dimensions of image " + url (.getMessage x)) nil))] (if dimensions (assoc slide :w (first dimensions) :h (nth dimensions 1)) @@ -105,14 +106,14 @@ (defn find-thumb [url thumbsize] (when - (and - (uploaded? url) - thumbsize) + (and + (uploaded? url) + thumbsize) (let [p (str (cio/file "uploads" (name thumbsize) (fs/base-name url))) p' (cio/file content-dir p) r (str (cio/file "content" p))] (if - (and (fs/exists? p') (fs/readable? p')) + (and (fs/exists? p') (fs/readable? p')) r (do (log/warn "Failed to find" thumbsize "thumbnail for" url "at" p') @@ -132,15 +133,15 @@ (let [s' (zipmap (map first slide) (map #(nth % 1) slide)) thumbsizes (:thumbnails config) thumbsize (first - (sort - #(> (%1 thumbsizes) (%2 thumbsizes)) - (keys thumbsizes))) + (sort + #(> (%1 thumbsizes) (%2 thumbsizes)) + (keys thumbsizes))) url (:src s') thumb (find-thumb url thumbsize)] (slide-merge-dimensions - (if thumb - (assoc s' :msrc thumb) - s')))) + (if thumb + (assoc s' :msrc thumb) + s')))) (def process-simple-photoswipe @@ -148,15 +149,15 @@ a sequence of MarkDown image links. This is REALLY expensive to do, we don't want to do it often. Hence memoised." (memoize - (fn - [^String spec ^Integer index] - (process-full-photoswipe - (json/write-str - {:slides (map - process-simple-slide - (simplify (simple-grammar spec))) - :options { :timeToIdle 100 } - :openImmediately true}) index)))) + (fn + [^String spec ^Integer index] + (process-full-photoswipe + (json/write-str + {:slides (map + process-simple-slide + (simplify (simple-grammar spec))) + :options {:timeToIdle 100} + :openImmediately true}) index)))) (defn process-photoswipe @@ -165,7 +166,7 @@ [^String url-or-pswp-spec ^Integer index] (let [data (resource-url-or-data->data url-or-pswp-spec) spec (cs/trim (:data data))] - (if - (cs/starts-with? spec "![") - (process-simple-photoswipe spec index) - (process-full-photoswipe spec index)))) + (if + (cs/starts-with? spec "![") + (process-simple-photoswipe spec index) + (process-full-photoswipe spec index)))) diff --git a/src/smeagol/extensions/test.clj b/src/smeagol/extensions/test.clj index 60aefb9..e53539e 100644 --- a/src/smeagol/extensions/test.clj +++ b/src/smeagol/extensions/test.clj @@ -1,6 +1,7 @@ (ns ^{:doc "Very simple extension for testing the extension processing flow." :author "Simon Brooke"} - smeagol.extensions.test) + smeagol.extensions.test + (:gen-class)) (def process-test-return-value "") diff --git a/src/smeagol/extensions/vega.clj b/src/smeagol/extensions/vega.clj index e4afd0e..0e6be8a 100644 --- a/src/smeagol/extensions/vega.clj +++ b/src/smeagol/extensions/vega.clj @@ -2,7 +2,8 @@ :author "Simon Brooke"} smeagol.extensions.vega (:require [smeagol.extensions.utils :refer [resource-url-or-data->data yaml->json]] - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:gen-class)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;