Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions codox/src/codox/main.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns codox.main
"Main namespace for generating documentation"
(:use [codox.utils :only (add-source-paths)])
(:require [clojure.string :as str]
[clojure.java.shell :as shell]
(:require [clojure.java.shell :as shell]
[clojure.string :as str]
[codox.reader.clojure :as clj]
[codox.reader.plaintext :as text]))
[codox.reader.plaintext :as text]
[codox.utils :refer [add-source-paths]]))

(defn- writer [{:keys [writer]}]
(let [writer-sym (or writer 'codox.writer.html/write-docs)
Expand All @@ -28,7 +28,7 @@
(remove (comp empty? :publics))))

(defn- merge-namespaces [namespaces]
(for [[name namespaces] (group-by :name namespaces)]
(for [[_ namespaces] (group-by :name namespaces)]
(assoc (first namespaces) :publics (mapcat :publics namespaces))))

(defn- cljs-read-namespaces [paths read-opts]
Expand Down
8 changes: 4 additions & 4 deletions codox/src/codox/reader/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"Read raw documentation information from Clojure source directory."
(:import java.util.jar.JarFile
java.io.FileNotFoundException)
(:use [codox.utils :only (assoc-some update-some correct-indent)])
(:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.namespace.find :as ns]
[clojure.string :as str]))
[codox.utils :refer (assoc-some correct-indent update-some)]))

(defn try-require [namespace]
(try
Expand Down Expand Up @@ -65,7 +65,7 @@

(defn core-typed-type [var]
(let [{:keys [delayed-errors ret]} (typecheck-var var)]
(if (empty? delayed-errors)
(when (empty? delayed-errors)
(:t ret))))

(defn- read-var [vars var]
Expand All @@ -74,7 +74,7 @@
:added :deprecated :doc/format])
(update-some :doc correct-indent)
(assoc-some :type (var-type var)
:type-sig (if (core-typed?) (core-typed-type var))
:type-sig (when (core-typed?) (core-typed-type var))
:members (seq (map (partial read-var vars)
(protocol-methods var vars))))))

Expand Down
12 changes: 6 additions & 6 deletions codox/src/codox/reader/clojurescript.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns codox.reader.clojurescript
"Read raw documentation information from ClojureScript source directory."
(:use [codox.utils :only [assoc-some update-some correct-indent]])
(:require [clojure.java.io :as io]
[cljs.analyzer :as an]
(:require [cljs.analyzer :as an]
[cljs.analyzer.api :as ana]
[clojure.string :as str]))
[clojure.java.io :as io]
[clojure.string :as str]
[codox.utils :refer [assoc-some correct-indent update-some]]))

(defn- cljs-filename? [filename]
(or (.endsWith filename ".cljs")
Expand All @@ -23,11 +23,11 @@
(let [len (inc (count (.getPath parent)))]
(fn [child]
(let [child-name (.getPath child)]
(if (>= (count child-name) len)
(when (>= (count child-name) len)
(io/file (subs child-name len)))))))

(defn- find-files [file]
(if (.isDirectory file)
(when (.isDirectory file)
(->> (file-seq file)
(filter cljs-file?)
(keep (strip-parent file)))))
Expand Down
10 changes: 5 additions & 5 deletions codox/src/codox/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(assoc-some m k (apply f (m k) args)))

(defn- find-minimum [coll]
(if (seq coll)
(when (seq coll)
(apply min coll)))

(defn- find-smallest-indent [text]
Expand All @@ -34,7 +34,7 @@
`codox.reader/read-namespaces`), and a sequence of source directory paths,
returns a File object indicating the file from the repo root."
[file sources]
(if (and file (not (.isAbsolute (io/file file))))
(when (and file (not (.isAbsolute (io/file file))))
(->> (map #(io/file % file) sources)
(filter #(.exists %))
first)))
Expand All @@ -51,7 +51,7 @@
(str/join "\n")))))

(defn correct-indent [text]
(if text
(when text
(let [lines (str/split-lines text)]
(->> (rest lines)
(str/join "\n")
Expand Down Expand Up @@ -87,7 +87,7 @@
character to the first page break (\f) character OR the first TWO
newlines."
[s]
(if s
(when s
(->> (str/trim s)
(re-find #"(?s).*?(?=\f)|.*?(?=\n\n)|.*"))))

Expand All @@ -105,7 +105,7 @@
(defn re-escape
"Escape a string so it can be safely placed in a regex."
[s]
(str/escape s #(if (re-chars %) (str \\ %))))
(str/escape s #(when (re-chars %) (str \\ %))))

(defn search-vars
"Find the best-matching var given a partial var string, a list of namespaces,
Expand Down
41 changes: 18 additions & 23 deletions codox/src/codox/writer/html.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
(ns codox.writer.html
"Documentation writer that outputs HTML."
(:use [hiccup core page element])
(:import [java.net URLEncoder]
[java.io File]
[org.pegdown
PegDownProcessor Extensions FastEncoder
LinkRenderer LinkRenderer$Rendering]
Expand All @@ -12,9 +10,10 @@
[clojure.pprint :as pp]
[clojure.string :as str]
[clojure.walk :as walk]
[codox.utils :as util]
[hiccup.core :refer [h html5 link-to unordered-list]]
[net.cgrand.enlive-html :as enlive-html]
[net.cgrand.jsoup :as jsoup]
[codox.utils :as util]))
[net.cgrand.jsoup :as jsoup]))

(def enlive-operations
{:append enlive-html/append
Expand Down Expand Up @@ -52,12 +51,12 @@
#"((https?|ftp|file)://[-A-Za-z0-9+()&@#/%?=~_|!:,.;]+[-A-Za-z0-9+()&@#/%=~_|])")

(defn- add-anchors [text]
(if text
(when text
(str/replace text url-regex "<a href=\"$1\">$1</a>")))

(defmulti format-docstring
"Format the docstring of a var or namespace into HTML."
(fn [project ns var] (:doc/format var))
(fn [_ _ var] (:doc/format var))
:default :plaintext)

(defmethod format-docstring :plaintext [_ _ metadata]
Expand Down Expand Up @@ -145,7 +144,7 @@
(str (ns-filename namespace) "#" (var-id (:name var))))

(defn- get-source-uri [source-uris path]
(some (fn [[re f]] (if (re-find re path) f)) source-uris))
(some (fn [[re f]] (when (re-find re path) f)) source-uris))

(defn- uri-basename [path]
(second (re-find #"/([^/]+?)$" path)))
Expand Down Expand Up @@ -217,11 +216,11 @@
[:span.top {:style (str "height: " height "px;")}]
[:span.bottom]])))

(defn- index-link [project on-index?]
(defn- index-link [_ on-index?]
(list
[:h3.no-link [:span.inner "Project"]]
[:ul.index-link
[:li.depth-1 {:class (if on-index? "current")}
[:li.depth-1 {:class (when on-index? "current")}
(link-to "index.html" [:div.inner "Index"])]]))

(defn- topics-menu [project current-doc]
Expand All @@ -231,26 +230,26 @@
[:ul
(for [doc docs]
[:li.depth-1
{:class (if (= doc current-doc) " current")}
{:class (when (= doc current-doc) " current")}
(link-to (doc-filename doc) [:div.inner [:span (h (:title doc))]])])])))

(defn- nested-namespaces [namespaces current-ns]
(let [ns-map (index-by :name namespaces)]
[:ul
(for [[name depth height branch?] (namespace-hierarchy namespaces)]
(let [class (str "depth-" depth (if branch? " branch"))
(let [class (str "depth-" depth (when branch? " branch"))
short (last (split-ns name))
inner [:div.inner (ns-tree-part height) [:span (h short)]]]
(if-let [ns (ns-map name)]
(let [class (str class (if (= ns current-ns) " current"))]
(let [class (str class (when (= ns current-ns) " current"))]
[:li {:class class} (link-to (ns-filename ns) inner)])
[:li {:class class} [:div.no-link inner]])))]))

(defn- flat-namespaces [namespaces current-ns]
[:ul
(for [ns (sort-by :name namespaces)]
[:li.depth-1
{:class (if (= ns current-ns) "current")}
{:class (when (= ns current-ns) "current")}
(link-to (ns-filename ns) [:div.inner [:span (h (:name ns))]])])])

(defn- namespace-list-type [project]
Expand Down Expand Up @@ -312,7 +311,7 @@
(if (.endsWith s ending) s (str s ending)))

(defn- strip-prefix [s prefix]
(if s (str/replace s (re-pattern (str "(?i)^" prefix)) "")))
(when s (str/replace s (re-pattern (str "(?i)^" prefix)) "")))

(defn- index-page [project]
(html5
Expand Down Expand Up @@ -356,7 +355,7 @@

(defmulti format-document
"Format a document into HTML."
(fn [project doc] (:format doc)))
(fn [_ doc] (:format doc)))

(defmethod format-document :markdown [project doc]
[:div.markdown (.markdownToHtml pegdown (:content doc) (link-renderer project))])
Expand All @@ -381,7 +380,7 @@
(if-let [added (:added var)]
[:h4.added "added in " added])
(if-let [deprecated (:deprecated var)]
[:h4.deprecated "deprecated" (if (string? deprecated) (str " in " deprecated))])))
[:h4.deprecated "deprecated" (when (string? deprecated) (str " in " deprecated))])))

(defn- remove-namespaces [x namespaces]
(if (and (symbol? x) (contains? namespaces (namespace x)))
Expand All @@ -406,10 +405,10 @@
[:h3 (h (:name var))]
(if-not (= (:type var) :var)
[:h4.type (name (:type var))])
(if (:dynamic var)
(when (:dynamic var)
[:h4.dynamic "dynamic"])
(added-and-deprecated-docs var)
(if (:type-sig var)
(when (:type-sig var)
[:div.type-sig
[:pre (h (type-sig namespace var))]])
[:div.usage
Expand All @@ -422,7 +421,7 @@
[:div.inner
(let [project (dissoc project :source-uri)]
(map (partial var-docs project namespace) members))]])
(if (:source-uri project)
(when (:source-uri project)
(if (:path var)
[:div.src-link (link-to (var-source-uri project var) "view source")]
(println "Could not generate source link for" (:name var))))])
Expand All @@ -443,10 +442,6 @@
(for [var (sorted-public-vars namespace)]
(var-docs project namespace var))]]))

(defn- mkdirs [output-dir & dirs]
(doseq [dir dirs]
(.mkdirs (io/file output-dir dir))))

(defn- write-index [output-dir project]
(spit (io/file output-dir "index.html") (transform-html project (index-page project))))

Expand Down