Merge pull request #65 from budu/master
Convertion to Clojure 1.3 and some fixes.
This commit is contained in:
commit
cb21d5921a
4 changed files with 81 additions and 65 deletions
11
project.clj
11
project.clj
|
@ -2,19 +2,16 @@
|
|||
:description "lightweight literate programming for clojure -- inspired by [docco](http://jashkenas.github.com/docco/)"
|
||||
:main marginalia.core
|
||||
:dependencies
|
||||
[[org.clojure/clojure "1.2.0"]
|
||||
[org.clojure/clojure-contrib "1.2.0"]
|
||||
[[org.clojure/clojure "1.3.0"]
|
||||
[org.clojure/tools.namespace "0.1.1"]
|
||||
[org.clojure/tools.cli "0.2.1"]
|
||||
[hiccup "0.3.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"]
|
||||
[swank-clojure "1.2.1"]
|
||||
[marginalia "0.7.0-SNAPSHOT"]
|
||||
[lein-marginalia "0.6.1"]]
|
||||
[org.clojars.autre/lein-vimclojure "1.0.0"]]
|
||||
;;Needed for testing Latex equation formatting. You must download
|
||||
;;and install MathJax in you doc directory.
|
||||
:marginalia {:javascript ["mathjax/MathJax.js"]})
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
(:use [marginalia
|
||||
[html :only (uberdoc-html index-html single-page-html)]
|
||||
[parser :only (parse-file)]]
|
||||
[clojure.contrib
|
||||
[find-namespaces :only (read-file-ns-decl)]
|
||||
[command-line :only (print-help with-command-line)]])
|
||||
[clojure.tools
|
||||
[namespace :only (read-file-ns-decl)]
|
||||
[cli :only (cli)]])
|
||||
(:gen-class))
|
||||
|
||||
|
||||
|
@ -216,9 +216,6 @@
|
|||
[%]))
|
||||
(flatten))))
|
||||
|
||||
(defn usage []
|
||||
(println "marginalia <src1> ... <src-n>"))
|
||||
|
||||
(defn split-deps [deps]
|
||||
(when deps
|
||||
(for [d (.split deps ";")
|
||||
|
@ -237,26 +234,24 @@
|
|||
|
||||
If no source files are found, complain with a usage message."
|
||||
[args & [project]]
|
||||
(with-command-line args
|
||||
(str "Leiningen plugin for running marginalia against your project.\n\n"
|
||||
"Usage: lein marg <options?> <src1> ... <src-n>\n")
|
||||
[[dir d "Directory into which the documentation will be written" "./docs"]
|
||||
[file f "File into which the documentation will be written" "uberdoc.html"]
|
||||
[name n "Project name - if not given will be taken from project.clj"]
|
||||
[version v "Project version - if not given will be taken from project.clj"]
|
||||
[desc D "Project description - if not given will be taken from project.clj"]
|
||||
[deps a "Project dependencies in the form <group1>:<artifact1>:<version1>;<group2>...
|
||||
(let [[{:keys [dir file name version desc deps css js]} files help]
|
||||
(cli args
|
||||
["-d" "--dir" "Directory into which the documentation will be written" :default "./docs"]
|
||||
["-f" "--file" "File into which the documentation will be written" :default "uberdoc.html"]
|
||||
["-n" "--name" "Project name - if not given will be taken from project.clj"]
|
||||
["-v" "--version" "Project version - if not given will be taken from project.clj"]
|
||||
["-D" "--desc" "Project description - if not given will be taken from project.clj"]
|
||||
["-a" "--deps" "Project dependencies in the form <group1>:<artifact1>:<version1>;<group2>...
|
||||
If not given will be taken from project.clj"]
|
||||
[css c "Additional css resources <resource1>;<resource2>;...
|
||||
["-c" "--css" "Additional css resources <resource1>;<resource2>;...
|
||||
If not given will be taken from project.clj."]
|
||||
[js j "Additional javascript resources <resource1>;<resource2>;...
|
||||
If not given will be taken from project.clj"]
|
||||
src]
|
||||
(let [sources (format-sources (seq src))]
|
||||
["-j" "--js" "Additional javascript resources <resource1>;<resource2>;...
|
||||
If not given will be taken from project.clj"])
|
||||
sources (format-sources (seq files))]
|
||||
(if-not sources
|
||||
(do
|
||||
(println "Wrong number of arguments passed to marginalia.")
|
||||
(print-help))
|
||||
(println help))
|
||||
(binding [*docs* dir]
|
||||
(let [project-clj (or project
|
||||
(when (.exists (io/file "project.clj"))
|
||||
|
@ -281,7 +276,7 @@
|
|||
(uberdoc! (str *docs* "/" file) sources opts)
|
||||
(println "Done generating your documentation, please see"
|
||||
(str *docs* "/" file))
|
||||
(println "")))))))
|
||||
(println ""))))))
|
||||
|
||||
(defn -main
|
||||
"The main entry point into Marginalia."
|
||||
|
|
|
@ -105,9 +105,9 @@
|
|||
(if (= (:type section) :comment)
|
||||
(:raw section)
|
||||
(:docstring section)))]
|
||||
[:td {:class "codes"}] (if (= (:type section) :code)
|
||||
[:td {:class "codes"} (if (= (:type section) :code)
|
||||
(codes-to-html (:raw section))
|
||||
"")]))
|
||||
"")]]))
|
||||
|
||||
(defn dependencies-html [deps & header-name]
|
||||
(when-let [deps (seq deps)]
|
||||
|
|
|
@ -4,8 +4,33 @@
|
|||
(ns marginalia.parser
|
||||
"Provides the parsing facilities for Marginalia."
|
||||
(:refer-clojure :exclude [replace])
|
||||
(:use [clojure.contrib [reflect :only (get-field call-method)]]
|
||||
[clojure [string :only (join replace)]]))
|
||||
(:use [clojure [string :only (join replace)]]))
|
||||
|
||||
|
||||
;; Extracted from clojure.contrib.reflect
|
||||
(defn get-field
|
||||
"Access to private or protected field. field-name is a symbol or
|
||||
keyword."
|
||||
[klass field-name obj]
|
||||
(-> klass (.getDeclaredField (name field-name))
|
||||
(doto (.setAccessible true))
|
||||
(.get obj)))
|
||||
|
||||
;; Extracted from clojure.contrib.reflect
|
||||
(defn call-method
|
||||
"Calls a private or protected method.
|
||||
|
||||
params is a vector of classes which correspond to the arguments to
|
||||
the method e
|
||||
|
||||
obj is nil for static methods, the instance object otherwise.
|
||||
|
||||
The method-name is given a symbol or a keyword (something Named)."
|
||||
[klass method-name params obj & args]
|
||||
(-> klass (.getDeclaredMethod (name method-name)
|
||||
(into-array Class params))
|
||||
(doto (.setAccessible true))
|
||||
(.invoke obj (into-array Object args))))
|
||||
|
||||
(defrecord Comment [content])
|
||||
|
||||
|
@ -15,7 +40,7 @@
|
|||
(def top-level-comments (atom []))
|
||||
(def sub-level-comments (atom []))
|
||||
|
||||
(def *comments* nil)
|
||||
(def ^{:dynamic true} *comments* nil)
|
||||
|
||||
(defn read-comment [reader semicolon]
|
||||
(let [sb (StringBuilder.)]
|
||||
|
@ -123,8 +148,7 @@
|
|||
(if (symbol? sym)
|
||||
(do
|
||||
(when (= 'ns (first form))
|
||||
(try (require sym)
|
||||
(catch Exception _)))
|
||||
(require sym))
|
||||
(let [nspace (find-ns sym)
|
||||
docstring (if nspace
|
||||
(-> nspace meta :doc)
|
||||
|
|
Loading…
Reference in a new issue