dependenciesorg.clojure/clojure |
| 1.2.0 | org.clojars.nakkaya/markdownj |
| 1.0.2b4 | hiccup |
| 0.3.0 |
dev dependencieslein-clojars |
| 0.5.0-SNAPSHOT | jline |
| 0.9.94 | swank-clojure |
| 1.2.1 | hiccup |
| 0.3.0 | org.clojars.nakkaya/markdownj |
| 1.0.2b4 | marginalia |
| 0.2.1 |
|
(this space intentionally left blank) |
| |
| |
Core provides all of the functionality around parsing clojure source files
into an easily consumable format.
| (ns marginalia.core
(:require [clojure.java.io :as io]
@@ -2569,7 +2540,9 @@ into an easily consumable format.
| (def *comment* #"^\s*;;\s?") |
| (def *divider-text* "\n;;DIVIDER\n")
(def *divider-html* #"\n*<span class=\"c[1]?\">;;DIVIDER</span>\n*") |
File System Utilities
- | |
+ | |
Performs roughly the same task as the UNIX ls . That is, returns a seq of the filenames
+at a given directory. If a path to a file is supplied, then the seq contains only the
+original path given.
|
(defn ls
[path]
@@ -2580,36 +2553,38 @@ into an easily consumable format.
[path])))) |
|
(defn mkdir [path]
- (.mkdirs (io/file path))) |
+ (.mkdirs (io/file path))) |
Ensure that the directory specified by path exists. If not then make it so.
+Here is a snowman ☃
|
-(defn ensure-directory! [path]
+(defn ensure-directory!
+ [path]
(when-not (ls path)
(mkdir path))) |
|
(defn dir? [path]
(.isDirectory (java.io.File. path))) |
Returns a seq of clojure file paths (strings) in alphabetical depth-first order (I think?).
|
-(defn find-clojure-file-paths [dir]
+(defn find-clojure-file-paths
+ [dir]
(->> (java.io.File. dir)
(file-seq)
(filter #(re-find #"\.clj$" (.getAbsolutePath %)))
- (map #(.getAbsolutePath %))))
- |
Project Info Parsing
+ (map #(.getAbsolutePath %)))) |
Project Info Parsing
Marginalia will parse info out of your project.clj to display in
the generated html file's header.
-TODO: add pom.xml support.
+ add pom.xml support.
|
|
Parses a project.clj file and returns a map in the following form
-ex. {:name
- :version
- :dependencies
- :dev-dependencies
- etc...}
+{:name
+ :version
+ :dependencies
+ :dev-dependencies
+ etc...}
by reading the defproject form from your project.clj to obtain name and
@@ -2671,28 +2646,28 @@ version, then merges in the rest of the defproject forms (:dependencies(defn docstring-line? [line sections]
(let [l (last sections)
last-code-text (get l :code-text "")]
- (try |
|
Is the last line's code-text a defn, and does the
-current line start with a quote?
+ (try |
Last line contain defn &&
+last line not contain what looks like a param vector &&
+current line start with a quote
| (or
- (and (re-find #"\(defn" last-code-text) |
Is the last line's code-text a deftask, and does the
+ (and (re-find #"\(defn" last-code-text)
+ (not (re-find #"\[.*\]" last-code-text)) |
Is the last line's code-text a deftask, and does the
current line start with a quote?
| (re-find #"^\"" (str/trim (str line))))
- (and (re-find #"\(deftask" last-code-text) |
Is the last line's code-text the start of a ns
+ (and (re-find #"^\(deftask" (str/trim last-code-text)) |
Is the last line's code-text the start of a ns
decl, and does the current line start with a quote?
| (re-find #"^\"" (str/trim (str line))))
- (and (re-find #"\(ns" last-code-text) |
Is the prev line a docstring line, the current line not
-start with a ( or [ or {, and the current line not an empty string?
+ (and (re-find #"^\(ns" last-code-text) |
Is the prev line a docstring, prev line not end with a quote,
+and the current line empty?
| (re-find #"^\"" (str/trim (str line))))
- (and (:docstring-text l)
- (not (re-find #"^\(" (str/trim (str line))))
- (not (re-find #"^\[" (str/trim (str line))))
- (not (re-find #"^\{" (str/trim (str line)))) |
Is the prev line a docstring, the prev line not end with a quote,
+ (and (:docstring-text l) |
Is the prev line a docstring, the prev line not end with a quote,
and the current line not an empty string?
- | (not= "" (str/trim (str line))))
+ | (not (re-find #"\"$" (str/trim (:docstring-text l)))))
(and (:docstring-text l)
- (not (re-find #"\"$" (str/trim (:docstring-text l))))
+ (not (re-find #"[^\\]\"$" (str/trim (:docstring-text l))))
(= "" (str/trim (str line)))))
- (catch Exception e nil)))) |
+ (catch Exception e nil))))
+ |
|
(defn parse [src]
(loop [[line & more] (line-seq src) cnum 1 dnum 0 sections []]
@@ -2743,7 +2718,8 @@ I wonder?
The path to spit the result (output-file-name )
|
-(defn uberdoc! [output-file-name files-to-analyze]
+(defn uberdoc!
+ [output-file-name files-to-analyze]
(let [docs (map path-to-doc files-to-analyze)
source (uberdoc-html
output-file-name
@@ -2784,7 +2760,8 @@ Multi line
|
(defn -main
[sources]
- (run-marginalia sources)) |
Example Usage
+ (run-marginalia sources))
+ |
Example Usage
|
(comment |
Command line example
|
@@ -2826,7 +2803,8 @@ Multi line
ex. (css [:h1 {:color "blue"}] [:div.content p {:text-indent "1em"}])
→ h1 {color: blue;} div.content p {text-indent: 1em;}
|
-(defn css [& rules]
+(defn css
+ [& rules]
(html [:style {:type "text/css"}
(apply str (map css-rule rules))])) |
Stolen from leiningen
|
@@ -2852,10 +2830,11 @@ Multi line
based) for display through html & css.
| |
| |
Markdown processor.
- | (def mdp (com.petebevin.markdown.MarkdownProcessor.)) |
Markdown string to html converter. Translates strings like "# header!
-→ "<h1>header!</h1>
+ | (def mdp (com.petebevin.markdown.MarkdownProcessor.)) |
Markdown string to html converter. Translates strings like "# header!
|
-(defn md [s]
+(defn md
+ -> \"<h1>header!</h1>"
+ [s]
(.markdown mdp s)) |
Inserts super-fancy characters into the doc section.
|
(defn replace-special-chars
@@ -2932,7 +2911,33 @@ outlined above.
(html [:div {:class "plugins"}
[:h3 "cake plugin namespaces"]
[:ul
- (map #(vector :li %) tasks)]]))) |
Is overloaded? Maybe we should consider redistributing
+ (map #(vector :li %) tasks)]]))) |
Load Optional Resources
+
+Use external Javascript and CSS in your documentation. For example:
+To format Latex math equations, download the
+MathJax Javascript library to the docs
+directory and then add
+
+:marginalia {:javascript ["mathjax/MathJax.js"]}
+
+
+to project.clj. Below is a simple example of both inline and block
+formatted equations.
+
+When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
+$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
+ | |
Generate script and link tags for optional external javascript and css.
+ |
+(defn opt-resources-html
+ [project-info]
+ (let [options (:marginalia project-info)
+ javascript (:javascript options)
+ css (:css options)]
+ (html (concat
+ (when javascript
+ (map #(vector :script {:type "text/javascript" :src %}) javascript))
+ (when css
+ (map #(vector :link {:tyle "text/css" :rel "stylesheet" :href %}) css)))))) |
Is overloaded? Maybe we should consider redistributing
| |
header numbers instead of adding classes to all the h1 tags.
| (defn header-html [project-info]
(html
@@ -3111,7 +3116,8 @@ outlined above.
& inline-css ) to be able to package the output as a single file (uberdoc if you will). It goes without
saying that all this is WIP and will prabably change in the future.
|
-(defn page-template [header toc floating-toc content]
+(defn page-template
+ [opt-resources header toc floating-toc content]
(html
(doctype :html5)
[:html
@@ -3130,6 +3136,7 @@ saying that all this is WIP and will prabably change in the future.
header-css
floating-toc-css
general-css
+ opt-resources
[:title "Marginalia Output"]]
[:body
[:table
@@ -3156,6 +3163,7 @@ It's probably the only var consumers will use.
(defn uberdoc-html
[output-file-name project-metadata docs]
(page-template
+ (opt-resources-html project-metadata)
(header-html project-metadata)
(toc-html docs)
(floating-toc-html docs)
@@ -3165,7 +3173,7 @@ It's probably the only var consumers will use.
Usage
-- In your project.clj, add
[marginalia "0.2.0"] to your :dev-dependenciesand marginalia.tasksto :tasks`
+- In your project.clj, add
[marginalia "0.2.1"] to your :dev-dependenciesand marginalia.tasksto :tasks`
- Run
cake marg from within your project directory.
| (ns marginalia.tasks
@@ -3175,5 +3183,44 @@ Optionally, you can pass files or directories to control what documentation is g
|
(deftask marg
{files :marg}
- (run-marginalia files)) |
| |