updated to use parser modules

This commit is contained in:
Yogthos 2015-01-14 20:49:51 -05:00
parent cc16110f10
commit 96502bd517
3 changed files with 23 additions and 51 deletions

View file

@ -1,4 +1,4 @@
(defproject cryogen-core "0.1.15"
(defproject cryogen-core "0.1.16"
:description "Cryogen's compiler"
:url "https://github.com/lacarmen/cryogen-core"
:license {:name "Eclipse Public License"
@ -12,6 +12,4 @@
[io.aviso/pretty "0.1.13"]
[hiccup "1.0.5"]
[selmer "0.7.8"]
[markdown-clj "0.9.62"]
[pandect "0.4.1"]
[org.asciidoctor/asciidoctorj "1.5.2"]])
[pandect "0.4.1"]])

View file

@ -1,9 +1,7 @@
(ns cryogen-core.markup
(:require [markdown.core :refer [md-to-html-string]]
[markdown.transformers :refer [transformer-vector]]
[clojure.string :as s])
(:import org.asciidoctor.Asciidoctor$Factory
java.util.Collections))
(:import java.util.Collections))
(defonce markup-registry (atom []))
(defprotocol Markup
"A markup engine comprising a dir(ectory) containing markup files,
@ -13,56 +11,16 @@
(ext [this])
(render-fn [this]))
(defn- rewrite-hrefs
(defn rewrite-hrefs
"Injects the blog prefix in front of any local links
ex. <img src='/img/cryogen.png'/> becomes <img src='/blog/img/cryogen.png'/>"
[blog-prefix text]
(clojure.string/replace text #"href=.?/|src=.?/" #(str (subs % 0 (dec (count %))) blog-prefix "/")))
(defn- rewrite-hrefs-transformer
"A :replacement-transformer for use in markdown.core that will inject the
given blog prefix in front of local links."
[{:keys [blog-prefix]} text state]
[(rewrite-hrefs blog-prefix text) state])
(defn- markdown
"Returns a Markdown (https://daringfireball.net/projects/markdown/)
implementation of the Markup protocol."
[]
(reify Markup
(dir [this] "md")
(ext [this] ".md")
(render-fn [this]
(fn [rdr config]
(md-to-html-string
(->> (java.io.BufferedReader. rdr)
(line-seq)
(s/join "\n"))
:reference-links? true
:heading-anchors true
:replacement-transformers (conj transformer-vector (partial rewrite-hrefs-transformer config)))))))
(defn- asciidoc
"Returns an Asciidoc (http://asciidoc.org/) implementation of the
Markup protocol."
[]
(reify Markup
(dir [this] "asc")
(ext [this] ".asc")
(render-fn [this]
(fn [rdr config]
(->>
(.convert (Asciidoctor$Factory/create)
(->> (java.io.BufferedReader. rdr)
(line-seq)
(s/join "\n"))
(Collections/emptyMap))
(rewrite-hrefs (:blog-prefix config)))))))
(defn markups
"Return a vector of Markup implementations. This is the primary entry point
for a client of this ns. This vector should be used to iterate over supported
Markups."
[]
[(markdown) (asciidoc)])
@markup-registry)

View file

@ -0,0 +1,16 @@
(ns cryogen-core.plugins
(:require [cryogen-core.compiler :refer [compile-assets-timed]]
[clojure.edn :as edn]
[text-decoration.core :refer :all]))
(defn load-plugin [url]
(let [config (edn/read-string (slurp url))]
(println (green (str "loading module: " (:description config))))
(require (:namespace config))))
(defn load-plugins []
(let [plugins (.getResources (ClassLoader/getSystemClassLoader) "plugin.edn")]
(loop []
(load-plugin (.. plugins nextElement openStream))
(when (.hasMoreElements plugins)
(recur)))))