Merge pull request #141 from bilus/cljx-reader-macros
Add support for cljx reader tags #+clj and #+cljs
This commit is contained in:
commit
ab71d7d4d1
2 changed files with 33 additions and 20 deletions
|
@ -36,9 +36,8 @@
|
||||||
[clojure.string :as str])
|
[clojure.string :as str])
|
||||||
(:use [marginalia
|
(:use [marginalia
|
||||||
[html :only (uberdoc-html index-html single-page-html)]
|
[html :only (uberdoc-html index-html single-page-html)]
|
||||||
[parser :only (parse-file)]]
|
[parser :only (parse-file parse-ns)]]
|
||||||
[clojure.tools
|
[clojure.tools
|
||||||
[namespace :only (read-file-ns-decl)]
|
|
||||||
[cli :only (cli)]]))
|
[cli :only (cli)]]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,7 +92,7 @@
|
||||||
(->> (io/file dir)
|
(->> (io/file dir)
|
||||||
(file-seq)
|
(file-seq)
|
||||||
(filter (partial processable-file? pred))
|
(filter (partial processable-file? pred))
|
||||||
(sort-by #(->> % read-file-ns-decl second))
|
(sort-by #(->> % parse-ns second))
|
||||||
(map #(.getCanonicalPath %))))
|
(map #(.getCanonicalPath %))))
|
||||||
|
|
||||||
;; ## Project Info Parsing
|
;; ## Project Info Parsing
|
||||||
|
@ -170,15 +169,8 @@
|
||||||
:else (recur (merge-line (first lines) cur-group) groups (rest lines)))))
|
:else (recur (merge-line (first lines) cur-group) groups (rest lines)))))
|
||||||
|
|
||||||
(defn path-to-doc [fn]
|
(defn path-to-doc [fn]
|
||||||
(let [file (java.io.File. fn)
|
{:ns (parse-ns (java.io.File. fn))
|
||||||
ns (-> file
|
:groups (parse-file fn)})
|
||||||
(read-file-ns-decl)
|
|
||||||
(second)
|
|
||||||
(str))
|
|
||||||
ns (if (or (nil? ns) (empty? ns)) (.getName file) ns)
|
|
||||||
groups (parse-file fn)]
|
|
||||||
{:ns ns
|
|
||||||
:groups groups}))
|
|
||||||
|
|
||||||
|
|
||||||
;; ## Output Generation
|
;; ## Output Generation
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
"Provides the parsing facilities for Marginalia."
|
"Provides the parsing facilities for Marginalia."
|
||||||
(:refer-clojure :exclude [replace])
|
(:refer-clojure :exclude [replace])
|
||||||
(:use [clojure [string :only (join replace lower-case)]]
|
(:use [clojure [string :only (join replace lower-case)]]
|
||||||
[cljs.tagged-literals :only [*cljs-data-readers*]]))
|
[cljs.tagged-literals :only [*cljs-data-readers*]]
|
||||||
|
[clojure.tools.namespace :only (read-file-ns-decl)]))
|
||||||
|
|
||||||
|
|
||||||
;; Extracted from clojure.contrib.reflect
|
;; Extracted from clojure.contrib.reflect
|
||||||
|
@ -391,10 +392,30 @@
|
||||||
(defn cljs-file? [filepath]
|
(defn cljs-file? [filepath]
|
||||||
(.endsWith (lower-case filepath) "cljs"))
|
(.endsWith (lower-case filepath) "cljs"))
|
||||||
|
|
||||||
(defn parse-file [file]
|
(defn cljx-file? [filepath]
|
||||||
(let [readers (if (cljs-file? file)
|
(.endsWith (lower-case filepath) "cljx"))
|
||||||
(->> default-data-readers (merge *cljs-data-readers*))
|
|
||||||
default-data-readers)]
|
(def cljx-data-readers {'+clj identity
|
||||||
(binding [*data-readers* readers
|
'+cljs identity})
|
||||||
*comments-enabled* (atom true)]
|
|
||||||
(parse (slurp file)))))
|
(defmacro with-readers-for [file & body]
|
||||||
|
`(let [readers# (merge {}
|
||||||
|
(when (cljs-file? ~file) *cljs-data-readers*)
|
||||||
|
(when (cljx-file? ~file) cljx-data-readers)
|
||||||
|
default-data-readers)]
|
||||||
|
(binding [*data-readers* readers#]
|
||||||
|
~@body)))
|
||||||
|
|
||||||
|
(defn parse-file [fn]
|
||||||
|
(with-readers-for fn
|
||||||
|
(binding [*comments-enabled* (atom true)]
|
||||||
|
(parse (slurp fn)))))
|
||||||
|
|
||||||
|
(defn parse-ns [file]
|
||||||
|
(let [filename (.getName file)]
|
||||||
|
(with-readers-for filename
|
||||||
|
(or (not-empty (-> file
|
||||||
|
(read-file-ns-decl)
|
||||||
|
(second)
|
||||||
|
(str)))
|
||||||
|
filename))))
|
||||||
|
|
Loading…
Reference in a new issue