Skip to content

Commit

Permalink
#47: Something well broken here, but I'm on the right path
Browse files Browse the repository at this point in the history
Fragment indices are being returned instead of fragments, and it does not seem that the extension formatters are being called at all. But... config is definitely improved in the
right direction.
  • Loading branch information
simon-brooke committed Feb 12, 2020
1 parent b191f40 commit 0d686a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[org.clojure/core.memoize "0.5.9"]
[org.clojure/data.json "0.2.6"]
[org.clojure/tools.logging "0.4.0"]
[org.clojure/tools.trace "0.7.10"]
[org.slf4j/slf4j-api "1.7.25"]
[org.slf4j/log4j-over-slf4j "1.7.25"]
[org.slf4j/jul-to-slf4j "1.7.25"]
Expand Down
11 changes: 6 additions & 5 deletions resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
:default-locale "en-GB" ;; default language used for messages
:formatters ;; formatters for processing markdown
;; extensions.
{"vega" smeagol.formatting/process-vega
"vis" smeagol.formatting/process-vega
"mermaid" smeagol.extensions.mermaid/process-mermaid
"backticks" smeagol.formatting/process-backticks
"pswp" smeagol.extensions.photoswipe/process-photoswipe}
{:vega {:formatter "smeagol.extensions.vega/process-vega" }
:vis {:formatter "smeagol.extensions.vega/process-vega" }
:mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid" }
:backticks {:formatter "smeagol.formatting/process-backticks" }
:pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe" }
}
:log-level :info ;; the minimum logging level; one of
;; :trace :debug :info :warn :error :fatal
:js-from :cdnjs ;; where to load JavaScript libraries
Expand Down
2 changes: 1 addition & 1 deletion resources/public/content/Simplified example gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ That's all there is to it - a sequence of image links just as you'd write them a

## The Gallery

This page holds another example Photoswipe gallery, this time using a simpler, Markdown-based specification. Processing this specification takes more work than the full syntax used in the other [Example gallery], so the gallery may be slower to load; but it's much easier to configure.
This page holds another example Photoswipe gallery, this time using a simpler, Markdown-based specification. Processing this specification takes more work than the full syntax used in the other [[Example gallery]], so the gallery may be slower to load; but it's much easier to configure.

```pswp
![Frost on a gate, Laurieston](content/uploads/g1.jpg)
Expand Down
17 changes: 11 additions & 6 deletions src/smeagol/extensions/photoswipe.clj
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,15 @@
;; 1)

(defn process-photoswipe
[^String url-or-pswp-spec ^Integer index]
[^String url-or-pswp-spec ^Integer index]
(log/info "process-photoswipe called with arg1 `"
url-or-pswp-spec "`; arg2 `" 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))))
spec (cs/trim (:data data))
result
(if
(cs/starts-with? spec "![")
(process-simple-photoswipe spec index)
(process-full-photoswipe spec index))]
(log/info "process-photoswipe returning `" result "`.")
))
15 changes: 13 additions & 2 deletions src/smeagol/formatting.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[markdown.core :as md]
[smeagol.configuration :refer [config]]
[smeagol.extensions.mermaid :refer [process-mermaid]]
[smeagol.extensions.photoswipe :refer [process-photoswipe]]))
[smeagol.extensions.photoswipe :refer [process-photoswipe]]
[taoensso.timbre :as log]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
Expand Down Expand Up @@ -149,7 +150,17 @@
;; I need to put the backticks back in.
remarked (if (odd? index) (str "```" fragment "\n```") fragment)
first-token (get-first-token fragment)
formatter (eval ((:formatters config) first-token))]
formatter (if-not
(empty? first-token)
(try
(let [kw (keyword first-token)]
(read-string (-> config :formatters kw :formatter)))
(catch Exception _
(do
(log/info "No formatter found for extension `" first-token "`")
;; no extension registered - there sometimes won't be,
;; and it doesn't matter
nil))))]
(cond
(empty? fragments)
(assoc result :text
Expand Down

0 comments on commit 0d686a9

Please sign in to comment.