Created
October 27, 2012 22:24
-
-
Save patrick-steele-idem/3966647 to your computer and use it in GitHub Desktop.
Raptor Templates (Looping over properties)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"settings" : { | |
"foo" : "low", | |
"bar" : "high", | |
"baz" : "low" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Settings</h1><h2>foo</h2><input type="radio" name="foo" value="low" checked="checked"> low<input type="radio" name="foo" value="high"> high<h2>bar</h2><input type="radio" name="bar" value="low"> low<input type="radio" name="bar" value="high" checked="checked"> high<h2>baz</h2><input type="radio" name="baz" value="low" checked="checked"> low<input type="radio" name="baz" value="high"> high |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rset("rhtml", "test", function(helpers) { | |
var empty=helpers.e, | |
notEmpty=helpers.ne, | |
forEachProp=helpers.fp, | |
escapeXml=helpers.x, | |
forEach=helpers.f; | |
return function(data, context) { | |
var settings=data.settings; | |
context.w('<h1>Settings</h1>'); | |
forEachProp(settings, function(name,value) { | |
context.w('<h2>') | |
.w(escapeXml(name)) | |
.w('</h2>'); | |
forEach(['low', 'high'], function(option) { | |
context.w('<input type="radio"') | |
.a("name", name) | |
.a("value", option) | |
.a("checked", (value === option ? "checked" : '')) | |
.w('> ') | |
.w(escapeXml(option)); | |
}); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<c:template xmlns:c="core" params="settings"> | |
<h1>Settings</h1> | |
<c:for each="(name,value) in settings"> | |
<h2>$name</h2> | |
<c:for each="option in ['low', 'high']"> | |
<input type="radio" name="$name" value="$option" checked="{?value === option;checked}" /> | |
$option | |
</c:for> | |
</c:for> | |
</c:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment