Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow nil #15

Closed
wants to merge 2 commits into from

5 participants

@aiba

This change will ignore nil elements in templates instead of throwing an error. This is useful if you want to put (when) clauses directly in a template, and matches the behavior of hiccup.core/html.

@mpenet

+1

I need this as well.

@dubiousdavid

Is this still an issue?

@mpenet

My guess is yes, since it hasn't been merged. I don't think the previous PR fixes that but I didn't test it.

@dubiousdavid
@aria42

Sorry we're really slammed right now, we do have this fixed internally and will release a fix along with some other new features soon.

@dubiousdavid

Cool. I'm just starting my first ClojureScript project, and currently figuring out all the libraries I'll need :)

@mpenet

I put a patched version on clojars in case you need it now (I do). https://clojars.org/cc.qbits/dommy (matches this branch https://github.com/mpenet/dommy/tree/patched )

@mpenet

By the way that made me notice: the versioning # are a bit odd, I don't know if you follow semver, but 0.0.3 should be 0.3.0 instead probably.

@simon-nicholls

Thanks, Max.

@dubiousdavid

I know you guys are busy, but this was opened a month ago. Seems like this should have been merged by now.

@aria42
@dubiousdavid
@aria42

I believe this has now been fixed and your test case merged in with our changes. We had a concurrent set of changes to the actual templating stuff but your test case was still useful. Thanks and sorry that took so long.

@aria42 aria42 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 2, 2013
  1. @aiba
  2. @aiba

    allow nil data in templates

    aiba authored
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +3 −0  src/dommy/template.cljs
  2. +9 −0 test/dommy/template_test.cljs
View
3  src/dommy/template.cljs
@@ -71,6 +71,9 @@
(do (doseq [child data] (->document-fragment result-frag child))
result-frag)
+ (nil? data)
+ result-frag
+
:else
(throw-unable-to-make-node data))))
View
9 test/dommy/template_test.cljs
@@ -120,3 +120,12 @@
(deftest nested-deftemplate
(is= "<ul class=\"class1\"><li>0</li><li>1</li><li>2</li><li>3</li><li>4</li></ul>"
(.-outerHTML (nested-template 5))))
+
+(deftest nil-in-template
+ (is= "<span></span>"
+ (.-outerHTML (template/node [:span nil])))
+ (is= "<ul><li>0</li><li>2</li></ul>"
+ (.-outerHTML (template/node [:ul (for [i (range 3)]
+ (when (even? i)
+ [:li i]))]))))
+
Something went wrong with that request. Please try again.