Permalink
Browse files

Added support for repeated sections.

  • Loading branch information...
1 parent 4857edf commit 512f434f56debd1de1f748455bc801b2231f2841 @fhd committed Dec 10, 2010
Showing with 16 additions and 13 deletions.
  1. +1 −0 CHANGES.md
  2. +11 −10 src/main/clojure/clostache/parser.clj
  3. +4 −3 src/test/clojure/clostache/test_parser.clj
View
1 CHANGES.md
@@ -1,5 +1,6 @@
0.5.0
==================
+* Added support for repeated sections.
0.4.0 (2010-11-20)
==================
View
21 src/main/clojure/clostache/parser.clj
@@ -66,13 +66,14 @@
(let [before (.substring template 0 (:start section))
after (.substring template (:end section))
section-data ((keyword (:name section)) data)]
- (recur (str before
- (if (:inverted section)
- (if (or (and (vector? section-data) (empty? section-data))
- (not section-data))
- (:body section))
- (if (vector? section-data)
- (map-str (fn [m] (render (:body section) m)) section-data)
- (if section-data
- (replace-all (:body section) replacements))))
- after) data)))))
+ (recur
+ (str before
+ (if (:inverted section)
+ (if (or (and (vector? section-data) (empty? section-data))
+ (not section-data))
+ (:body section))
+ (if (vector? section-data)
+ (map-str (fn [m] (render (:body section) m)) section-data)
+ (if section-data
+ (replace-all (:body section) replacements))))
+ after) data)))))
View
7 src/test/clojure/clostache/test_parser.clj
@@ -26,9 +26,10 @@
{:name "Jenny"}]}))))
(deftest test-render-list-twice
- (is (= "Hello, Felix, Jenny! Hello, Felix, Jenny!" (render "Hello{{#names}}, {{name}}{{/names}}! Hello{{#names}}, {{name}}{{/names}}!"
- {:names [{:name "Felix"}
- {:name "Jenny"}]}))))
+ (is (= "Hello, Felix, Jenny! Hello, Felix, Jenny!"
+ (render (str "Hello{{#names}}, {{name}}{{/names}}! "
+ "Hello{{#names}}, {{name}}{{/names}}!")
+ {:names [{:name "Felix"} {:name "Jenny"}]}))))
(deftest test-render-empty-list
(is (= "" (render "{{#things}}Something{{/things}}" {:things []}))))

0 comments on commit 512f434

Please sign in to comment.