Fix no namespace extracted from .cljx files.

This commit is contained in:
Martin Bilski 2015-01-06 22:22:10 +01:00
parent 0e43f515a9
commit 319f26693d
2 changed files with 27 additions and 21 deletions

View file

@ -36,9 +36,8 @@
[clojure.string :as str])
(:use [marginalia
[html :only (uberdoc-html index-html single-page-html)]
[parser :only (parse-file)]]
[parser :only (parse-file parse-ns)]]
[clojure.tools
[namespace :only (read-file-ns-decl)]
[cli :only (cli)]]))
@ -93,7 +92,7 @@
(->> (io/file dir)
(file-seq)
(filter (partial processable-file? pred))
(sort-by #(->> % read-file-ns-decl second))
(sort-by #(->> % parse-ns second))
(map #(.getCanonicalPath %))))
;; ## Project Info Parsing
@ -170,15 +169,8 @@
:else (recur (merge-line (first lines) cur-group) groups (rest lines)))))
(defn path-to-doc [fn]
(let [file (java.io.File. fn)
ns (-> file
(read-file-ns-decl)
(second)
(str))
ns (if (or (nil? ns) (empty? ns)) (.getName file) ns)
groups (parse-file fn)]
{:ns ns
:groups groups}))
{:ns (parse-ns (java.io.File. fn))
:groups (parse-file fn)})
;; ## Output Generation

View file

@ -5,7 +5,8 @@
"Provides the parsing facilities for Marginalia."
(:refer-clojure :exclude [replace])
(: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
@ -397,11 +398,24 @@
(def cljx-data-readers {'+clj identity
'+cljs identity})
(defn parse-file [file]
(let [readers (merge {}
(when (cljs-file? file) *cljs-data-readers*)
(when (cljx-file? file) cljx-data-readers)
(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
*comments-enabled* (atom true)]
(parse (slurp file)))))
(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))))