Skip to content

Commit

Permalink
move test vars into separate ns, better map of info
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Mar 16, 2012
1 parent 44c8155 commit b3a27a2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
15 changes: 15 additions & 0 deletions src/foo/bar.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns foo.bar
"A test namespace.")

;; testing vars
(def ^{:private true :doc "a test variable"} test-var 42)

(defn ^Long typed-fn [] (constantly 5))

(defn- ^:dynamic test-fn
"A function to test read-file against"
([x]
(println x))
([x y]
(println x y)))

66 changes: 25 additions & 41 deletions src/leiningen/clojuredocs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,44 @@

(defn get-project-meta
"Return a map of information about the project that should be indexed."
[{:keys [name group url description version] :as project}]
{:project (str (if (= name group)
""
(str group "/"))
name)
:url url
:version version
:descripton description})
[project]
(select-keys project [:name :group :url :description :version :group]))

(defn serialize-docs
(defn serialize-project-info
"TODO: Write the docs to a file"
[proj-meta docs]
#_(pp/print-table [:ns :name :arglists :private :dynamic] docs)
(pp/pprint (assoc proj-meta :vars (vec docs))))
[info]
(pp/pprint info)
(flush))

(defn read-file
(defn read-namespace
"Reads a file, serializing docs to a file for import to ClojureDocs"
[project f]
[f]
(let [ns-dec (clj-ns/read-file-ns-decl f)
ns-name (second ns-dec)
proj-meta (get-project-meta project)]
ns-name (second ns-dec)]
(printf "[+] Processing %s...\n" (or ns-name f))
(flush)
(try
(require ns-name)
(catch Exception e
(println "Error requiring" ns-name e)))
(let [vars (vals (ns-interns ns-name))
metas (map meta vars)
docs (->> metas
(map (fn [m] (assoc m :project (:project proj-meta))))
(map munge-doc))]
(serialize-docs proj-meta docs))))


;; testing vars
(def ^{:private true :doc "a test variable"} test-var 42)

(defn ^Long typed-fn [] 5)

(defn- ^:dynamic test-fn
"A function to test read-file against"
([x]
(println x))
([x y]
(println x y)))
{(str ns-name) (->> ns-name
ns-interns
vals
(map meta)
(map munge-doc))}))

;; actual lein function
;; actual lein plugin function
(defn clojuredocs
"Publish vars for clojuredocs"
[project]
(let [paths (or (:source-paths project) [(:source-path project)])
source-files (mapcat #(-> % io/file clj-ns/find-clojure-sources-in-dir)
paths)]
(doseq [source-file source-files]
(read-file project source-file))
(flush)))
source-files (mapcat #(-> %
io/file
clj-ns/find-clojure-sources-in-dir)
paths)
proj-meta (get-project-meta project)
data-map (merge proj-meta
{:namespaces
(apply merge (for [source-file source-files]
(read-namespace source-file)))})]
(serialize-project-info data-map)))

0 comments on commit b3a27a2

Please sign in to comment.