Skip to content

Commit

Permalink
added test output for publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Zheng committed Oct 1, 2016
1 parent a562c9b commit 7954a7b
Show file tree
Hide file tree
Showing 24 changed files with 946 additions and 161 deletions.
518 changes: 518 additions & 0 deletions docs/hara-zip.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/theme/stark/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<style>
<@=css-page>
<@=css-code>
<@=css-api>
<@=css-highlight>
</style>
</head>
Expand Down
46 changes: 46 additions & 0 deletions resources/theme/stark/partials/api.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

.api .entry-description
{
display: flex;
}

.api ul
{
list-style-type: none;
padding-left: 5px;
}

.api .entry-description h4
{
float: left;
width: auto;
height 30px;
}

.api .entry-description p
{
float: left;
margin-bottom: 0px;
padding-left:2px;
}

.api .entry-option h6
{
float: left;
padding-right:5px;
}

.api .entry-option .args
{
font-weight: lighter;
}

.api .entry pre
{
width: 100%;
}

.api .entry pre h6
{
float: right;
}
17 changes: 17 additions & 0 deletions resources/theme/stark/partials/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ header div.heading {
display:none;
}

.code .failed
{
background-color:brown;
padding: 10px;
}

.code .failed h5, h4
{
color: white
}

.code .failed hr
{
margin-top: 15px;
margin-bottom: 0px;
}


@media print, screen and (max-width: 960px) {

Expand Down
5 changes: 3 additions & 2 deletions src/lucid/core/code/source.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
fns (->> (query/$ zloc [(#{defn defmulti defmacro} | _ ^:%?- string? ^:%?- map? & _)]
{:return :zipper :walk :top})
(map (juxt source/sexpr
(comp #(hash-map :source %)
source/string
(comp #(hash-map :source {:code (source/string %)
:line (meta (source/node %))
:path file})
source/up)))
(into {}))]
{nsp fns}))
2 changes: 1 addition & 1 deletion src/lucid/core/code/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
frameworks (find-frameworks ns-form)]
(->> frameworks
(map (fn [framework]
(test/analyse-test framework zloc)))
(test/analyse-test framework zloc {:path file})))
(apply nested/merge-nested))))
10 changes: 5 additions & 5 deletions src/lucid/core/code/test/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@
{:added "1.1"}
[zloc]
(if-let [mta (common/gather-meta zloc)]
(assoc mta :docs (gather-deftest-body zloc))))
(assoc mta :test (gather-deftest-body zloc))))

(defmethod common/frameworks 'clojure.test [_] :clojure)

(defmethod common/analyse-test :clojure
[type zloc]
[type zloc opts]
(let [fns (query/$ zloc [(deftest _ | & _)] {:return :zipper :walk :top})]
(->> (keep gather-deftest fns)
(reduce (fn [m {:keys [ns var docs] :as meta}]
(reduce (fn [m {:keys [ns var test] :as meta}]
(-> m
(assoc-in [ns var :docs] docs)
(assoc-in [ns var :meta] (dissoc meta :docs :ns :var :refer))))
(assoc-in [ns var :test] test)
(assoc-in [ns var :meta] (dissoc meta :test :ns :var :refer))))
{}))))
2 changes: 1 addition & 1 deletion src/lucid/core/code/test/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(defmulti frameworks (fn [sym] sym))
(defmethod frameworks :default [_])

(defmulti analyse-test (fn [type zloc] type))
(defmulti analyse-test (fn [type zloc opts] type))

(defn gather-meta
"gets the metadata for a particular form
Expand Down
25 changes: 20 additions & 5 deletions src/lucid/core/code/test/fact.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,32 @@
{:added "1.1"}
[zloc]
(if-let [mta (common/gather-meta zloc)]
(assoc mta :docs (gather-fact-body zloc))))
(let [exp (source/sexpr zloc)
[intro nzloc] (if (string? exp)
[exp (if (source/right zloc)
(source/right* zloc))]
["" zloc])]
(assoc mta
:line (meta (source/node (source/up zloc)))
:test (if nzloc
(gather-fact-body nzloc)
[])
:intro intro))))

(defmethod common/frameworks 'midje.sweet [_] :fact)
(defmethod common/frameworks 'hara.test [_] :fact)

(defmethod common/analyse-test :fact
([type zloc]
([type zloc opts]
(let [fns (query/$ zloc [(fact | & _)] {:return :zipper :walk :top})]
(->> (keep gather-fact fns)
(reduce (fn [m {:keys [ns var docs] :as meta}]
(reduce (fn [m {:keys [ns var test intro line] :as meta}]
(-> m
(assoc-in [ns var :docs] docs)
(assoc-in [ns var :meta] (dissoc meta :docs :ns :var :refer))))
(update-in [ns var]
assoc
:test {:code test
:line line
:path (:path opts)}
:meta (dissoc meta :test :line :intro :ns :var :refer)
:intro intro)))
{})))))
31 changes: 17 additions & 14 deletions src/lucid/publish.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@
*output*)]
(fs/path (:root project) output-dir)))

(defn load-settings [opts project]
(let [theme (or (:theme opts)
(-> project :publish :theme))
settings (merge (theme/load-settings theme)
opts)]
(when (:refresh settings)
(theme/deploy settings project)
(copy-assets settings project))
settings))

(defn copy-assets
([] (copy-assets {} (project/project)))
([opts project]
(let [settings (load-settings opts project)
template-dir (theme/template-path settings project)
([]
(let [project (project/project)
theme (-> project :publish :theme)
settings (theme/load-settings theme)]
(copy-assets settings project)))
([settings project]
(let [template-dir (theme/template-path settings project)
output-dir (output-path project)]
(doseq [entry (:copy settings)]
(let [dir (fs/path template-dir entry)
Expand All @@ -44,6 +37,16 @@
(fs/create-directory (fs/parent out))
(fs/copy-single in out {:options [:replace-existing :copy-attributes]}))))))))

(defn load-settings [opts project]
(let [theme (or (:theme opts)
(-> project :publish :theme))
settings (merge (theme/load-settings theme)
opts)]
(when (:refresh settings)
(theme/deploy settings project)
(copy-assets settings project))
settings))

(defn add-lookup [project]
(if (:lookup project)
project
Expand Down
40 changes: 36 additions & 4 deletions src/lucid/publish/collect/api.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
(ns lucid.publish.collect.api
(:require [lucid.core.code :as code]))
(:require [lucid.core.code :as code]
[lucid.publish.collect.reference :as reference]))

(defn collect-apis
""
{:added "1.2"}
[{:keys [articles] :as interim} name]
[{:keys [articles project] :as interim} name]
(let [all (->> (get-in articles [name :elements])
(filter #(-> % :type (= :api))))]
interim))
(filter #(-> % :type (= :api))))
namespaces (-> (map (comp symbol :namespace) all))]
(-> interim
(update-in [:references]
(fnil (fn [references]
(reference/reference-namespaces references
(:lookup project)
namespaces))
{})))))

(comment
"DO NOT DELETE!!!!!"

(:lookup PROJECT)
(-> (parse/parse-file
"test/documentation/hara_zip.clj" PROJECT)
(->> (assoc-in {} [:articles "hara-zip" :elements]))
(assoc :project PROJECT)
(collect-references "hara-zip")
:references
keys)
(hara.zip hara.zip.base))

(comment
(do (require '[lucid.publish :as publish]
'[lucid.publish.theme]
'[hara.io.project :as project]
'[lucid.publish.parse :as parse])

(def project-file "/Users/chris/Development/chit/hara/project.clj")

(def PROJECT (let [project (project/project project-file)]
(assoc project :lookup (project/file-lookup project))))))
31 changes: 12 additions & 19 deletions src/lucid/publish/collect/reference.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
(remove references))
sources (concat missing imported)
tests (map #(symbol (str % "-test")) sources)]
(prn "STUFF:" sources tests)
(reduce (fn [references ns]
(if-let [file (lookup ns)]
(->> (code/analyse-file file)
Expand All @@ -26,19 +25,21 @@
(concat sources tests))))

(defn collect-references
""
{:added "1.2"}
[{:keys [articles project] :as interim} name]
(let [lookup (:lookup project)
all (->> (get-in articles [name :elements])
(let [all (->> (get-in articles [name :elements])
(filter #(-> % :type (= :reference))))
namespaces (-> (map (comp symbol namespace symbol :refer) all))]
(update-in interim [:references]
(fnil (fn [references]
(reference-namespaces references lookup namespaces))
{}))))
(-> interim
(update-in [:references]
(fnil (fn [references]
(reference-namespaces references
(:lookup project)
namespaces))
{})))))

(comment
"DO NOT DELETE!!!!!"

(:lookup PROJECT)
(-> (parse/parse-file
"test/documentation/hara_zip.clj" PROJECT)
Expand All @@ -47,14 +48,7 @@
(collect-references "hara-zip")
:references
keys)
(hara.zip hara.zip.base)


)




(hara.zip hara.zip.base))
(comment
(do (require '[lucid.publish :as publish]
'[lucid.publish.theme]
Expand All @@ -64,5 +58,4 @@
(def project-file "/Users/chris/Development/chit/hara/project.clj")

(def PROJECT (let [project (project/project project-file)]
(assoc project :lookup (project/file-lookup project)))))
)
(assoc project :lookup (project/file-lookup project))))))
11 changes: 0 additions & 11 deletions src/lucid/publish/collect/test.clj

This file was deleted.

59 changes: 59 additions & 0 deletions src/lucid/publish/engine/plugin/api.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(ns lucid.publish.engine.plugin.api
(:require [lucid.publish.render.util :as util]
[clojure.string :as string]))

(defn entry-tag [ns var]
(munge (str "entry__" ns "__" var)))

(defn api-entry [[var entry] {:keys [project namespace] :as elem}]
[:div {:class "entry"}
[:a {:name (entry-tag namespace var)}]
[:div {:class "entry-description"}
[:h4 [:b (str var "&nbsp; &nbsp;")]]
[:p [:i (:intro entry)]]]

[:div {:class "entry-option"}
[:h6
"&nbsp;&nbsp;args: "
[:i {:class "args"}
(string/join " " (:arglists entry)) ]
"&nbsp;&nbsp;&nbsp;"
[:a {:href (format "%s/blob/master/%s#L%d-L%d"
(:url project)
(-> entry :source :path)
(-> entry :source :line :row)
(-> entry :source :line :end-row))
:target "_blank"}
"(source)"]]]
(let [code (-> entry :test :code
(util/adjust-indent 2)
(string/trim))]
[:pre
[:h6 [:i [:a {:href (format "%s/blob/master/%s#L%d-L%d"
(:url project)
(-> entry :test :path)
(-> entry :test :line :row)
(-> entry :test :line :end-row))}
"(test code)"]]]
[:code {:class "clojure"} code]])])

(defn api-contents [{:keys [table project] :as elem}]
(->> table
seq
sort
(map #(api-entry % elem))))

(defn api-element
[{:keys [table tag title namespace] :as elem}]
[:div {:class "api"}
[:div [:hr] [:h2 (or title namespace)] [:hr]]
[:div
[:h3 "Outline"]
(apply vector
:ul
(map (fn [v]
[:li [:a {:href (str "#" (entry-tag namespace v))} (str v)]
" - " (get-in table [v :intro])])
(-> table keys sort)))
[:h3 "Contents"]
(apply vector :div (api-contents elem))]])
Loading

0 comments on commit 7954a7b

Please sign in to comment.