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
1027d5bba3
commit
5566664050
6 changed files with 75 additions and 16 deletions
|
@ -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"]
|
||||
|
|
|
@ -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]
|
||||
"<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:
|
||||
|
||||
|
@ -248,7 +270,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"))
|
||||
|
||||
|
|
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,20 +1,8 @@
|
|||
(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
|
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