diff --git a/README.md b/README.md index 7d50267..cb274dd 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ 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) - [Frederick Giasson](https://github.com/fgiasson) If I've missed your name then please ping me. @@ -127,6 +127,6 @@ 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. 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/core.clj b/src/marginalia/core.clj index 6274c1b..6577d3b 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 @@ -123,9 +122,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 @@ -170,15 +173,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/html.clj b/src/marginalia/html.clj index 4275c5e..89c59a8 100644 --- a/src/marginalia/html.clj +++ b/src/marginalia/html.clj @@ -395,7 +395,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/marginalia/parser.clj b/src/marginalia/parser.clj index 709d5ae..3283d2d 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 @@ -391,10 +392,30 @@ (defn cljs-file? [filepath] (.endsWith (lower-case filepath) "cljs")) -(defn parse-file [file] - (let [readers (if (cljs-file? file) - (->> default-data-readers (merge *cljs-data-readers*)) - default-data-readers)] - (binding [*data-readers* readers - *comments-enabled* (atom true)] - (parse (slurp file))))) +(defn cljx-file? [filepath] + (.endsWith (lower-case filepath) "cljx")) + +(def cljx-data-readers {'+clj identity + '+cljs identity}) + +(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)))) 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/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/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 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"]])