Multidoc (splitting docs into multiple pages).
Implemented basic test framework for working with source trees (similar to what is done in http://github.com/technomancy/leiningen). Basic functionality of writing separate source files to separate output files.
This commit is contained in:
parent
0cec5a0cd1
commit
b76df81683
6 changed files with 75 additions and 17 deletions
|
@ -8,6 +8,7 @@
|
||||||
[org.markdownj/markdownj "0.3.0-1.0.2b4"]]
|
[org.markdownj/markdownj "0.3.0-1.0.2b4"]]
|
||||||
:dev-dependencies
|
:dev-dependencies
|
||||||
[[lein-clojars "0.6.0"]
|
[[lein-clojars "0.6.0"]
|
||||||
|
[lein-marginalia "0.6.0"]
|
||||||
[jline "0.9.94"]
|
[jline "0.9.94"]
|
||||||
;; lein vimclojure& #starts the nailgun server
|
;; lein vimclojure& #starts the nailgun server
|
||||||
[org.clojars.autre/lein-vimclojure "1.0.0"]
|
[org.clojars.autre/lein-vimclojure "1.0.0"]
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
(defn find-clojure-file-paths
|
(defn find-clojure-file-paths
|
||||||
"Returns a seq of clojure file paths (strings) in alphabetical depth-first order."
|
"Returns a seq of clojure file paths (strings) in alphabetical depth-first order."
|
||||||
[dir]
|
[dir]
|
||||||
(->> (java.io.File. dir)
|
(->> (io/file dir)
|
||||||
(file-seq)
|
(file-seq)
|
||||||
(filter #(re-find #"\.clj$" (.getAbsolutePath %)))
|
(filter #(re-find #"\.clj$" (.getAbsolutePath %)))
|
||||||
(map #(.getAbsolutePath %))))
|
(map #(.getAbsolutePath %))))
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
(defn parse-project-form
|
(defn parse-project-form
|
||||||
"Parses a project.clj file and returns a map in the following form
|
"Parses a project.clj file and returns a map in the following form
|
||||||
|
|
||||||
{:name
|
{:name
|
||||||
:version
|
:version
|
||||||
:dependencies
|
:dependencies
|
||||||
:dev-dependencies
|
:dev-dependencies
|
||||||
|
@ -168,6 +168,28 @@
|
||||||
|
|
||||||
;; ## Ouput Generation
|
;; ## Ouput Generation
|
||||||
|
|
||||||
|
(defn index-html
|
||||||
|
[props files]
|
||||||
|
"<html></html>")
|
||||||
|
|
||||||
|
(defn single-page-html
|
||||||
|
[file]
|
||||||
|
(str "<html><body>" file "</body></html>"))
|
||||||
|
|
||||||
|
(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!
|
(defn uberdoc!
|
||||||
"Generates an uberdoc html file from 3 pieces of information:
|
"Generates an uberdoc html file from 3 pieces of information:
|
||||||
|
|
||||||
|
@ -277,7 +299,7 @@
|
||||||
(comment
|
(comment
|
||||||
;; Command line example
|
;; Command line example
|
||||||
(-main "./src/marginalia/core.clj" "./src/marginalia/html.clj")
|
(-main "./src/marginalia/core.clj" "./src/marginalia/html.clj")
|
||||||
|
|
||||||
;; This will find all marginalia source files, and then generate an uberdoc.
|
;; This will find all marginalia source files, and then generate an uberdoc.
|
||||||
(apply -main (find-clojure-file-paths "./src"))
|
(apply -main (find-clojure-file-paths "./src"))
|
||||||
|
|
||||||
|
|
36
test/marginalia/test/multidoc.clj
Normal file
36
test/marginalia/test/multidoc.clj
Normal file
|
@ -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
|
|
@ -1,24 +1,11 @@
|
||||||
(ns parse-test
|
(ns marginalia.test.parse
|
||||||
"This module does stuff"
|
"This module does stuff"
|
||||||
(:require [clojure.string :as str])
|
|
||||||
(:use clojure.test)
|
(:use clojure.test)
|
||||||
(:require marginalia.parser))
|
(: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
|
(deftest test-inline-literals
|
||||||
(is (= (count (marginalia.parser/parse "(ns test)")) 1))
|
(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")) 1)) still failing
|
||||||
(is (= (count (marginalia.parser/parse "(ns test)\n123\n")) 1))
|
(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\"string\"")) 1))
|
||||||
(is (= (count (marginalia.parser/parse "(ns test)\n\"some string\"")) 1)))
|
(is (= (count (marginalia.parser/parse "(ns test)\n\"some string\"")) 1)))
|
6
test_projects/multi_page/src/first_part.clj
Normal file
6
test_projects/multi_page/src/first_part.clj
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
;; # The First Part
|
||||||
|
(ns first-part)
|
||||||
|
|
||||||
|
;; This function represents the essence of the essence
|
||||||
|
(defn essence [essence]
|
||||||
|
(+ essence essence))
|
6
test_projects/multi_page/src/second_part.clj
Normal file
6
test_projects/multi_page/src/second_part.clj
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
;; # The Second Part
|
||||||
|
(ns second-part)
|
||||||
|
|
||||||
|
;; This function represents the nature of the nature
|
||||||
|
(defn nature [nature]
|
||||||
|
(+ nature nature))
|
Loading…
Reference in a new issue