Permalink
Browse files

Converted the project to use Clojure 1.3.0 and got rid of contrib.

  • Loading branch information...
1 parent ae296b3 commit e3b54c86951abf684a703fef8989598ffb9d3f51 @budu committed Nov 14, 2011
Showing with 78 additions and 61 deletions.
  1. +4 −7 project.clj
  2. +46 −51 src/marginalia/core.clj
  3. +28 −3 src/marginalia/parser.clj
View
@@ -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"]})
View
@@ -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,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 <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>...
- If not given will be taken from project.clj"]
- [css c "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))]
- (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 <group1>:<artifact1>:<version1>;<group2>...
+ If not given will be taken from project.clj"]
+ ["-c" "--css" "Additional css resources <resource1>;<resource2>;...
+ If not given will be taken from project.clj."]
+ ["-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.")
+ (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."
View
@@ -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.)]

0 comments on commit e3b54c8

Please sign in to comment.