File tree 4 files changed +55
-0
lines changed
4 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ pom.xml
2
+ * jar
3
+ lib
4
+ classes
Original file line number Diff line number Diff line change
1
+ # comb
2
+
3
+ FIXME: write description
4
+
5
+ ## Usage
6
+
7
+ FIXME: write
8
+
9
+ ## License
10
+
11
+ Copyright (C) 2010 FIXME
12
+
13
+ Distributed under the Eclipse Public License, the same as Clojure.
Original file line number Diff line number Diff line change
1
+ (defproject comb " 0.1.0"
2
+ :description " Clojure templating library"
3
+ :dependencies [[org.clojure/clojure " 1.2.0" ]])
Original file line number Diff line number Diff line change
1
+ (ns comb.template
2
+ " Clojure templating library."
3
+ (:refer-clojure :exclude [compile eval]))
4
+
5
+ (defn- read-source [source]
6
+ (if (string? source)
7
+ source
8
+ (slurp source)))
9
+
10
+ (def delimiters [" <%" " %>" ])
11
+
12
+ (def parser-regex
13
+ (re-pattern
14
+ (str " (?s)\\ A"
15
+ " (?:" " (.*?)"
16
+ (first delimiters) " (.*?)" (last delimiters)
17
+ " )?"
18
+ " (.*)\\ z" )))
19
+
20
+ (defn- parse-string [src]
21
+ (lazy-seq
22
+ (let [[_ before expr after] (re-matches parser-regex src)]
23
+ (if expr
24
+ (list* before
25
+ (read-string expr)
26
+ (parse-string after))
27
+ (list after)))))
28
+
29
+ (defmacro compile
30
+ " Compile a template into a function that takes the supplied arguments. The
31
+ template source of the template may be a string, or an IO source such as a
32
+ File, Reader or InputStream."
33
+ [source args]
34
+ `(fn ~args
35
+ (str ~@(parse-string (read-source source)))))
You can’t perform that action at this time.
0 commit comments