Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 2 files changed
  • 0 comments
  • 1 contributor
40  src/scribe/template.clj
@@ -34,14 +34,14 @@
34 34
 (defn- map-to-attributes
35 35
   "Converts a map to a string of key='value' statements"
36 36
   [attrs]
37  
-  (cs/join \space (map (fn [[k v]]
  37
+  (s/join \space (map (fn [[k v]]
38 38
                          (str k "=" "\"" v "\""))
39 39
                        (walk/stringify-keys attrs))))
40 40
 
41 41
 (defn- escape-string
42 42
   "Escapes a string so it will always be literal in output. It shouldn't be possible for users to manually or accidentally write raw soy"
43 43
   [s]
44  
-  (str/escape (str s) {\space "{sp}"
  44
+  (s/escape (str s) {\space "{sp}"
45 45
                        \newline "{\n}"
46 46
                        \return "{\r}"
47 47
                        \tab "{\t}"
@@ -163,4 +163,38 @@
163 163
   (reify SoyCommand
164 164
          (render [this] "{default}")
165 165
          (params [this] [])
166  
-         (children [this] [])))
  166
+         (children [this] [])))
  167
+
  168
+(defn foreach-cmd
  169
+  "Creates a foreach SoyCommand"
  170
+  [local-var data-ref children]
  171
+  (reify SoyCommand
  172
+         (render [this] (str "{foreach "
  173
+                             local-var
  174
+                             " in "
  175
+                             data-ref "}"
  176
+                             (reduce str (render-child children))
  177
+                             "{/foreach}"
  178
+                             ))
  179
+         (params [this] (clojure.set/union (extract-params data-ref) (get-child-params children)))
  180
+         (children [this] children)))
  181
+
  182
+(defn ifempty-cmd
  183
+  "Creates an ifempty SoyCommand"
  184
+  []
  185
+  (reify SoyCommand
  186
+         (render [this] "{ifempty}")
  187
+         (params [this] [])
  188
+         (children [this] [])))
  189
+
  190
+(defn for-cmd
  191
+  "Creates a for SoyCommand. expressions is a seq of 1-3 expressions that is used as the argument to the GT range function."
  192
+  [local-var expressions children]
  193
+  (reify SoyCommand
  194
+         (render [this] (str "{for "
  195
+                             local-var
  196
+                             " in range("
  197
+                             (s/join ", " expressions)
  198
+                             ")}"))
  199
+         (params [this] (clojure.set/union (map clojure.set/union expressions) (get-child-params children)))
  200
+         (children [this] children)))
6  test/scribe/test/template.clj
@@ -60,4 +60,8 @@
60 60
     (is (= "{switch $foo}{case 1, 2, 3}few{case 4, 5, 6}some{case $bar}other{default}default{/switch}"
61 61
            (render cmd)))
62 62
     (is (= #{"foo" "bar"}
63  
-           (params cmd)))))
  63
+           (params cmd)))))
  64
+
  65
+(deftest t-foreach-cmd)
  66
+
  67
+(deftest t-for-cmd)

No commit comments for this range

Something went wrong with that request. Please try again.