Skip to content
This repository
Browse code

Added support for repeated sections.

  • Loading branch information...
commit 512f434f56debd1de1f748455bc801b2231f2841 1 parent 4857edf
Felix H. Dahlke authored December 10, 2010
1  CHANGES.md
Source Rendered
... ...
@@ -1,5 +1,6 @@
1 1
 0.5.0
2 2
 ==================
  3
+* Added support for repeated sections.
3 4
 
4 5
 0.4.0 (2010-11-20)
5 6
 ==================
21  src/main/clojure/clostache/parser.clj
@@ -66,13 +66,14 @@
66 66
       (let [before (.substring template 0 (:start section))
67 67
             after (.substring template (:end section))
68 68
             section-data ((keyword (:name section)) data)]
69  
-        (recur (str before
70  
-             (if (:inverted section)
71  
-               (if (or (and (vector? section-data) (empty? section-data))
72  
-                       (not section-data))
73  
-                 (:body section))
74  
-               (if (vector? section-data)
75  
-                 (map-str (fn [m] (render (:body section) m)) section-data)
76  
-                 (if section-data
77  
-                   (replace-all (:body section) replacements))))
78  
-             after) data)))))
  69
+        (recur
  70
+         (str before
  71
+              (if (:inverted section)
  72
+                (if (or (and (vector? section-data) (empty? section-data))
  73
+                        (not section-data))
  74
+                  (:body section))
  75
+                (if (vector? section-data)
  76
+                  (map-str (fn [m] (render (:body section) m)) section-data)
  77
+                  (if section-data
  78
+                    (replace-all (:body section) replacements))))
  79
+              after) data)))))
7  src/test/clojure/clostache/test_parser.clj
@@ -26,9 +26,10 @@
26 26
                                                  {:name "Jenny"}]}))))
27 27
 
28 28
 (deftest test-render-list-twice
29  
-  (is (= "Hello, Felix, Jenny! Hello, Felix, Jenny!" (render "Hello{{#names}}, {{name}}{{/names}}! Hello{{#names}}, {{name}}{{/names}}!"
30  
-                                        {:names [{:name "Felix"}
31  
-                                                 {:name "Jenny"}]}))))
  29
+  (is (= "Hello, Felix, Jenny! Hello, Felix, Jenny!"
  30
+         (render (str "Hello{{#names}}, {{name}}{{/names}}! "
  31
+                      "Hello{{#names}}, {{name}}{{/names}}!")
  32
+                 {:names [{:name "Felix"} {:name "Jenny"}]}))))
32 33
 
33 34
 (deftest test-render-empty-list
34 35
   (is (= "" (render "{{#things}}Something{{/things}}" {:things []}))))

0 notes on commit 512f434

Please sign in to comment.
Something went wrong with that request. Please try again.