Merge pull request #130 from OtherPeoplesPixels/master

Improve cljs file support and sort by namespace
This commit is contained in:
Gary Deer 2014-03-15 13:13:38 -05:00
commit 445dd05319
2 changed files with 27 additions and 14 deletions

View file

@ -74,14 +74,27 @@
[path] [path]
(.isDirectory (java.io.File. path))) (.isDirectory (java.io.File. path)))
(defn find-file-extension
"Returns a string containing the files extension."
[^java.io.File file]
(second (re-find #"\.([^.]+)$" (.getName file))))
(defn processable-file?
"Predicate. Returns true for \"normal\" files with a file extension which
passes the provided predicate."
[pred ^java.io.File file]
(when (.isFile file)
(-> file find-file-extension pred)))
(defn find-processable-file-paths (defn find-processable-file-paths
"Returns a seq of clojure file paths (strings) in alphabetical order." "Returns a seq of processable file paths (strings) in alphabetical order by
[dir matching-re] namespace."
[dir pred]
(->> (io/file dir) (->> (io/file dir)
(file-seq) (file-seq)
(filter #(re-find matching-re (.getCanonicalPath %))) (filter (partial processable-file? pred))
(map #(.getCanonicalPath %)) (sort-by #(->> % read-file-ns-decl second))
(sort))) (map #(.getCanonicalPath %))))
;; ## Project Info Parsing ;; ## Project Info Parsing
;; Marginalia will parse info out of your project.clj to display in ;; Marginalia will parse info out of your project.clj to display in
@ -202,20 +215,18 @@
;; These functions support Marginalia's use by client software or command-line ;; These functions support Marginalia's use by client software or command-line
;; users. ;; users.
(def ^:private file-extensions #{"clj" "cljs" "cljx"})
(defn format-sources (defn format-sources
"Given a collection of filepaths, returns a lazy sequence of filepaths to "Given a collection of filepaths, returns a lazy sequence of filepaths to all
all .clj files on those paths: directory paths will be searched recursively .clj, .cljs, and .cljx files on those paths: directory paths will be searched
for .clj files." recursively for files."
[sources] [sources]
(if (nil? sources) (if (nil? sources)
(concat (find-processable-file-paths "./src" file-extensions)
(find-processable-file-paths "./src" #"\.clj$")
(find-processable-file-paths "./src" #"\.cljs$"))
(->> sources (->> sources
(mapcat #(if (dir? %) (mapcat #(if (dir? %)
(concat (find-processable-file-paths % file-extensions)
(find-processable-file-paths % #"\.clj$")
(find-processable-file-paths % #"\.cljs$"))
[(.getCanonicalPath (io/file %))]))))) [(.getCanonicalPath (io/file %))])))))
(defn split-deps [deps] (defn split-deps [deps]

View file

@ -302,6 +302,8 @@
:background-color "#F5F5FF"}] :background-color "#F5F5FF"}]
[:h1 {:font-size "20px" [:h1 {:font-size "20px"
:margin-top 0}] :margin-top 0}]
[:h2 {:font-size "18px"}]
[:h3 {:font-size "16px"}]
[:a.anchor {:text-decoration "none" [:a.anchor {:text-decoration "none"
:color "#252519"}] :color "#252519"}]
[:a.anchor:hover {:color "#5050A6"}] [:a.anchor:hover {:color "#5050A6"}]