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:
dm3 2011-07-28 04:23:53 +08:00 committed by fogus
parent 0cec5a0cd1
commit b76df81683
6 changed files with 75 additions and 17 deletions

View file

@ -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"]

View file

@ -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 %))))
@ -168,6 +168,28 @@
;; ## 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!
"Generates an uberdoc html file from 3 pieces of information:

View 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

View file

@ -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)))

View file

@ -0,0 +1,6 @@
;; # The First Part
(ns first-part)
;; This function represents the essence of the essence
(defn essence [essence]
(+ essence essence))

View file

@ -0,0 +1,6 @@
;; # The Second Part
(ns second-part)
;; This function represents the nature of the nature
(defn nature [nature]
(+ nature nature))