can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
73 lines (49 loc) • 2.11 kB
HTML
<script>
window.hasError = window.parent.hasError || function(error) {
console.log("error in autoload", error)
};
window.removeMyself = window.parent.removeMyself || function(){};
window.QU = window.parent.QUnit || {equal: console.log.bind(console), ok: console.log.bind(console)};
</script>
<script type="text/stache" id="basics">
<a can-href="{page='recipe' id=recipe.id}">{{recipe.name}}</a>
</script>
<script src='../../../node_modules/steal/steal.js' main='@empty'></script>
<script>
steal('can', 'can/view/stache','can/route',function(can){
can.route.ready();
// TEST THINGS WITH AN EMPTY ROUTE
// HELPER EXPRESSION
var template = can.stache("<a href=\"{{routeUrl page='recipe' id=recipe.id}}\">{{recipe.name}}</a>");
var frag = template({
recipe: new can.Map({id: 5, name: 'Cool recipe'})
});
QU.equal( frag.firstChild.getAttribute("href"), "#!&page=recipe&id=5", "href set");
// CALL EXPRESSION
template = can.stache("<a href=\"{{routeUrl(page='recipe' id=recipe.id)}}\">{{recipe.name}}</a>");
frag = template({
recipe: new can.Map({id: 5, name: 'Cool recipe'})
});
QU.equal( frag.firstChild.getAttribute("href"), "#!&page=recipe&id=5", "href set");
// routeCurrent
template = can.stache("{{#routeCurrent(undefined)}}yes{{else}}no{{/routeCurrent}}");
frag = template({});
QU.equal(frag.firstChild.nodeValue, "yes", "route is current");
template = can.stache("{{#routeCurrent()}}yes{{else}}no{{/routeCurrent}}");
frag = template({});
QU.equal(frag.firstChild.nodeValue, "yes", "route is current");
can.route.attr({"page":"recipe"});
setTimeout(function(){
//route current
template = can.stache("{{#routeCurrent()}}yes{{else}}no{{/routeCurrent}}");
frag = template({});
QU.equal(frag.firstChild.nodeValue, "no", "route is not current");
template = can.stache("<a href=\"{{routeUrl(id=recipe.id, true)}}\"></a>");
frag = template({
recipe: new can.Map({id: 5, name: 'Cool recipe'})
});
QU.equal( frag.firstChild.getAttribute("href"), "#!&page=recipe&id=5", "call expression merge");
removeMyself();
},50);
});
</script>