From 1dbbd42862b270a10f6ed9ce071ea247dde3baf8 Mon Sep 17 00:00:00 2001
From: David Tulig
Date: Sat, 27 Dec 2014 14:41:34 -0600
Subject: [PATCH 1/6] Addresses an issue where marginalia fails to parse a
project.clj where the first form in the file isn't "defproject".
Instead of reading just the first line, parse-project-form will loop
through the full file, stopping when defproject is found and then
parse it as it always has.
---
src/marginalia/core.clj | 10 +++++++---
test/marginalia/test/core.clj | 6 ++++++
test/marginalia/test/multi-def-project.clj.txt | 10 ++++++++++
3 files changed, 23 insertions(+), 3 deletions(-)
create mode 100644 test/marginalia/test/core.clj
create mode 100644 test/marginalia/test/multi-def-project.clj.txt
diff --git a/src/marginalia/core.clj b/src/marginalia/core.clj
index 09ffdc2..eaaccda 100644
--- a/src/marginalia/core.clj
+++ b/src/marginalia/core.clj
@@ -123,9 +123,13 @@
([path]
(try
(let [rdr (clojure.lang.LineNumberingPushbackReader.
- (java.io.FileReader.
- (java.io.File. path)))]
- (parse-project-form (read rdr)))
+ (java.io.FileReader.
+ (java.io.File. path)))]
+ (loop [line (read rdr)]
+ (let [found-project? (= 'defproject (first line))]
+ (if found-project?
+ (parse-project-form line)
+ (recur (read rdr))))))
(catch Exception e
(throw (Exception.
(str
diff --git a/test/marginalia/test/core.clj b/test/marginalia/test/core.clj
new file mode 100644
index 0000000..4986954
--- /dev/null
+++ b/test/marginalia/test/core.clj
@@ -0,0 +1,6 @@
+(ns marginalia.test.core
+ (:require marginalia.core)
+ (:use clojure.test))
+
+(deftest parse-project-file-simple
+ (is (= "project-name" (:name (marginalia.core/parse-project-file "test/marginalia/test/multi-def-project.clj.txt")))))
diff --git a/test/marginalia/test/multi-def-project.clj.txt b/test/marginalia/test/multi-def-project.clj.txt
new file mode 100644
index 0000000..ff56e65
--- /dev/null
+++ b/test/marginalia/test/multi-def-project.clj.txt
@@ -0,0 +1,10 @@
+(defn some-other-form
+ []
+ (= 1 1))
+
+(defproject project-name "0.1.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :url "http://example.com/FIXME"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :dependencies [[org.clojure/clojure "1.6.0"]])
From 0e43f515a90645ac64fac3b73814eafc4ddeaca0 Mon Sep 17 00:00:00 2001
From: Martin Bilski
Date: Tue, 6 Jan 2015 15:43:13 +0100
Subject: [PATCH 2/6] Add support for cljx reader tags #+clj and #+cljs to make
it possible to generate marginalia docs in projects using cljx to target
Clojure and ClojureScript.
---
src/marginalia/parser.clj | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/marginalia/parser.clj b/src/marginalia/parser.clj
index 709d5ae..297ffb5 100644
--- a/src/marginalia/parser.clj
+++ b/src/marginalia/parser.clj
@@ -391,10 +391,17 @@
(defn cljs-file? [filepath]
(.endsWith (lower-case filepath) "cljs"))
+(defn cljx-file? [filepath]
+ (.endsWith (lower-case filepath) "cljx"))
+
+(def cljx-data-readers {'+clj identity
+ '+cljs identity})
+
(defn parse-file [file]
- (let [readers (if (cljs-file? file)
- (->> default-data-readers (merge *cljs-data-readers*))
- default-data-readers)]
+ (let [readers (merge {}
+ (when (cljs-file? file) *cljs-data-readers*)
+ (when (cljx-file? file) cljx-data-readers)
+ default-data-readers)]
(binding [*data-readers* readers
*comments-enabled* (atom true)]
(parse (slurp file)))))
From 319f26693d4d34901c61ed972f88293bc9e6da7d Mon Sep 17 00:00:00 2001
From: Martin Bilski
Date: Tue, 6 Jan 2015 22:22:10 +0100
Subject: [PATCH 3/6] Fix no namespace extracted from .cljx files.
---
src/marginalia/core.clj | 16 ++++------------
src/marginalia/parser.clj | 32 +++++++++++++++++++++++---------
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/src/marginalia/core.clj b/src/marginalia/core.clj
index 09ffdc2..8622160 100644
--- a/src/marginalia/core.clj
+++ b/src/marginalia/core.clj
@@ -36,9 +36,8 @@
[clojure.string :as str])
(:use [marginalia
[html :only (uberdoc-html index-html single-page-html)]
- [parser :only (parse-file)]]
+ [parser :only (parse-file parse-ns)]]
[clojure.tools
- [namespace :only (read-file-ns-decl)]
[cli :only (cli)]]))
@@ -93,7 +92,7 @@
(->> (io/file dir)
(file-seq)
(filter (partial processable-file? pred))
- (sort-by #(->> % read-file-ns-decl second))
+ (sort-by #(->> % parse-ns second))
(map #(.getCanonicalPath %))))
;; ## Project Info Parsing
@@ -170,15 +169,8 @@
:else (recur (merge-line (first lines) cur-group) groups (rest lines)))))
(defn path-to-doc [fn]
- (let [file (java.io.File. fn)
- ns (-> file
- (read-file-ns-decl)
- (second)
- (str))
- ns (if (or (nil? ns) (empty? ns)) (.getName file) ns)
- groups (parse-file fn)]
- {:ns ns
- :groups groups}))
+ {:ns (parse-ns (java.io.File. fn))
+ :groups (parse-file fn)})
;; ## Output Generation
diff --git a/src/marginalia/parser.clj b/src/marginalia/parser.clj
index 297ffb5..0721981 100644
--- a/src/marginalia/parser.clj
+++ b/src/marginalia/parser.clj
@@ -5,7 +5,8 @@
"Provides the parsing facilities for Marginalia."
(:refer-clojure :exclude [replace])
(:use [clojure [string :only (join replace lower-case)]]
- [cljs.tagged-literals :only [*cljs-data-readers*]]))
+ [cljs.tagged-literals :only [*cljs-data-readers*]]
+ [clojure.tools.namespace :only (read-file-ns-decl)]))
;; Extracted from clojure.contrib.reflect
@@ -397,11 +398,24 @@
(def cljx-data-readers {'+clj identity
'+cljs identity})
-(defn parse-file [file]
- (let [readers (merge {}
- (when (cljs-file? file) *cljs-data-readers*)
- (when (cljx-file? file) cljx-data-readers)
- default-data-readers)]
- (binding [*data-readers* readers
- *comments-enabled* (atom true)]
- (parse (slurp file)))))
+(defmacro with-readers-for [file & body]
+ `(let [readers# (merge {}
+ (when (cljs-file? ~file) *cljs-data-readers*)
+ (when (cljx-file? ~file) cljx-data-readers)
+ default-data-readers)]
+ (binding [*data-readers* readers#]
+ ~@body)))
+
+(defn parse-file [fn]
+ (with-readers-for fn
+ (binding [*comments-enabled* (atom true)]
+ (parse (slurp fn)))))
+
+(defn parse-ns [file]
+ (let [filename (.getName file)]
+ (with-readers-for filename
+ (or (not-empty (-> file
+ (read-file-ns-decl)
+ (second)
+ (str)))
+ filename))))
\ No newline at end of file
From e35c3baeff72cc1d7e122a82584bc5c662f2b9bd Mon Sep 17 00:00:00 2001
From: Martin Bilski
Date: Tue, 6 Jan 2015 22:25:40 +0100
Subject: [PATCH 4/6] Fix no newline at the end of parser.clj.
---
src/marginalia/parser.clj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/marginalia/parser.clj b/src/marginalia/parser.clj
index 0721981..3283d2d 100644
--- a/src/marginalia/parser.clj
+++ b/src/marginalia/parser.clj
@@ -418,4 +418,4 @@
(read-file-ns-decl)
(second)
(str)))
- filename))))
\ No newline at end of file
+ filename))))
From e7806a7a456a9fb93b6cd4b01b8f1093a16ec135 Mon Sep 17 00:00:00 2001
From: Martin Harrigan
Date: Wed, 7 Jan 2015 15:07:20 +0000
Subject: [PATCH 5/6] Fix typos
---
site/src/uberdoc.html | 4 ++--
src/marginalia/html.clj | 2 +-
src/problem_cases/general.clj | 2 +-
test/marginalia/test/helpers.clj | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/site/src/uberdoc.html b/site/src/uberdoc.html
index 963bea8..52f83b3 100644
--- a/site/src/uberdoc.html
+++ b/site/src/uberdoc.html
@@ -2751,7 +2751,7 @@ I wonder?
(group-lines))]
{:ns ns
:groups groups}))
-Ouput Generation
+ |
Output Generation
| |
Generates an uberdoc html file from 3 pieces of information:
@@ -3199,7 +3199,7 @@ saying that all this is WIP and will prabably change in the future.
"SyntaxHighlighter.defaults['gutter'] = false;
SyntaxHighlighter.all()"]]]))
|
Syntax highlighting is done a bit differently than docco. Instead of embedding
-the higlighting metadata on the parse / html gen phase, we use SyntaxHighlighter
+the highlighting metadata on the parse / html gen phase, we use SyntaxHighlighter
to do it in javascript.
| |
This generates a stand alone html file (think lein uberjar ).
It's probably the only var consumers will use.
diff --git a/src/marginalia/html.clj b/src/marginalia/html.clj
index 746bbd0..27db23d 100644
--- a/src/marginalia/html.clj
+++ b/src/marginalia/html.clj
@@ -386,7 +386,7 @@
;; Syntax highlighting is done a bit differently than docco. Instead of embedding
-;; the higlighting metadata on the parse / html gen phase, we use [SyntaxHighlighter](http://alexgorbatchev.com/SyntaxHighlighter/)
+;; the highlighting metadata on the parse / html gen phase, we use [SyntaxHighlighter](http://alexgorbatchev.com/SyntaxHighlighter/)
;; to do it in javascript.
(defn uberdoc-html
diff --git a/src/problem_cases/general.clj b/src/problem_cases/general.clj
index 47924b6..cff2aab 100644
--- a/src/problem_cases/general.clj
+++ b/src/problem_cases/general.clj
@@ -105,7 +105,7 @@
"GENERATED ALWAYS AS IDENTITY")
(defn strict-eval-op-fn
- "`strict-eval-op-fn` is used to define functions of the above pattern for fuctions such as `+`, `*`, etc. Cljs special forms defined this way are applyable, such as `(apply + [1 2 3])`.
+ "`strict-eval-op-fn` is used to define functions of the above pattern for functions such as `+`, `*`, etc. Cljs special forms defined this way are applyable, such as `(apply + [1 2 3])`.
Resulting expressions are wrapped in an anonymous function and, down the line, `call`ed, like so:
diff --git a/test/marginalia/test/helpers.clj b/test/marginalia/test/helpers.clj
index e3a5191..f06b9fd 100644
--- a/test/marginalia/test/helpers.clj
+++ b/test/marginalia/test/helpers.clj
@@ -27,7 +27,7 @@
Provides the following variables to the assertion context:
* `number-of-generated-pages` - result of running the `doc-generator`
- function (which should ultimately call one of the marginalias' own
+ function (which should ultimately call one of the Marginalia's own
functions.
* `project-name` - the name of the project
From 45cf608e6f783b84cd68537e65675235645d45d9 Mon Sep 17 00:00:00 2001
From: Ben Bader
Date: Wed, 7 Jan 2015 10:52:00 -0800
Subject: [PATCH 6/6] Update copyright and fix broken contributor link
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index fc7fc84..e929bf8 100644
--- a/README.md
+++ b/README.md
@@ -118,13 +118,13 @@ Marginalia is...
- [Tero Parviainen](https://github.com/teropa)
- [MerelyAPseudonym](https://github.com/MerelyAPseudonym)
- [Ivan](https://github.com/ivantm)
-- [benjamin bader] (https://github.com/benjamin-bader)
+- [Benjamin Bader](https://github.com/benjamin-bader)
If I've missed your name then please ping me.
License
-------
-Copyright (C) 2010-2013 Fogus and contributors.
+Copyright (C) 2010-2015 Fogus and contributors.
Distributed under the Eclipse Public License, the same as Clojure.
|