diff --git a/project.clj b/project.clj index f06ba15..d9d5e51 100644 --- a/project.clj +++ b/project.clj @@ -8,6 +8,7 @@ [org.markdownj/markdownj "0.3.0-1.0.2b4"]] :dev-dependencies [[lein-clojars "0.6.0"] + [lein-marginalia "0.6.0"] [jline "0.9.94"] ;; lein vimclojure& #starts the nailgun server [org.clojars.autre/lein-vimclojure "1.0.0"] diff --git a/src/marginalia/core.clj b/src/marginalia/core.clj index 1ece324..c59e3ca 100644 --- a/src/marginalia/core.clj +++ b/src/marginalia/core.clj @@ -78,7 +78,7 @@ (defn find-clojure-file-paths "Returns a seq of clojure file paths (strings) in alphabetical depth-first order." [dir] - (->> (java.io.File. dir) + (->> (io/file dir) (file-seq) (filter #(re-find #"\.clj$" (.getAbsolutePath %))) (map #(.getAbsolutePath %)))) @@ -91,7 +91,7 @@ (defn parse-project-form "Parses a project.clj file and returns a map in the following form - {:name + {:name :version :dependencies :dev-dependencies @@ -168,6 +168,28 @@ ;; ## Ouput Generation +(defn index-html + [props files] + "") + +(defn single-page-html + [file] + (str "" file "")) + +(defn filename-contents + [output-dir parsed-file] + {:name (io/file output-dir (str (:ns parsed-file) ".html")) + :contents (single-page-html parsed-file)}) + +(defn multidoc! + [output-dir files-to-analyze props] + (let [parsed-files (map path-to-doc files-to-analyze) + index (index-html props parsed-files) + pages (map #(filename-contents output-dir %) parsed-files)] + (doseq [f (conj pages {:name (io/file output-dir "index.html") + :contents index})] + (spit (:name f) (:contents f))))) + (defn uberdoc! "Generates an uberdoc html file from 3 pieces of information: @@ -277,7 +299,7 @@ (comment ;; Command line example (-main "./src/marginalia/core.clj" "./src/marginalia/html.clj") - + ;; This will find all marginalia source files, and then generate an uberdoc. (apply -main (find-clojure-file-paths "./src")) diff --git a/test/marginalia/test/multidoc.clj b/test/marginalia/test/multidoc.clj new file mode 100644 index 0000000..5566c4f --- /dev/null +++ b/test/marginalia/test/multidoc.clj @@ -0,0 +1,36 @@ +(ns marginalia.test.multidoc + (:require marginalia.core) + (:use clojure.test) + (:use [clojure.java.io :only (file delete-file)])) + +(def multi-page-project (file "test_projects" "multi_page")) +(def test-project-src (file multi-page-project "src")) +(def test-project-target (file multi-page-project "docs")) + +(use-fixtures :each (fn [f] + (delete-file test-project-target true) + (.mkdirs test-project-target) + (f) + (delete-file test-project-target true))) + +(def test-metadata { + :dependencies [["some/dep" "0.0.1"]] + :description "Test project" + :name "test" + :dev-dependencies [] + :version "0.0.1" +}) + +(defn run-marginalia [source-dir output-dir] + (binding [marginalia.html/*resources* "resources"] + (marginalia.core/multidoc! output-dir + (marginalia.core/find-clojure-file-paths source-dir) + test-metadata))) + +(defn files-in [dir] + (seq (.listFiles (file dir)))) + +(deftest test-multi-page-generation + (do (run-marginalia test-project-src test-project-target) + (is (= (count (files-in test-project-target)) + (+ (count (files-in test-project-src)) 1))))) ;; Additional index file diff --git a/test/parse_test.clj b/test/marginalia/test/parse.clj similarity index 53% rename from test/parse_test.clj rename to test/marginalia/test/parse.clj index 65f5377..7da8a75 100644 --- a/test/parse_test.clj +++ b/test/marginalia/test/parse.clj @@ -1,24 +1,11 @@ -(ns parse-test +(ns marginalia.test.parse "This module does stuff" - (:require [clojure.string :as str]) (:use clojure.test) (:require marginalia.parser)) - -;; It seems that, in Clojure, block -;; comments are used to inform about -;; the next section of code, rather than -;; the next function definition only. - -(defn hello-world [name] - "Greets a person by name. - Does some other cool stuff too." - (println (str "Hello World, " name "!"))) - (deftest test-inline-literals (is (= (count (marginalia.parser/parse "(ns test)")) 1)) ;(is (= (count (marginalia.parser/parse "(ns test)\n123")) 1)) still failing (is (= (count (marginalia.parser/parse "(ns test)\n123\n")) 1)) - (is (= (count (marginalia.parser/parse "(ns test)\n::foo\n")) 1)) (is (= (count (marginalia.parser/parse "(ns test)\n\"string\"")) 1)) (is (= (count (marginalia.parser/parse "(ns test)\n\"some string\"")) 1))) diff --git a/test_projects/multi_page/src/first_part.clj b/test_projects/multi_page/src/first_part.clj new file mode 100644 index 0000000..693094d --- /dev/null +++ b/test_projects/multi_page/src/first_part.clj @@ -0,0 +1,6 @@ +;; # The First Part +(ns first-part) + +;; This function represents the essence of the essence +(defn essence [essence] + (+ essence essence)) diff --git a/test_projects/multi_page/src/second_part.clj b/test_projects/multi_page/src/second_part.clj new file mode 100644 index 0000000..bc3ab4c --- /dev/null +++ b/test_projects/multi_page/src/second_part.clj @@ -0,0 +1,6 @@ +;; # The Second Part +(ns second-part) + +;; This function represents the nature of the nature +(defn nature [nature] + (+ nature nature))