Merge remote-tracking branch 'upstream/master'

Conflicts:
	README.md
This commit is contained in:
Frederick Giasson 2015-01-16 14:32:20 -05:00
commit eb8808706a
9 changed files with 63 additions and 30 deletions

View file

@ -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.

View file

@ -2751,7 +2751,7 @@ I wonder?</p>
(group-lines))]
{:ns ns
:groups groups}))
</pre></td></tr><tr><td class="docs"><h2>Ouput Generation</h2>
</pre></td></tr><tr><td class="docs"><h2>Output Generation</h2>
</td><td class="codes"><pre class="brush: clojure"></pre></td></tr><tr><td class="docs"><p>Generates an uberdoc html file from 3 pieces of information:</p>
<ol>
@ -3199,7 +3199,7 @@ saying that all this is WIP and will prabably change in the future.</p>
&quot;SyntaxHighlighter.defaults['gutter'] = false;
SyntaxHighlighter.all()&quot;]]]))
</pre></td></tr><tr><td class="docs"><p>Syntax highlighting is done a bit differently than docco. Instead of embedding
the higlighting metadata on the parse / html gen phase, we use <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a>
the highlighting metadata on the parse / html gen phase, we use <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a>
to do it in javascript.</p>
</td><td class="codes"><pre class="brush: clojure"></pre></td></tr><tr><td class="docs"><p>This generates a stand alone html file (think <code>lein uberjar</code>).
It's probably the only var consumers will use.</p>

View file

@ -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
@ -125,7 +124,11 @@
(let [rdr (clojure.lang.LineNumberingPushbackReader.
(java.io.FileReader.
(java.io.File. path)))]
(parse-project-form (read rdr)))
(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

View file

@ -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

View file

@ -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*))
(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
*comments-enabled* (atom true)]
(parse (slurp file)))))
(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))))

View file

@ -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:

View file

@ -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")))))

View file

@ -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

View file

@ -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"]])