Skip to content

Commit 4199a47

Browse files
committed
Initial commit
0 parents  commit 4199a47

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pom.xml
2+
*jar
3+
lib
4+
classes

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.

project.clj

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(defproject comb "0.1.0"
2+
:description "Clojure templating library"
3+
:dependencies [[org.clojure/clojure "1.2.0"]])

src/comb/template.clj

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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)))))

0 commit comments

Comments
 (0)