Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support simultaneous Clojure & ClojureScript output #220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
43 changes: 39 additions & 4 deletions codox/resources/codox/theme/default/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ h5.license {
right: 0;
height: 22px;
color: #f5f5f5;
padding: 5px 7px;
padding: 7px 10px;
}

#content {
Expand Down Expand Up @@ -97,6 +97,8 @@ h5.license {
}

#header h1 {
display: block;
float: left;
margin: 0;
padding: 0;
font-size: 18px;
Expand All @@ -121,6 +123,26 @@ h5.license {
color: #f5f5f5;
}

#langs {
display: block;
float: left;
font-size: 16px;
margin: 0 10px;
}

#langs .lang {
display: inline-block;
margin: 0 2px;
padding: 0 7px;
background-color: #717171;
border-radius: 6px;
vertical-align: middle;
}

#langs .lang.current {
background-color: #a33;
}

.sidebar a {
color: #333;
}
Expand Down Expand Up @@ -325,7 +347,8 @@ h5.license {
h4.type,
h4.dynamic,
h4.added,
h4.deprecated {
h4.deprecated,
h4.lang {
float: left;
margin: 3px 10px 15px 0;
font-size: 15px;
Expand All @@ -336,15 +359,17 @@ h4.deprecated {
.public h4.type,
.public h4.dynamic,
.public h4.added,
.public h4.deprecated {
.public h4.deprecated,
.public h4.lang {
font-size: 13px;
font-weight: bold;
margin: 3px 0 0 10px;
}

.members h4.type,
.members h4.added,
.members h4.deprecated {
.members h4.deprecated,
.members h4.lang {
margin-top: 1px;
}

Expand All @@ -364,6 +389,16 @@ h4.deprecated {
color: #880000;
}

.public h4.lang, .public h4.lang a {
font-weight: normal;
font-variant: normal;
color: #717171;
}

.public h4.lang.current {
color: #a33;
}

.namespace {
margin-bottom: 30px;
}
Expand Down
71 changes: 62 additions & 9 deletions codox/src/codox/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,52 @@
namespaces))

(defn- read-namespaces
"Returns {<language> <namespace-seq>} for cross-platform opts,
or <namespace-seq> otherwise."
[{:keys [language root-path source-paths namespaces metadata exclude-vars] :as opts}]
(let [reader (namespace-readers language)]
(-> (reader source-paths (select-keys opts [:exception-handler]))
(filter-namespaces namespaces)
(remove-excluded-vars exclude-vars)
(add-source-paths root-path source-paths)
(add-ns-defaults metadata))))
(if (:cross-platform? opts)
(reduce
(fn [m language]
(assoc m language
(read-namespaces
(assoc opts
:language language
:cross-platform? false))))
{}
(:languages opts))
(let [reader (namespace-readers language)]
(-> (reader source-paths (select-keys opts [:exception-handler]))
(filter-namespaces namespaces)
(remove-excluded-vars exclude-vars)
(add-source-paths root-path source-paths)
(add-ns-defaults metadata)))))

(defn- get-var-langs
"Returns {<ns> {<var> <set-of-languages>}} for given namespaces."
([language namespaces var-langs]
(reduce
(fn [var-langs ns]
(reduce
(fn [var-langs public-var]
(update-in var-langs [(:name ns) (:name public-var)]
#(conj (or % #{}) language)))
var-langs
(:publics ns)))
var-langs
namespaces))

([options namespaces]
(if-not (:cross-platform? options)
(get-var-langs (:language options) namespaces {})
(reduce
(fn [var-langs language]
(get-var-langs language (get namespaces language) var-langs))
{}
(:languages options)))))

(comment (get-var-langs {:languages #{:clojure :clojurescript}}
'({:name codox.main :publics ({:name defaults} {:name bar})}
{:name codox.foo :publics ({:name bar})})))

(defn- read-documents [{:keys [doc-paths doc-files] :or {doc-files :all}}]
(cond
Expand Down Expand Up @@ -113,15 +152,29 @@
:themes [:default]
:git-commit (delay (git-commit root-path))}))

(defn- cross-platform-options [{:keys [language] :as opts}]
(if-not (set? language)
opts ; {:language <keyword>}
(if (= (count language) 1)
(assoc opts :language (first language)) ; {:language <keyword>}

;; Cross-platform case: {:language nil, :languages <set>}
(assoc opts
:language nil
:languages language
:cross-platform? true))))

(defn generate-docs
"Generate documentation from source files."
([]
(generate-docs {}))
([options]
(let [options (merge defaults options)
(let [options (-> (merge defaults options) cross-platform-options)
write-fn (writer options)
namespaces (read-namespaces options)
documents (read-documents options)]
documents (read-documents options)
var-langs (get-var-langs options namespaces)]
(write-fn (assoc options
:namespaces namespaces
:documents documents)))))
:documents documents
:var-langs var-langs)))))
Loading