Commits

Meikel Brandmeyer committed 636d121

Move codox to v0.6.1

Comments (0)

Files changed (7)

runtime/src/main/resources/clojuresque/codox/css/default.css

 }
 
 pre, code {
-   font-family: monospace;
-   font-size: 10pt;
+   font-family: Monaco, DejaVu Sans Mono, Consolas, monospace;
+   font-size: 9pt;
 }
 
 h2 {
    font-weight: normal;
    font-size: 18pt;
-   margin: 10px 0 0.8em 0;
+   margin: 10px 0 0.4em 0;
 }
 
 #header, #content, .sidebar {
 }
 
 .public {
-   margin-bottom: 2.5em;
+   margin-top: 1.5em;
+   margin-bottom: 2.0em;
 }
 
 .public:last-child {
 
 .usage code {
    display: block;
+   color: #008;
 }

runtime/src/main/resources/clojuresque/codox/js/page_effects.js

   $(element).scroll(function() { storeScrollPosition(element) })
 }
 
+function sidebarContentWidth(element) {
+    var widths = $(element).find('span').map(function() { return $(this).width() })
+    return Math.max.apply(Math, widths)
+}
+
+function resizeNamespaces() {
+    var width = sidebarContentWidth('#namespaces') + 40
+    $('#namespaces').css('width', width)
+    $('#vars, .namespace-index').css('left', width + 1)
+    $('.namespace-docs').css('left', $('#vars').width() + width + 2)
+}
+
+$(window).ready(resizeNamespaces)
 $(window).ready(setCurrentVarLink)
 $(window).ready(function() { $('#content').scroll(setCurrentVarLink) })
 $(window).ready(function() { persistScrollPosition('#namespaces')})

runtime/src/main/resources/clojuresque/codox/main.clj

 (ns clojuresque.codox.main
   "Main namespace for generating documentation"
-  (:use [clojuresque.codox.reader :only (read-namespaces)]
-        [clojuresque.codox.writer.html :only (write-docs)]))
+  (:use [clojuresque.codox.utils :only (ns-filter)]
+        [clojuresque.codox.reader :only (read-namespaces)]))
+
+(defn- writer [{:keys [writer]}]
+  (let [writer-sym (or writer 'clojuresque.codox.writer.html/write-docs)
+        writer-ns (symbol (namespace writer-sym))]
+    (try
+      (require writer-ns)
+      (catch Exception e
+        (throw
+         (Exception. (str "Could not load codox writer " writer-ns) e))))
+    (if-let [writer (resolve writer-sym)]
+      writer
+      (throw
+         (Exception. (str "Could not resolve codox writer " writer-sym))))))
 
 (defn generate-docs
   "Generate documentation from source files."
   ([]
      (generate-docs {}))
-  ([options]
-     (let [namespaces (apply read-namespaces (:sources options))]
-       (write-docs (assoc options :namespaces namespaces)))))
+  ([{:keys [sources include exclude] :as options}]
+     (let [namespaces (-> (apply read-namespaces sources)
+                          (ns-filter include exclude))
+           write (writer options)]
+       (write (assoc options :namespaces namespaces)))))

runtime/src/main/resources/clojuresque/codox/reader.clj

        (filter (comp :doc meta))
        (sort-by (comp :name meta))))
 
+(defn- skip-public? [var]
+  (let [{:keys [skip-wiki no-doc]} (meta var)]
+    (or skip-wiki no-doc)))
+
 (defn- read-publics [namespace]
-  (for [var (sorted-public-vars namespace)]
+  (for [var (sorted-public-vars namespace)
+        :when (not (skip-public? var))]
     (-> (meta var)
-        (select-keys [:name :file :line :arglists :doc :macro :added])
+        (select-keys
+         [:name :file :line :arglists :doc :macro :added :deprecated])
         (update-in [:doc] correct-indent))))
 
 (defn- read-ns [namespace]

runtime/src/main/resources/clojuresque/codox/utils.clj

        (->> (str/split-lines text)
             (map #(str/replace % re ""))
             (str/join "\n")))))
+
+(defn symbol-set
+  "Accepts a single item (or a collection of items), converts them to
+  symbols and returns them in set form."
+  [x]
+  (->> (if (coll? x) x [x])
+       (filter identity)
+       (map symbol)
+       (into #{})))
+
+(defn ns-filter
+  "Accepts a sequence of namespaces (generated by
+  `codox.reader/read-namespaces`), a sequence of namespaces to keep
+  and a sequence of namespaces to drop. The sequence is returned with
+  all namespaces in `exclude` and all namespaces NOT in `include`
+  removed."
+  [ns-seq include exclude]
+  (let [has-name? (fn [names] (comp (symbol-set names) :name))
+        ns-seq    (remove (has-name? exclude) ns-seq)]
+    (if include
+      (filter (has-name? include) ns-seq)
+      ns-seq)))

runtime/src/main/resources/clojuresque/codox/writer/html.clj

 (ns clojuresque.codox.writer.html
   "Documentation writer that outputs HTML."
-  (:use [clojuresque.hiccup core page-helpers])
+  (:use [clojuresque.hiccup core page element])
   (:import java.net.URLEncoder)
   (:require [clojure.java.io :as io]
             [clojure.string :as str]))
 (defn- ns-filename [namespace]
   (str (:name namespace) ".html"))
 
+(defn- ns-filepath [output-dir namespace]
+  (str output-dir "/" (ns-filename namespace)))
+
 (defn- var-id [var]
   (str "var-" (URLEncoder/encode (str (:name var)))))
 
   (str (ns-filename namespace) "#" (var-id var)))
 
 (defn- link-to-ns [namespace]
-  (link-to (ns-filename namespace) (h (:name namespace))))
+  (link-to (ns-filename namespace) [:span (h (:name namespace))]))
 
 (defn- link-to-var [namespace var]
-  (link-to (var-uri namespace var) (h (:name var))))
+  (link-to (var-uri namespace var) [:span (h (:name var))]))
 
 (defn- namespaces-menu [project & [namespace]]
   [:div#namespaces.sidebar
-   [:h3 "Namespaces"]
+   [:h3 [:span "Namespaces"]]
    [:ul
     (for [ns (:namespaces project)]
       (if (= ns namespace)
            [:code (h (pr-str form))])]
         [:pre.doc (h (:doc var))]])]]))
 
-(defn- copy-resource [src dest]
+(defn- copy-resource [output-dir src dest]
   (io/copy (io/input-stream (io/resource src))
-           (io/file dest)))
+           (io/file output-dir dest)))
 
-(defn- mkdirs [& dirs]
+(defn- mkdirs [output-dir & dirs]
   (doseq [dir dirs]
-    (.mkdirs (io/file dir))))
+    (.mkdirs (io/file output-dir dir))))
 
-(defn- destination
-  [project]
-  (fn [dir]
-    (str (:destination project) "/" dir)))
+(defn- write-index [output-dir project]
+  (spit (io/file output-dir "index.html") (index-page project)))
+
+(defn- write-namespaces
+  [output-dir project]
+  (doseq [namespace (:namespaces project)]
+    (spit (ns-filepath output-dir namespace)
+          (namespace-page project namespace))))
 
 (defn write-docs
   "Take raw documentation info and turn it into formatted HTML."
   [project]
-  (let [destination (destination project)]
-    (mkdirs (destination "css") (destination "js"))
-    (doseq [[from to] (map (juxt (partial str "clojuresque/codox/")
-                                 destination)
-                           ["css/default.css"
-                            "js/jquery.min.js"
-                            "js/page_effects.js"])]
-      (copy-resource from to))
-    (spit (destination "index.html") (index-page project))
-    (doseq [namespace (:namespaces project)]
-      (spit (destination (ns-filename namespace))
-            (namespace-page project namespace)))))
+  (doto (:output-dir project "doc")
+    (mkdirs "css" "js")
+    (copy-resource "clojuresque/codox/css/default.css" "css/default.css")
+    (copy-resource "clojuresque/codox/js/jquery.min.js" "js/jquery.min.js")
+    (copy-resource "clojuresque/codox/js/page_effects.js" "js/page_effects.js")
+    (write-index project)
+    (write-namespaces project))
+  nil)

runtime/src/main/resources/clojuresque/tasks/doc.clj

   (let [project {:name        name
                  :version     version
                  :description description
-                 :destination destination
+                 :output-dir  destination
                  :sources     sources}]
     (generate-docs project)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.