From f83a3caa1db60b2f687db211ba1cedccde4095d7 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Thu, 13 Jun 2013 16:53:07 -0400 Subject: [PATCH] DUEL bug fixed, code style. --- .../duel/src/main/resources/views/Task.duel | 2 +- .../src/main/webapp/js/todos/controller.js | 138 ++++++++++-------- .../duel/src/main/webapp/js/todos/model.js | 133 ++++++++--------- ...40176df828f72a94b201a48c223860b95908dc.js} | 24 +-- .../architecture-examples/duel/www/index.html | 2 +- 5 files changed, 151 insertions(+), 148 deletions(-) rename labs/architecture-examples/duel/www/cdn/{cb86ce6c04dc2c3e1a7111b0000b1252c883d20c.js => 4340176df828f72a94b201a48c223860b95908dc.js} (60%) diff --git a/labs/architecture-examples/duel/src/main/resources/views/Task.duel b/labs/architecture-examples/duel/src/main/resources/views/Task.duel index aaec338076..570fe97743 100644 --- a/labs/architecture-examples/duel/src/main/resources/views/Task.duel +++ b/labs/architecture-examples/duel/src/main/resources/views/Task.duel @@ -2,7 +2,7 @@ <%-- could have embedded in 'tasks' for-loop, but this allows us to add single tasks --%> -
  • +
  • "+a.name+'

    Source

    '}).join(""),b.querySelector(".source-links").innerHTML=f;a.link_groups&&(f=a.link_groups.map(function(a){return"

    "+a.heading+"

      "+a.links.map(function(a){return"
    • "+d.replace(e,function(b,c){return a[c]})+"
    • "}).join("")+"
    "}).join(""),b.innerHTML+=f,b.innerHTML+=c.footer.outerHTML);return b}};e.prototype.append=function(){var a=this._parseTemplate();a.className="learn";document.body.className=(document.body.className+" learn-bar").trim(); -document.body.insertAdjacentElement("afterBegin",a)};(function(){var a=document.createElement("a"),c=document.createElement("p"),b=document.getElementById("info");if(b)a.href="/tastejs/todomvc/tree/gh-pages"+(0/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var b=/(.)^/,c={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},e=/\\|'|\r|\n|\t|\u2028|\u2029/g;a.template=function(i,g,f){var k,f=a.defaults({}, +f,a.templateSettings),h=RegExp([(f.escape||b).source,(f.interpolate||b).source,(f.evaluate||b).source].join("|")+"|$","g"),j=0,d="__p+='";i.replace(h,function(a,b,f,g,h){d+=i.slice(j,h).replace(e,function(a){return"\\"+c[a]});b&&(d+="'+\n((__t=("+b+"))==null?'':_.escape(__t))+\n'");f&&(d+="'+\n((__t=("+f+"))==null?'':__t)+\n'");g&&(d+="';\n"+g+"\n__p+='");j=h+a.length;return a});d+="';\n";f.variable||(d="with(obj||{}){\n"+d+"}\n");d="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+ +d+"return __p;\n";try{k=new Function(f.variable||"obj","_",d)}catch(l){throw l.source=d,l;}if(g)return k(g,a);g=function(b){return k.call(this,b,a)};g.source="function("+(f.variable||"obj")+"){\n"+d+"}";return g};return a}({});if("todomvc.com"===location.hostname)window._gaq=[["_setAccount","UA-31081062-1"],["_trackPageview"]],function(a,b){var c=a.createElement(b),e=a.getElementsByTagName(b)[0];c.src="//www.google-analytics.com/ga.js";e.parentNode.insertBefore(c,e)}(document,"script");i.prototype.append= +function(){var a=document.createElement("aside");a.innerHTML=m.template(this.template,this.frameworkJSON);a.className="learn";var b=a.querySelectorAll(".demo-link");Array.prototype.forEach.call(b,function(a){a.setAttribute("href",j()+a.getAttribute("href"))});document.body.className=(document.body.className+" learn-bar").trim();document.body.insertAdjacentHTML("afterBegin",a.outerHTML)};if("tastejs.github.io"===location.hostname)location.href=location.href.replace("tastejs.github.io/todomvc","todomvc.com"); +(function(a,b){if(!location.host)return console.info("Miss the info bar? Run TodoMVC from a server to avoid a cross-origin error.");var c=new XMLHttpRequest;c.open("GET",j()+a,!0);c.send();c.onload=function(){200===c.status&&b&&b(c.responseText)}})("learn.json",i)})();/* DUEL v0.8.2 http://duelengine.org Copyright (c)2006-2012 Stephen M. McKamey. Licensed under The MIT License. @@ -24,10 +24,10 @@ k(e.index,b,c,f,d):c;i=e.hasOwnProperty("count")?k(e.count,b,c,f,d):f;b=e.hasOwn u=function(a){return n(a)&&n(a.getView)?a:J(a)};u.raw=function(a){return new x(a)};var M={area:!0,base:!0,basefont:!0,br:!0,col:!0,frame:!0,hr:!0,img:!0,input:!0,isindex:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,wbr:!0},C={async:1,checked:1,defer:1,disabled:1,hidden:1,novalidate:1,formnovalidate:1};q.prototype.toString=function(){var a;var b=this.value;try{var c=new o;B(c,b);a=c.toString()}catch(f){a="["+f+"]"}return a};q.prototype.write=function(a){(a||m).write(""+this)};var P={rowspan:"rowSpan", colspan:"colSpan",cellpadding:"cellPadding",cellspacing:"cellSpacing",tabindex:"tabIndex",accesskey:"accessKey",hidefocus:"hideFocus",usemap:"useMap",maxlength:"maxLength",readonly:"readOnly",contenteditable:"contentEditable"},p={enctype:"encoding",onscroll:"DOMMouseScroll",checked:"defaultChecked"},N=/^[\r\n]+/,O=/[\r\n]+$/;q.prototype.toDOM=function(a,b){4===l(a)&&(a=m.getElementById(a));var c;try{b&&(c=a,a=null),c=I(c||t(this.value[0]),this.value)}catch(f){c=m.createTextNode("["+f+"]")}a&&a.parentNode&& a.parentNode.replaceChild(c,a);return c};q.prototype.reload=function(){var a=m;try{var b=this.toDOM();a.replaceChild(b,a.documentElement);if(a.createStyleSheet){for(var c=b.firstChild;c&&"HEAD"!==(c.tagName||"");)c=c.nextSibling;for(var f=c&&c.firstChild;f;){if("LINK"===(f.tagName||""))f.href=f.href;f=f.nextSibling}}}catch(d){a=a.open("text/html"),a.write(this.toString()),a.close()}};return u}(document,window.ScriptEngineMajorVersion);var todos=todos||{}; -(function(i,f,h){function e(){var b="undefined"!==typeof JSON?JSON.stringify(a):a;f.setItem(h,b)}var a,f=f||function(){var b={};return{getItem:function(a){return b[a]},setItem:function(a,d){b[a]=d}}}(),g=f.getItem(h);a=g?"undefined"!==typeof JSON?JSON.parse(g):g:[];i.model={tasks:function(){return a},stats:function(){for(var b={total:a.length,active:a.length,completed:0},c=a.length;c--;)a[c].completed&&b.completed++;b.active-=b.completed;return b},add:function(b){b={id:((new Date).getTime()+Math.random()).toString(36), -title:b,completed:!1};a.push(b);e();return b},edit:function(b,c){for(var d=a.length;d--;)if(a[d].id===b){a[d].title=c;e();break}},toggle:function(b,c){for(var d=a.length;d--;)if(a[d].id===b){a[d].completed=c;e();break}},toggleAll:function(b){for(var c=a.length;c--;)a[c].completed=b;e()},remove:function(b){for(var c=a.length;c--;)if(a[c].id===b){a.splice(c,1);e();break}},expunge:function(){for(var b=a.length;b--;)a[b].completed&&a.splice(b,1);e()}}})(todos,window.localStorage,"todos-duel");var todos=todos||{};todos.views=todos.views||{};todos.views.Stats=duel([""," ",["$if",{test:function(a){return a.total}},["footer",{id:"footer"}," ",["span",{id:"todo-count"},["strong",function(a){return a.active}]," ",function(a){return 1===a.active?"item":"items"}," left"]," "," ",["$if",{test:function(a){return a.completed}},["button",{id:"clear-completed",onclick:function(){return todos.actions.clear_click}},"Clear completed (",function(a){return a.completed},")"]]]]]);var todos=todos||{};todos.views=todos.views||{}; -todos.views.Task=duel([""," ",["li",{"class":function(a){return a.completed?"complete":""}}," ",["div",{"class":"view"}," ",["input",{"class":"toggle",type:"checkbox",checked:function(a){return a.completed},onchange:function(a){return todos.actions.completed_change(a.id)}}]," ",["label",{ondblclick:function(a){return todos.actions.content_dblclick(a.id)}},function(a){return a.title}]," ",["button",{"class":"destroy",onclick:function(a){return todos.actions.remove_click(a.id)}}]," "]," ",["input", +(function(h,e,g){function d(){var a="undefined"!==typeof JSON?JSON.stringify(b):b;e.setItem(g,a)}var b,e=e||function(){var a={};return{getItem:function(c){return a[c]},setItem:function(c,b){a[c]=b}}}(),f=e.getItem(g);b=f?"undefined"!==typeof JSON?JSON.parse(f):f:[];h.model={tasks:function(){return b},stats:function(){var a={};a.total=b.length;a.completed=b.filter(function(a){return a.completed}).length;a.active=a.total-a.completed;return a},add:function(a){a={id:((new Date).getTime()+Math.random()).toString(36), +title:a,completed:!1};b.push(a);d();return a},edit:function(a,c){b.filter(function(b){return b.id===a})[0].title=c;d()},toggle:function(a,c){b.filter(function(b){return b.id===a})[0].completed=c;d()},toggleAll:function(a){b.forEach(function(b){b.completed=a});d()},remove:function(a){b.forEach(function(c,d){c.id===a&&b.splice(d,1)});d()},expunge:function(){b.forEach(function(a,c){a.completed&&b.splice(c,1)});d()}}})(todos,window.localStorage,"todos-duel");var todos=todos||{};todos.views=todos.views||{};todos.views.Stats=duel([""," ",["$if",{test:function(a){return a.total}},["footer",{id:"footer"}," ",["span",{id:"todo-count"},["strong",function(a){return a.active}]," ",function(a){return 1===a.active?"item":"items"}," left"]," "," ",["$if",{test:function(a){return a.completed}},["button",{id:"clear-completed",onclick:function(){return todos.actions.clear_click}},"Clear completed (",function(a){return a.completed},")"]]]]]);var todos=todos||{};todos.views=todos.views||{}; +todos.views.Task=duel([""," ",["li",{"class":function(a){return a.completed?"completed":""}}," ",["div",{"class":"view"}," ",["input",{"class":"toggle",type:"checkbox",checked:function(a){return a.completed},onchange:function(a){return todos.actions.completed_change(a.id)}}]," ",["label",{ondblclick:function(a){return todos.actions.content_dblclick(a.id)}},function(a){return a.title}]," ",["button",{"class":"destroy",onclick:function(a){return todos.actions.remove_click(a.id)}}]," "]," ",["input", {"class":"edit",type:"text",value:function(a){return a.title},onblur:function(a){return todos.actions.edit_blur(a.id)},onkeypress:function(a){return todos.actions.edit_keypress(a.id)}}]]]);var todos=todos||{};todos.views=todos.views||{};todos.views.Tasks=duel([""," ",["$if",{test:function(a){return a.tasks.length}},["section",{id:"main"}," ",["input",{id:"toggle-all",type:"checkbox",checked:function(a){return!a.stats.active},onchange:function(){return todos.actions.toggle_change}}]," ",["label",{"for":"toggle-all"},"Mark all as complete"]," ",["ul",{id:"todo-list"}," ",["$for",{each:function(a){return a.tasks}}," ",["$call",{view:function(){return todos.views.Task}}]]," "]]]]);var todos=todos||{};todos.views=todos.views||{};todos.views.TodoApp=duel(["section",{id:"todoapp"}," ",["header",{id:"header"}," ",["h1","todos"]," ",["input",{id:"new-todo",placeholder:"What needs to be done?",autofocus:null,onblur:function(){return todos.actions.add_blur},onkeypress:function(){return todos.actions.add_keypress}}]," "]," ",["$call",{view:function(){return todos.views.Tasks},data:function(a){return a}}]," ",["$call",{view:function(){return todos.views.Stats},data:function(a){return a.stats}}]]);var todos=todos||{}; -(function(b,e){function f(a){var a=a||b.model.stats(),a=b.views.Stats(a).toDOM(),c=e.getElementById(i);c?c.parentNode.replaceChild(a,c):e.getElementById(g).appendChild(a)}function d(){var a={tasks:b.model.tasks(),stats:b.model.stats()},c=b.views.Tasks(a).toDOM(),d=e.getElementById(j);d?d.parentNode.replaceChild(c,d):e.getElementById(g).appendChild(c);f(a.stats)}function h(a){var c=(a.value||"").trim();a.value="";c&&(a=b.model.add(c),(c=e.getElementById(k))?(c.appendChild(b.views.Task(a).toDOM()),f()): -d())}var i="footer",g="todoapp",j="main",k="todo-list";b.actions={add_blur:function(){h(this)},add_keypress:function(a){13===a.keyCode&&h(this)},edit_blur:function(a){return function(){var c=(this.value||"").trim();(this.value=c)?b.model.edit(a,c):b.model.remove(a);d()}},edit_keypress:function(){return function(a){13===a.keyCode&&this.blur()}},remove_click:function(a){return function(){b.model.remove(a);d()}},clear_click:function(){b.model.expunge();d()},content_dblclick:function(){return function(){this.className= -"editing";this.getElementsByTagName("input")[1].focus()}},completed_change:function(a){return function(){b.model.toggle(a,this.checked);d()}},toggle_change:function(){b.model.toggleAll(this.checked);d()}};(function(a){var c=b.views.TodoApp({tasks:b.model.tasks(),stats:b.model.stats()}).toDOM();a.insertBefore(c,a.firstChild)})(e.body)})(todos,document); \ No newline at end of file +(function(c,e){function f(a){var a=a||c.model.stats(),a=c.views.Stats(a).toDOM(),b=e.getElementById(i);b?b.parentNode.replaceChild(a,b):e.getElementById(g).appendChild(a)}function d(){var a={tasks:c.model.tasks(),stats:c.model.stats()},b=c.views.Tasks(a).toDOM(),d=e.getElementById(j);d?d.parentNode.replaceChild(b,d):e.getElementById(g).appendChild(b);f(a.stats)}function h(a){var b=(a.value||"").trim();a.value="";b&&(a=c.model.add(b),(b=e.getElementById(k))?(b.appendChild(c.views.Task(a).toDOM()),f()): +d())}var i="footer",g="todoapp",j="main",k="todo-list";c.actions={addBlur:function(){h(this)},add_keypress:function(a){13===a.keyCode&&h(this)},edit_blur:function(a){return function(){var b=(this.value||"").trim();(this.value=b)?c.model.edit(a,b):c.model.remove(a);d()}},edit_keypress:function(){return function(a){13===a.keyCode&&this.blur()}},remove_click:function(a){return function(){c.model.remove(a);d()}},clear_click:function(){c.model.expunge();d()},content_dblclick:function(){var a=function(b){if("LI"!== +b.tagName)return a(b.parentNode);b.className="editing";b=b.getElementsByTagName("input")[1];b.focus();b.value=b.value};return function(){a(this)}},completed_change:function(a){return function(){c.model.toggle(a,this.checked);d()}},toggle_change:function(){c.model.toggleAll(this.checked);d()}};(function(a){var b=c.views.TodoApp({tasks:c.model.tasks(),stats:c.model.stats()}).toDOM();a.insertBefore(b,a.firstChild)})(e.body)})(todos,window.document); \ No newline at end of file diff --git a/labs/architecture-examples/duel/www/index.html b/labs/architecture-examples/duel/www/index.html index bde58801bb..38f10317f7 100644 --- a/labs/architecture-examples/duel/www/index.html +++ b/labs/architecture-examples/duel/www/index.html @@ -12,7 +12,7 @@

    Ported to DUEL by Stephen McKamey

    Part of TodoMVC

    - + \ No newline at end of file