diff --git a/project.clj b/project.clj index 9206d1a..93e25ed 100644 --- a/project.clj +++ b/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"]}) diff --git a/src/marginalia/core.clj b/src/marginalia/core.clj index 8c537d5..0589357 100644 --- a/src/marginalia/core.clj +++ b/src/marginalia/core.clj @@ -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 ... ")) - (defn split-deps [deps] (when deps (for [d (.split deps ";") @@ -237,51 +234,49 @@ 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 ... \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 ::;... - If not given will be taken from project.clj"] - [css c "Additional css resources ;;... - If not given will be taken from project.clj."] - [js j "Additional javascript resources ;;... - If not given will be taken from project.clj"] - src] - (let [sources (format-sources (seq src))] - (if-not sources - (do - (println "Wrong number of arguments passed to marginalia.") - (print-help)) - (binding [*docs* dir] - (let [project-clj (or project - (when (.exists (io/file "project.clj")) - (parse-project-file))) - choose #(or %1 %2) - marg-opts (merge-with choose - {:css (when css (.split css ";")) - :javascript (when js (.split js ";"))} - (:marginalia project-clj)) - opts (merge-with choose - {:name name - :version version - :description desc - :dependencies (split-deps deps) - :marginalia marg-opts} - project-clj)] - (println "Generating uberdoc for the following source files:") - (doseq [s sources] - (println " " s)) - (println) - (ensure-directory! *docs*) - (uberdoc! (str *docs* "/" file) sources opts) - (println "Done generating your documentation, please see" - (str *docs* "/" file)) - (println ""))))))) + (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 ::;... + If not given will be taken from project.clj"] + ["-c" "--css" "Additional css resources ;;... + If not given will be taken from project.clj."] + ["-j" "--js" "Additional javascript resources ;;... + 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.") + (println help)) + (binding [*docs* dir] + (let [project-clj (or project + (when (.exists (io/file "project.clj")) + (parse-project-file))) + choose #(or %1 %2) + marg-opts (merge-with choose + {:css (when css (.split css ";")) + :javascript (when js (.split js ";"))} + (:marginalia project-clj)) + opts (merge-with choose + {:name name + :version version + :description desc + :dependencies (split-deps deps) + :marginalia marg-opts} + project-clj)] + (println "Generating uberdoc for the following source files:") + (doseq [s sources] + (println " " s)) + (println) + (ensure-directory! *docs*) + (uberdoc! (str *docs* "/" file) sources opts) + (println "Done generating your documentation, please see" + (str *docs* "/" file)) + (println "")))))) (defn -main "The main entry point into Marginalia." diff --git a/src/marginalia/html.clj b/src/marginalia/html.clj index f64aae8..912b2b8 100644 --- a/src/marginalia/html.clj +++ b/src/marginalia/html.clj @@ -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)] diff --git a/src/marginalia/parser.clj b/src/marginalia/parser.clj index 5f92a07..2bd07ec 100644 --- a/src/marginalia/parser.clj +++ b/src/marginalia/parser.clj @@ -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)