pakyow 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE +1 -1
  4. data/README.md +4 -1
  5. data/bin/pakyow +2 -16
  6. data/lib/generators/pakyow/app/app_generator.rb +46 -13
  7. data/lib/generators/pakyow/app/templates/Gemfile +8 -7
  8. data/lib/generators/pakyow/app/templates/README.md +2 -2
  9. data/lib/generators/pakyow/app/templates/app/setup.rb +10 -19
  10. data/lib/generators/pakyow/app/templates/app/views/_templates/default.html +3 -1
  11. data/lib/generators/pakyow/app/templates/env +1 -0
  12. data/lib/generators/pakyow/app/templates/env.example +3 -0
  13. data/lib/generators/pakyow/app/templates/gitignore +8 -0
  14. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/fastlink.js +3 -2
  15. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/fastlink.min.js +1 -1
  16. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/ga.js +34 -0
  17. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/ga.min.js +1 -0
  18. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/modal.js +1 -1
  19. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/modal.min.js +1 -1
  20. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/mutable.js +5 -1
  21. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/mutable.min.js +1 -1
  22. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/navigator.js +10 -6
  23. data/lib/generators/pakyow/app/templates/public/scripts/ring/components/navigator.min.js +1 -1
  24. data/lib/generators/pakyow/app/templates/public/scripts/ring/pakyow.js +175 -45
  25. data/lib/generators/pakyow/app/templates/public/scripts/ring/pakyow.min.js +1 -1
  26. data/lib/generators/pakyow/app/templates/rspec +3 -0
  27. data/lib/pakyow.rb +1 -1
  28. data/lib/pakyow/command_line_interface.rb +79 -0
  29. data/lib/pakyow/commands/console.rb +27 -0
  30. data/lib/pakyow/commands/console_methods.rb +10 -0
  31. data/lib/pakyow/commands/server.rb +38 -0
  32. data/lib/pakyow/version.rb +3 -0
  33. metadata +58 -27
  34. data/lib/commands/USAGE +0 -9
  35. data/lib/commands/USAGE-CONSOLE +0 -12
  36. data/lib/commands/USAGE-NEW +0 -11
  37. data/lib/commands/USAGE-SERVER +0 -16
  38. data/lib/commands/console.rb +0 -17
  39. data/lib/commands/server.rb +0 -27
  40. data/lib/version.rb +0 -3
@@ -1 +1 @@
1
- var pw={version:"0.1.1"};!function(){pw.util={guid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=16*Math.random()|0,e="x"==t?n:3&n|8;return e.toString(16)})},dup:function(t){return JSON.parse(JSON.stringify(t))}};var t=[];pw.init={register:function(n){t.push(n)}},document.addEventListener("DOMContentLoaded",function(){t.forEach(function(t){t()})});var e=["data-scope","data-prop"],i=["SELECT"],o=["AREA","BASE","BASEFONT","BR","HR","INPUT","IMG","LINK","META"];pw.node={value:function(t){return"INPUT"===t.tagName?"checkbox"===t.type?t.checked?t.value?t.value:!0:!1:t.value:"TEXTAREA"===t.tagName?t.value:"SELECT"===t.tagName?t.value:t.textContent.trim()},significant:function(t,n){t===document&&(t=document.getElementsByTagName("body")[0]),void 0===n&&(n=[]);var e,i;return(e=pw.node.isSignificant(t))?(i=[],n.push([{node:e[0],type:e[1]},i])):i=n,pw.node.toA(t.children).forEach(function(t){pw.node.significant(t,i)}),n},isSignificant:function(t){var n=e.find(function(n){return t.hasAttribute(n)});return n?[t,n.split("-")[1]]:!1},mutable:function(t){pw.node.significant(t).flatten().filter(function(t){return pw.node.isMutable(t.node)}).map(function(t){return t.node})},isMutable:function(t){var n=t.tagName;return"FORM"===n||"INPUT"===n&&!t.disabled},trigger:function(t,n,e){var i=document.createEvent("Event");i.initEvent(t,!0,!0),n._evtData=e,n.dispatchEvent(i)},replaceEventListener:function(t,n,e){n.removeEventListener(t),n.addEventListener(t,e)},inForm:function(t){if("FORM"===t.tagName)return!0;var n=t.parentNode;return n!==document?pw.node.inForm(n):void 0},component:function(t){if(t.getAttribute("data-ui"))return t;var n=t.parentNode;return n!==document?pw.node.component(n):void 0},scope:function(t){if(t.getAttribute("data-scope"))return t;var n=t.parentNode;return n!==document?pw.node.scope(n):void 0},scopeName:function(t){if(t.getAttribute("data-scope"))return t.getAttribute("data-scope");var n=t.parentNode;return n!==document?pw.node.scopeName(n):void 0},prop:function(t){if(t.getAttribute("data-prop"))return t;var n=t.parentNode;return n!==document?pw.node.prop(n):void 0},propName:function(t){if(t.getAttribute("data-prop"))return t.getAttribute("data-prop");var n=t.parentNode;return n!==document?pw.node.propName(n):void 0},versionName:function(t){return t.hasAttribute("data-version")?t.getAttribute("data-version"):void 0},"with":function(t,n){n.call(t)},"for":function(t,n,e){pw.node.isNodeList(t)&&(t=pw.node.toA(t)),t=Array.ensure(t),n=Array.ensure(n),t.forEach(function(t,i){e.call(t,n[i])})},match:function(t,e){pw.node.isNodeList(t)&&(t=pw.node.toA(t)),t=Array.ensure(t),e=Array.ensure(e);var i=e.reduce(function(t,e,i){var o=n[i]||n[n.length-1],r=o.cloneNode(!0);return o.parentNode.insertBefore(r),t.concat([r])},[]);return t.forEach(function(t){t.parentNode.removeChild(t)}),i},repeat:function(t,n,e){pw.node["for"](pw.node.match(t,n),n,e)},bind:function(t,n,e){var i=pw.node.findBindings(n)[0];pw.node["for"](n,t,function(t){t&&(t.id&&this.setAttribute("data-id",t.id),pw.node.bindDataToScope(t,i,n),"undefined"!=typeof e&&e.call(this,t))})},apply:function(t,n,e){var i=pw.node.match(n,t);return pw.node.bind(t,i,e),i},findBindings:function(t){var n=[];return pw.node.breadthFirst(t,function(){var t=this,e=t.getAttribute("data-scope");if(e){var i=[];pw.node.breadthFirst(t,function(){var n=this;if(t==n||!n.getAttribute("data-scope")){var e=n.getAttribute("data-prop");e&&i.push({prop:e,doc:n})}}),n.push({scope:e,props:i,doc:t})}}),n},bindDataToScope:function(t,n,e){t&&n&&n.props.forEach(function(n){k=n.prop,v=t[k],v||(v=""),"object"==typeof v?(pw.node.bindValueToNode(v.__content,n.doc),pw.node.bindAttributesToNode(v.__attrs,n.doc)):pw.node.bindValueToNode(v,n.doc)})},bindAttributesToNode:function(t,n){var e=pw.attrs.init(pw.view.init(n));for(var i in t){var o=t[i];"function"==typeof o&&(o=o.call(n.getAttribute(i))),o?o instanceof Array?o.forEach(function(t){e[t[0]](i,t[1])}):e.set(i,o):e.remove(i)}},bindValueToNode:function(t,n){pw.node.isTagWithoutValue(n)||("INPUT"===n.tagName&&"checkbox"===n.type?t===!0||n.value&&t===n.value?n.checked=!0:n.checked=!1:"TEXTAREA"===n.tagName||pw.node.isSelfClosingTag(n)?n.value=t:n.innerHTML=t)},isTagWithoutValue:function(t){return-1!=i.indexOf(t.tagName)?!0:!1},isSelfClosingTag:function(t){return-1!=o.indexOf(t.tagName)?!0:!1},breadthFirst:function(t,n){for(var e=[t];e.length>0;){var i=e.shift();if(i){"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&i.cloneNode&&n.call(i);var o=i.childNodes;if(o)for(var r=0;r<o.length;r++)e.push(o[r])}}},isNodeList:function(t){return"undefined"!=typeof t.length},byAttr:function(t,n,e){return pw.node.all(t).filter(function(t){var i=t.getAttribute(n);return null!==i&&("undefined"==typeof e||i==e)})},setAttr:function(t,n,e){"style"===n?e.pairs().forEach(function(n){t.style[n[0]]=n[1]}):("class"===n&&(e=e.join(" ")),"checked"===n&&(e=e?"checked":"",t.checked=e),t.setAttribute(n,e))},all:function(t){var n=[];return t?(document!==t&&n.push(t),n.concat(pw.node.toA(t.getElementsByTagName("*")))):n},before:function(t,n){t.parentNode.insertBefore(n,t)},after:function(t,n){t.parentNode.insertBefore(n,this.nextSibling)},replace:function(t,n){t.parentNode.replaceChild(n,t)},append:function(t,n){t.appendChild(n)},prepend:function(t,n){t.insertBefore(n,t.firstChild)},remove:function(t){t.parentNode.removeChild(t)},clear:function(t){for(;t.firstChild;)pw.node.remove(t.firstChild)},title:function(t,n){var e;(e=t.getElementsByTagName("title")[0])&&(e.innerText=n)},toA:function(t){return Array.prototype.slice.call(t)},serialize:function(t){var n,e,i,o,r,a,c={};return t.querySelectorAll("input, select, textarea").forEach(function(t){n=c,i=t.name.split("["),o=i[i.length-1],i.forEach(function(i){e=pw.node.value(t),"]"==i&&(r[a]instanceof Array||(r[a]=[]),e&&r[a].push(e)),i!=o&&(e={}),i=i.replace("]",""),""!=i&&"_method"!=i&&(n[i]||(n[i]=e),r=n,a=i,n=n[i])})}),c}},pw.attrs={init:function(t){return new a(pw.collection.init(t))}};var r={hash:["style"],bool:["selected","checked","disabled","readonly","multiple"],mult:["class"]},a=function(t){this.views=t.views};a.prototype={findType:function(t){return r.hash.indexOf(t)>-1?"hash":r.bool.indexOf(t)>-1?"bool":r.mult.indexOf(t)>-1?"mult":"text"},findValue:function(t,n){switch(n){case"class":return t.node.classList;case"style":return t.node.style}return"bool"===this.findType(n)?t.node.hasAttribute(n):t.node.getAttribute(n)},set:function(t,n){this.views.forEach(function(e){pw.node.setAttr(e.node,t,n)})},remove:function(t){this.views.forEach(function(n){n.node.removeAttribute(t)})},ensure:function(t,n){this.views.forEach(function(e){var i=this.findValue(e,t);if("class"===t)i.contains(n)||i.add(n);else if("style"===t)n.pairs().forEach(function(t){e.node.style[t[0]]=t[1]});else if("bool"===this.findType(t))e.node.hasAttribute(t)||pw.node.setAttr(e.node,t,t);else{var i=e.node.getAttribute(t)||"";i.match(n)||pw.node.setAttr(e.node,t,i+n)}},this)},deny:function(t,n){this.views.forEach(function(e){var i=this.findValue(e,t);"class"===t?i.contains(n)&&i.remove(n):"style"===t?n.pairs().forEach(function(t){e.node.style[t[0]]=e.node.style[t[0]].replace(t[1],"")}):"bool"===this.findType(t)?e.node.hasAttribute(t)&&e.node.removeAttribute(t):pw.node.setAttr(e.node,t,e.node.getAttribute(t).replace(n,""))},this)},insert:function(t,n){this.views.forEach(function(e){var i=this.findValue(e,t);switch(t){case"class":i.add(n);break;default:pw.node.setAttr(e.node,t,i+n)}},this)}},pw.state={build:function(t,n){var e;return t.reduce(function(t,i){return(e=pw.state.buildForNode(i,n))&&t.push(e),t},[])},buildForNode:function(t,n){var e=t[0],i={};if("scope"===e.type)i.id=e.node.getAttribute("data-id"),i.scope=e.node.getAttribute("data-scope");else if("prop"===e.type&&n)return void(n[e.node.getAttribute("data-prop")]=pw.node.value(e.node));return i.__nested=pw.state.build(t[1],i),i},init:function(t,n){return new c(t,n)}};var c=function(t){this.node=t,this.snapshots=[],this.update()};c.prototype={update:function(){this.snapshots.push(pw.state.build(pw.node.significant(this.node)))},diffNode:function(t){return pw.state.build(pw.node.significant(pw.node.scope(t)))[0]},revert:function(){var t=pw.util.dup(this.snapshots[0]);return this.snapshots=[t],t},rollback:function(){return this.snapshots.pop(),this.current()},node:function(t){return this.current.flatten().find(function(n){return n.scope===t.scope&&n.id===t.id})},append:function(t){var n=this.copy();n.push(t),this.snapshots.push(n)},prepend:function(t){var n=this.copy();n.unshift(t),this.snapshots.push(n)},"delete":function(t){var n=this.copy(),e=n.find(function(n){return n.id===t.id});e&&(n.splice(n.indexOf(e),1),this.snapshots.push(n))},copy:function(){return pw.util.dup(this.current())},current:function(){return this.snapshots[this.snapshots.length-1]},initial:function(){return this.snapshots[0]}},pw.view={init:function(t){return new s(t)},fromStr:function(t){var n=document.createElement("div");return n.innerHTML=t,pw.view.init(n.childNodes[0])}};var s=function(t){this.node=t};s.prototype={clone:function(){return pw.view.init(this.node.cloneNode(!0))},title:function(t){pw.node.title(this.node,t)},text:function(t){this.node.innerText=t},html:function(t){this.node.innerHTML=t},component:function(t){return pw.collection.init(pw.node.byAttr(this.node,"data-ui",t).reduce(function(t,n){return t.concat(pw.view.init(n))},[]),this)},attrs:function(){return pw.attrs.init(this)},"with":function(t){pw.node["with"](this.node,t)},match:function(t){pw.node.match(this.node,t)},"for":function(t,n){pw.node["for"](this.node,t,n)},repeat:function(t,n){pw.node.repeat(this.node,t,n)},bind:function(t,n){pw.node.bind(t,this.node,n)},apply:function(t,n){pw.node.apply(t,this.node,n)}},["scope","prop"].forEach(function(t){s.prototype[t]=function(n){return pw.collection.init(pw.node.byAttr(this.node,"data-"+t,n).reduce(function(t,n){return t.concat(pw.view.init(n))},[]),this,n)}}),["remove","clear","versionNode"].forEach(function(t){s.prototype[t]=function(){return pw.node[t](this.node)}}),["after","before","replace","append","prepend","insert"].forEach(function(t){s.prototype[t]=function(n){return pw.node[t](this.node,n.node)}}),pw.collection={init:function(t,n,e){return t instanceof u?t:(t.constructor!==Array&&(t=[t]),new u(t,n,e))},fromNodes:function(t,n,e){return pw.collection.init(t.map(function(t){return pw.view.init(t)}),n,e)}};var u=function(t,n,e){this.views=t,this.parent=n,this.scope=e};u.prototype={clone:function(){return pw.collection.init(this.views.map(function(t){return t.clone()}))},last:function(){return this.views[this.length()-1]},first:function(){return this.views[0]},removeView:function(t){var n=this.views.indexOf(t);n>-1&&this.views.splice(n,1)[0].remove()},addView:function(t){var n=[];t instanceof u?n=t.views:n.push(t),this.length()>0?n.forEach(function(t){pw.node.after(this.last().node,t.node)},this):this.parent&&n.forEach(function(t){this.parent.append(t)},this),this.views=this.views.concat(n)},order:function(t){t.forEach(function(t){if(t){var n=this.views.find(function(n){return n.node.getAttribute("data-id")==t.toString()});if(n){n.node.parentNode.appendChild(n.node);var e=this.views.indexOf(n);this.views.splice(e,1),this.views.push(n)}}},this)},length:function(){return this.views.length},attrs:function(){return pw.attrs.init(this.views)},append:function(t){t=Array.ensure(t);var n=this.last();return this.views.push(n.append(t)),n},prepend:function(t){t=Array.ensure(t);var n=t.map(function(t){var n=this.first().prepend(t);return this.views.push(n),n},this);return pw.collection.init(n)},"with":function(t){pw.node["with"](this.views,t)},"for":function(t,n){t=Array.ensure(t),this.views.forEach(function(e,i){n.call(e,t[i])})},match:function(t,n){if(t=Array.ensure(t),0===t.length)return this.remove(),n.call(this);var e,i;if(this.views[0]&&(e=this.views[0].clone(),i=this.views[0].node.parentNode),this.views.slice(0).forEach(function(n){var e=n.node.getAttribute("data-id");e&&(t.find(function(t){return t.id.toString()===e})||this.removeView(n))},this),!(t.length>this.length()))return n.call(this);var o=this;return this.endpoint.template(this,function(r){return r||(r=e.clone(),o.parent=pw.view.init(i)),t.forEach(function(t){if(!o.views.find(function(n){return n.node.getAttribute("data-id")===(t.id||"").toString()})){var n=r.clone();n instanceof u&&(n=n.views[0]),n.node.setAttribute("data-id",t.id),o.addView(n),pw.component.findAndInit(n.node)}},o),n.call(o)}),this},repeat:function(t,n){this.match(t,function(){this["for"](t,n)})},bind:function(t,n){return this["for"](t,function(t){this.bind(t),"undefined"!=typeof n&&n.call(this,t)}),this},apply:function(t,n){this.match(t,function(){var e;this.order(t.map(function(t){return(e=t.id)?e.toString():void 0})),this.bind(t,n)})},endpoint:function(t){return this.endpoint=t,this}},["scope","prop","component"].forEach(function(t){u.prototype[t]=function(n){return pw.collection.init(this.views.reduce(function(e,i){return e.concat(i[t](n).views)},[]))}}),["remove","clear","text","html"].forEach(function(t){u.prototype[t]=function(n){this.views.forEach(function(e){e[t](n)})}}),pw.init.register(function(){pw.component.findAndInit(document.querySelectorAll("body")[0])});var d={},p={},f={},h={};pw.component={init:function(t,n){return new l(t,n)},resetChannels:function(){p={}},findAndInit:function(t){pw.node.byAttr(t,"data-ui").forEach(function(t){if(!t._ui){var n=t.getAttribute("data-ui"),e=d[n]||pw.component.init;h[n]||(h[n]=[]);var i=t.getAttribute("data-channel"),o=t.getAttribute("data-config"),r=pw.view.init(t),a=h[n].length,c=new e(r,pw.component.buildConfigObject(o),n,a);c.init(r,o,n),pw.component.registerForChannel(c,i),h[n].push(c),t._ui=!0}})},push:function(t){var n=t.channel,e=t.payload,i=e.instruct;(p[n]||[]).forEach(function(t){i?t.instruct(n,i):t.message(n,e)})},register:function(t,n){var e=l.prototype;Object.getOwnPropertyNames(e).forEach(function(t){n.prototype[t]=e[t]}),d[t]=n},buildConfigObject:function(t){return t?t.split(";").reduce(function(t,n){var e=n.trim().split(":");return t[e[0].trim()]=e[1].trim(),t},{}):{}},registerForChannel:function(t,n){p[n]||(p[n]=[]),p[n].push(t)},registerForBroadcast:function(t,n,e){f[t]||(f[t]=[]),f[t].push([n,e])},deregisterForBroadcast:function(t,n){var e=f[t],i=e.find(function(t){return t[1]==n}),o=e.indexOf(i);e.splice(o,1)},broadcast:function(t,n){(f[t]||[]).forEach(function(t){t[0].call(t[1],n)})}};var l=function(t,n,e){};l.prototype={init:function(t,n,e){var i=t.node;this.view=t,this.node=i,this.config=n,this.name=e,this.templates={};var o=this;if(pw.node.toA(i.querySelectorAll(":scope > *[data-template]")).forEach(function(t){var n=t.cloneNode(!0);pw.node.remove(t);var e=n.getAttribute("data-scope");this.templates[e]?this.templates[e].views.push(pw.view.init(n)):this.templates[e]=pw.collection.init(pw.view.init(n)),n.removeAttribute("data-template")},this),this.state=pw.state.init(this.node),this.dCb){var r=pw.node.component(this.node.parentNode);r&&(r.addEventListener("mutated",function(t){o.transform(o.dCb(t.target._evtData))}),o.transform(o.dCb(pw.state.init(r).current())))}var a=function(t){t.preventDefault();var n=pw.node.scope(t.target);n&&o.mutated(n)};i.addEventListener("submit",a),i.addEventListener("change",function(t){pw.node.inForm(t.target)||a(t)}),this.inited&&this.inited()},listen:function(t,n){pw.component.registerForBroadcast(t,n,this)},ignore:function(t){pw.component.deregisterForBroadcast(t,this)},instruct:function(t,n){this.endpoint=pw.instruct;var e=this.state.current();if(1===e.length){var i=this.view.scope(e[0].scope),o=i.views[0].node;if("empty"===o.getAttribute("data-version")){var r=this;return void pw.instruct.template(i,function(t){var e=o.parentNode;e.replaceChild(t.node,o),n.forEach(function(t){r[t[0]](t[1])})})}}n.forEach(function(t){this[t[0]](t[1])},this)},message:function(t,n){},mutated:function(t){this.mutation(this.state.diffNode(t)),this.state.update(),pw.node.trigger("mutated",this.node,this.state.current())},mutation:function(t){},transform:function(t){this._transform(t)},_transform:function(t){t&&(t.length>0?this.view.scope(t[0].scope).endpoint(this.endpoint||this).apply(t):pw.node.breadthFirst(this.view.node,function(){this.hasAttribute("data-scope")&&pw.node.remove(this)}),pw.node.trigger("mutated",this.node,this.state.current()))},revert:function(){this.transform(this.state.revert())},rollback:function(){this.transform(this.state.rollback())},template:function(t,n){var e;(e=this.templates[t.scope])&&n(e)},"delete":function(t){this.state["delete"](t),this.transform(this.state.current())},append:function(t){this.state.append(t),this.transform(this.state.current())},prepend:function(t){this.state.prepend(t),this.transform(this.state.current())},parent:function(){var t=pw.node.scope(this.node);return t?pw.state.init(t).current()[0]:void 0},dependent:function(t){this.dCb=t}},pw.init.register(function(){pw.socket.init({cb:function(t){window.socket=t}})}),pw.socket={init:function(t){return pw.socket.connect(t.host,t.port,t.protocol,t.connId,t.cb)},connect:function(t,n,e,i,o){if("undefined"==typeof t&&(t=window.location.hostname),"undefined"==typeof n&&(n=window.location.port),"undefined"==typeof e&&(e=window.location.protocol),"undefined"==typeof i&&(i=document.getElementsByTagName("body")[0].getAttribute("data-socket-connection-id")),i){var r="";return"http:"===e?r+="ws://":"https:"===e&&(r+="wss://"),r+=t,n&&(r+=":"+n),r+="/?socket_connection_id="+i,new w(r,o)}}};var w=function(t,n){var e=this;this.callbacks={},this.url=t,this.initCb=n,this.ws=new WebSocket(t),this.id=t.split("socket_connection_id=")[1];var i;this.ws.onmessage=function(t){pw.component.broadcast("socket:loaded");var n=JSON.parse(t.data);if(n.id){var i=e.callbacks[n.id];if(i)return void i.call(this,n)}e.message(n)},this.ws.onclose=function(t){console.log("socket closed"),clearInterval(i),e.reconnect()},this.ws.onopen=function(t){console.log("socket open"),e.initCb&&e.initCb(e),i=setInterval(function(){e.send({action:"ping"})},3e4)}};w.prototype={send:function(t,n){pw.component.broadcast("socket:loading"),t.id=pw.util.guid(),t.input||(t.input={}),t.input.socket_connection_id=this.id,this.callbacks[t.id]=n,this.ws.send(JSON.stringify(t))},message:function(t){console.log("received message"),console.log(t);var n='*[data-channel="'+t.channel+'"]';if(t.channel&&"component"===t.channel.split(":")[0])return void pw.component.push(t);var e=pw.node.toA(document.querySelectorAll(n));0!==e.length&&pw.instruct.process(pw.collection.fromNodes(e,n),t,this)},reconnect:function(){var t=this;t.wait?t.wait*=1.25:t.wait=100,console.log("reconnecting socket in "+t.wait+"ms"),setTimeout(function(){pw.socket.init({cb:t.initCb})},t.wait)},fetchView:function(t,n){var e;if(window.location.hash){var i=window.location.hash.split("#:")[1].split("/");i.shift(),e=i.join("/")}else e=window.location.pathname+window.location.search;this.send({action:"fetch-view",lookup:t,uri:e},function(t){var e=pw.view.fromStr(t.body);e.node?(e.node.removeAttribute("data-id"),n(e)):n()})}},pw.instruct={process:function(t,n,e){1===t.length()&&"empty"===t.views[0].node.getAttribute("data-version")?pw.instruct.fetchView(n,e,t.views[0].node):pw.instruct.perform(t,n.payload)},fetchView:function(t,n,e){n.fetchView({channel:t.channel},function(n){if(n){var i=e.parentNode;i.replaceChild(n.node,e);var o='*[data-channel="'+t.channel+'"]',r=pw.node.toA(i.querySelectorAll(o));pw.instruct.perform(pw.collection.fromNodes(r,o),t.payload)}else console.log("trouble fetching view :(")})},template:function(t,n){var e={};if(!t||!t.first())return n();var i=t.first().node;if(i.hasAttribute("data-channel"))e.channel=t.first().node.getAttribute("data-channel");else{if(!i.hasAttribute("data-ui")||!i.hasAttribute("data-scope"))return void n();e.component=pw.node.component(i).getAttribute("data-ui"),e.scope=i.getAttribute("data-scope")}window.socket.fetchView(e,function(t){n(t)})},perform:function(t,n){var e=this;(n||[]).forEach(function(n,i){var o=n[0],r=n[1],a=n[2];if(!t[o])return void console.log("could not find method named: "+o);if("with"==o||"for"==o||"bind"==o||"repeat"==o||"apply"==o)return void t.endpoint(e)[o].call(t,r,function(t){pw.instruct.perform(this,a[r.indexOf(t)])});if("attrs"==o)return void e.performAttr(t.attrs(),a);var c=t[o].call(t,r);a instanceof Array?pw.instruct.perform(c,a):c&&(t=c)}),pw.component.findAndInit(t.node)},performAttr:function(t,n){n.forEach(function(n){var e=n[0],i=n[1],o=n[2];i?t.set(e,i):t[o[0][0]](e,o[0][1])})}},Array.prototype.flatten||(Array.prototype.flatten=function(){return this.reduce(function(t,n){return t.concat(Array.isArray(n)?n.flatten():n)},[])}),Array.prototype.find||(Array.prototype.find=function(t){if(null==this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n,e=Object(this),i=e.length>>>0,o=arguments[1],r=0;i>r;r++)if(n=e[r],t.call(o,n,r,e))return n;return void 0}),Array.ensure=function(t){return t instanceof Array?t:[t]},NodeList.prototype.forEach=Array.prototype.forEach,Object.prototype.pairs||Object.defineProperty(Object.prototype,"pairs",{value:function(){return Object.keys(this).map(function(t){return[t,this[t]]},this)},enumerable:!1}),"function"==typeof define&&define.amd?define(pw):"object"==typeof module&&module.exports?module.exports=pw:this.pw=pw}();
1
+ var pw={version:"0.2.4"};!function(){pw.util={guid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=16*Math.random()|0,e="x"==t?n:3&n|8;return e.toString(16)})},dup:function(t){return JSON.parse(JSON.stringify(t))}};var t=[];pw.init={register:function(n){t.push(n)}},document.addEventListener("DOMContentLoaded",function(){t.forEach(function(t){t()})});var e=["data-scope","data-prop"],i=["SELECT"],o=["AREA","BASE","BASEFONT","BR","HR","INPUT","IMG","LINK","META"];pw.node={value:function(t){return"INPUT"===t.tagName?"checkbox"===t.type?t.checked?t.value?t.value:!0:!1:t.value:"TEXTAREA"===t.tagName?t.value:"SELECT"===t.tagName?t.value:t.textContent.trim()},significant:function(t,n){t===document&&(t=document.getElementsByTagName("body")[0]),void 0===n&&(n=[]);var e,i;return(e=pw.node.isSignificant(t))?(i=[],n.push([{node:e[0],type:e[1]},i])):i=n,pw.node.toA(t.children).forEach(function(t){pw.node.significant(t,i)}),n},isSignificant:function(t){var n=e.find(function(n){return t.hasAttribute(n)});return n?[t,n.split("-")[1]]:!1},mutable:function(t){pw.node.significant(t).flatten().filter(function(t){return pw.node.isMutable(t.node)}).map(function(t){return t.node})},isMutable:function(t){var n=t.tagName;return"FORM"===n||"INPUT"===n&&!t.disabled},trigger:function(t,n,e){var i=document.createEvent("Event");i.initEvent(t,!0,!0),n._evtData=e,n.dispatchEvent(i)},replaceEventListener:function(t,n,e){n.removeEventListener(t),n.addEventListener(t,e)},inForm:function(t){if("FORM"===t.tagName)return!0;var n=t.parentNode;return n&&n!==document?pw.node.inForm(n):void 0},component:function(t){if(t.getAttribute("data-ui"))return t;var n=t.parentNode;return n&&n!==document?pw.node.component(n):void 0},scope:function(t){if(t.getAttribute("data-scope"))return t;var n=t.parentNode;return n&&n!==document?pw.node.scope(n):void 0},scopeName:function(t){if(t.getAttribute("data-scope"))return t.getAttribute("data-scope");var n=t.parentNode;return n&&n!==document?pw.node.scopeName(n):void 0},prop:function(t){if(t.getAttribute("data-prop"))return t;var n=t.parentNode;return n&&n!==document?pw.node.prop(n):void 0},propName:function(t){if(t.getAttribute("data-prop"))return t.getAttribute("data-prop");var n=t.parentNode;return n&&n!==document?pw.node.propName(n):void 0},versionName:function(t){return t.hasAttribute("data-version")?t.getAttribute("data-version"):void 0},invoke:function(t,n){n.call(t)},invokeWithData:function(t,n,e){pw.node.isNodeList(t)&&(t=pw.node.toA(t)),t=Array.ensure(t),n=Array.ensure(n),t.forEach(function(t,i){e.call(t,n[i])})},match:function(t,e){pw.node.isNodeList(t)&&(t=pw.node.toA(t)),t=Array.ensure(t),e=Array.ensure(e);var i=e.reduce(function(t,e,i){var o=n[i]||n[n.length-1],r=o.cloneNode(!0);return o.parentNode.insertBefore(r),t.concat([r])},[]);return t.forEach(function(t){t.parentNode.removeChild(t)}),i},repeat:function(t,n,e){pw.node.invokeWithData(pw.node.match(t,n),n,e)},bind:function(t,n,e){var i=pw.node.findBindings(n)[0];pw.node.invokeWithData(n,t,function(t){t&&(t.id&&this.setAttribute("data-id",t.id),pw.node.bindDataToScope(t,i,n),"undefined"!=typeof e&&e.call(this,t))})},apply:function(t,n,e){var i=pw.node.match(n,t);return pw.node.bind(t,i,e),i},findBindings:function(t){var n=[];return pw.node.breadthFirst(t,function(){var t=this,e=t.getAttribute("data-scope");if(e){var i=[];pw.node.breadthFirst(t,function(){var n=this;if(t==n||!n.getAttribute("data-scope")){var e=n.getAttribute("data-prop");e&&i.push({prop:e,doc:n})}}),n.push({scope:e,props:i,doc:t})}}),n},bindDataToScope:function(t,n,e){t&&n&&n.props.forEach(function(n){k=n.prop,v=t[k],v||(v=""),"object"==typeof v?(pw.node.bindValueToNode(v.__content,n.doc),pw.node.bindAttributesToNode(v.__attrs,n.doc)):pw.node.bindValueToNode(v,n.doc)})},bindAttributesToNode:function(t,n){var e=pw.attrs.init(pw.view.init(n));for(var i in t){var o=t[i];"function"==typeof o&&(o=o.call(n.getAttribute(i))),o?o instanceof Array?o.forEach(function(t){e[t[0]](i,t[1])}):e.set(i,o):e.remove(i)}},bindValueToNode:function(t,n){pw.node.isTagWithoutValue(n)||("INPUT"===n.tagName&&"checkbox"===n.type?t===!0||n.value&&t===n.value?n.checked=!0:n.checked=!1:"TEXTAREA"===n.tagName||pw.node.isSelfClosingTag(n)?n.value=t:t&&(n.innerHTML=t))},isTagWithoutValue:function(t){return-1!=i.indexOf(t.tagName)?!0:!1},isSelfClosingTag:function(t){return-1!=o.indexOf(t.tagName)?!0:!1},breadthFirst:function(t,n){for(var e=[t];e.length>0;){var i=e.shift();if(i){"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&i.cloneNode&&n.call(i);var o=i.childNodes;if(o)for(var r=0;r<o.length;r++)e.push(o[r])}}},isNodeList:function(t){return"undefined"!=typeof t.length},byAttr:function(t,n,e){return pw.node.all(t).filter(function(t){var i=t.getAttribute(n);return null!==i&&("undefined"==typeof e||i==e)})},setAttr:function(t,n,e){"style"===n?e.pairs().forEach(function(n){t.style[n[0]]=n[1]}):("class"===n&&(e=e.join(" ")),"checked"===n&&(e=e?"checked":"",t.checked=e),t.setAttribute(n,e))},all:function(t){var n=[];return t?(document!==t&&n.push(t),n.concat(pw.node.toA(t.getElementsByTagName("*")))):n},before:function(t,n){t.parentNode.insertBefore(n,t)},after:function(t,n){t.parentNode.insertBefore(n,this.nextSibling)},replace:function(t,n){t.parentNode.replaceChild(n,t)},append:function(t,n){t.appendChild(n)},prepend:function(t,n){t.insertBefore(n,t.firstChild)},remove:function(t){t.parentNode.removeChild(t)},clear:function(t){for(;t.firstChild;)pw.node.remove(t.firstChild)},title:function(t,n){var e;(e=t.getElementsByTagName("title")[0])&&(e.innerText=n)},toA:function(t){return Array.prototype.slice.call(t)},serialize:function(t){var n,e,i,o,r,a,s={};return t.querySelectorAll("input, select, textarea").forEach(function(t){n=s,i=t.name.split("["),o=i[i.length-1],i.forEach(function(i){e=pw.node.value(t),"]"==i&&(r[a]instanceof Array||(r[a]=[]),e&&r[a].push(e)),i!=o&&(e={}),i=i.replace("]",""),""!=i&&"_method"!=i&&(n[i]||(n[i]=e),r=n,a=i,n=n[i])})}),s}},pw.attrs={init:function(t){return new a(pw.collection.init(t))}};var r={hash:["style"],bool:["selected","checked","disabled","readonly","multiple"],mult:["class"]},a=function(t){this.views=t.views};a.prototype={findType:function(t){return r.hash.indexOf(t)>-1?"hash":r.bool.indexOf(t)>-1?"bool":r.mult.indexOf(t)>-1?"mult":"text"},findValue:function(t,n){switch(n){case"class":return t.node.classList;case"style":return t.node.style}return"bool"===this.findType(n)?t.node.hasAttribute(n):t.node.getAttribute(n)},set:function(t,n){this.views.forEach(function(e){pw.node.setAttr(e.node,t,n)})},remove:function(t){this.views.forEach(function(n){n.node.removeAttribute(t)})},ensure:function(t,n){this.views.forEach(function(e){var i=this.findValue(e,t);if("class"===t)i.contains(n)||i.add(n);else if("style"===t)n.pairs().forEach(function(t){e.node.style[t[0]]=t[1]});else if("bool"===this.findType(t))e.node.hasAttribute(t)||pw.node.setAttr(e.node,t,t);else{var i=e.node.getAttribute(t)||"";i.match(n)||pw.node.setAttr(e.node,t,i+n)}},this)},deny:function(t,n){this.views.forEach(function(e){var i=this.findValue(e,t);"class"===t?i.contains(n)&&i.remove(n):"style"===t?n.pairs().forEach(function(t){e.node.style[t[0]]=e.node.style[t[0]].replace(t[1],"")}):"bool"===this.findType(t)?e.node.hasAttribute(t)&&e.node.removeAttribute(t):pw.node.setAttr(e.node,t,e.node.getAttribute(t).replace(n,""))},this)},insert:function(t,n){this.views.forEach(function(e){var i=this.findValue(e,t);switch(t){case"class":i.add(n);break;default:pw.node.setAttr(e.node,t,i+n)}},this)}},pw.state={build:function(t,n){var e;return t.reduce(function(t,i){return(e=pw.state.buildForNode(i,n))&&t.push(e),t},[])},buildForNode:function(t,n){var e=t[0],i={};if("scope"===e.type)i.id=e.node.getAttribute("data-id"),i.scope=e.node.getAttribute("data-scope");else if("prop"===e.type&&n)return void(n[e.node.getAttribute("data-prop")]=pw.node.value(e.node));return i.__nested=pw.state.build(t[1],i),i},init:function(t,n){return new s(t,n)}};var s=function(t){this.node=t,this.snapshots=[],this.update()};s.prototype={update:function(){this.snapshots.push(pw.state.build(pw.node.significant(this.node)))},diffNode:function(t){return t.hasAttribute("data-ui")?{__nested:pw.state.build(pw.node.significant(t))}:pw.state.build(pw.node.significant(pw.node.scope(t)))[0]},revert:function(){var t=pw.util.dup(this.snapshots[0]);return this.snapshots=[t],t},rollback:function(){return this.snapshots.pop(),this.current()},node:function(t){return this.current.flatten().find(function(n){return n.scope===t.scope&&n.id===t.id})},append:function(t){var n=this.copy();n.push(t),this.snapshots.push(n)},prepend:function(t){var n=this.copy();n.unshift(t),this.snapshots.push(n)},remove:function(t){var n=this.copy(),e=n.find(function(n){return n.id===t.id});e&&(n.splice(n.indexOf(e),1),this.snapshots.push(n))},copy:function(){return pw.util.dup(this.current())},current:function(){return this.snapshots[this.snapshots.length-1]},initial:function(){return this.snapshots[0]}},pw.view={init:function(t){return new c(t)},fromStr:function(t){var n="div";(t.match(/^<tr/)||t.match(/^<tbody/))&&(n="table");var e=document.createElement(n);return e.innerHTML=t,pw.view.init(e.childNodes[0])}};var c=function(t){this.node=t};c.prototype={clone:function(){return pw.view.init(this.node.cloneNode(!0))},title:function(t){pw.node.title(this.node,t)},text:function(t){this.node.innerText=t},html:function(t){this.node.innerHTML=t},component:function(t){return pw.collection.init(pw.node.byAttr(this.node,"data-ui",t).reduce(function(t,n){return t.concat(pw.view.init(n))},[]),this)},attrs:function(){return pw.attrs.init(this)},invoke:function(t){pw.node.invoke(this.node,t)},match:function(t){pw.node.match(this.node,t)},invokeWithData:function(t,n){pw.node.invokeWithData(this.node,t,n)},repeat:function(t,n){pw.node.repeat(this.node,t,n)},bind:function(t,n){pw.node.bind(t,this.node,n)},apply:function(t,n){pw.node.apply(t,this.node,n)},use:function(t,n){var e=this;if(this.node.getAttribute("data-version")!=t){this.node.setAttribute("data-version",t);var i={scope:this.node.getAttribute("data-scope"),version:t};window.socket.fetchView(i,function(t){t.node.setAttribute("data-channel",e.node.getAttribute("data-channel")),pw.node.replace(e.node,t.node),e.node=t.node,n()})}else n()},setEndpoint:function(t){return this.endpoint=t,this},first:function(){return this},length:function(){return 1}},["scope","prop"].forEach(function(t){c.prototype[t]=function(n){return pw.collection.init(pw.node.byAttr(this.node,"data-"+t,n).reduce(function(t,n){return t.concat(pw.view.init(n))},[]),this,n)}}),["remove","clear","versionName"].forEach(function(t){c.prototype[t]=function(){return pw.node[t](this.node)}}),["after","before","replace","append","prepend","insert"].forEach(function(t){c.prototype[t]=function(n){return pw.node[t](this.node,n.node)}}),pw.collection={init:function(t,n,e){return t instanceof u?t:(t.constructor!==Array&&(t=[t]),new u(t,n,e))},fromNodes:function(t,n,e){return pw.collection.init(t.map(function(t){return pw.view.init(t)}),n,e)}};var u=function(t,n,e){this.views=t,this.parent=n,this._scope=e};u.prototype={clone:function(){return pw.collection.init(this.views.map(function(t){return t.clone()}))},last:function(){return this.views[this.length()-1]},first:function(){return this.views[0]},removeView:function(t){var n=this.views.indexOf(t);n>-1&&this.views.splice(n,1)[0].remove()},addView:function(t){var n=[];t instanceof u?n=t.views:n.push(t),this.length()>0?n.forEach(function(t){pw.node.after(this.last().node,t.node)},this):this.parent&&n.forEach(function(t){this.parent.append(t)},this),this.views=this.views.concat(n)},order:function(t){t.forEach(function(t){if(t){var n=this.views.find(function(n){return n.node.getAttribute("data-id")==t.toString()});if(n){n.node.parentNode.appendChild(n.node);var e=this.views.indexOf(n);this.views.splice(e,1),this.views.push(n)}}},this)},length:function(){return this.views.length},attrs:function(){return pw.attrs.init(this.views)},append:function(t){t=Array.ensure(t);var n=this.last();return this.views.push(n.append(t)),n},prepend:function(t){t=Array.ensure(t);var n=t.map(function(t){var n=this.first().prepend(t);return this.views.push(n),n},this);return pw.collection.init(n)},invoke:function(t){pw.node.invoke(this.views,t)},invokeWithData:function(t,n){t=Array.ensure(t),this.views.forEach(function(e,i){n.call(e,t[i])})},match:function(t,n){if(t=Array.ensure(t),0===t.length)return this.remove(),n.call(this);var e,i;if(this.views[0]&&(e=this.views[0].clone(),i=this.views[0].node.parentNode),this.views.slice(0).forEach(function(n){var e=n.node.getAttribute("data-id");return!e&&t[0].id?void this.removeView(n):void(e&&(t.find(function(t){return t.id&&t.id.toString()===e})||this.removeView(n)))},this),!(t.length>this.length()))return n.call(this);var o=this;return this.endpoint.template(this,function(r){return r||(r=e.clone(),o.parent=pw.view.init(i)),t.forEach(function(t){if(!o.views.find(function(n){return n.node.getAttribute("data-id")===(t.id||"").toString()})){var n=r.clone();n instanceof u&&(n=n.views[0]),n.node.setAttribute("data-id",t.id),o.addView(n),pw.component.findAndInit(n.node)}},o),n.call(o)}),this},repeat:function(t,n){this.match(t,function(){this.invokeWithData(t,n)})},bind:function(t,n){return this.invokeWithData(t,function(t){this.bind(t),"undefined"!=typeof n&&n.call(this,t)}),this},apply:function(t,n){this.match(t,function(){var e;this.order(t.map(function(t){return(e=t.id)?e.toString():void 0})),this.bind(t,n)})},version:function(t,n){this.match(t,function(){this.invokeWithData(t,n)})},setEndpoint:function(t){return this.endpoint=t,this}},["scope","prop","component"].forEach(function(t){u.prototype[t]=function(n){return pw.collection.init(this.views.reduce(function(e,i){return e.concat(i[t](n).views)},[]))}}),["remove","clear","text","html"].forEach(function(t){u.prototype[t]=function(n){this.views.forEach(function(e){e[t](n)})}}),pw.init.register(function(){pw.component.findAndInit(document.querySelectorAll("body")[0])});var d={},p={},f={},h={};pw.component={init:function(t,n){return new l(t,n)},resetChannels:function(){p={}},findAndInit:function(t){pw.node.byAttr(t,"data-ui").forEach(function(t){if(!t._ui){var n=t.getAttribute("data-ui"),e=d[n]||pw.component.init;h[n]||(h[n]=[]);var i=t.getAttribute("data-channel"),o=t.getAttribute("data-config"),r=pw.view.init(t),a=h[n].length,s=new e(r,pw.component.buildConfigObject(o),n,a);s.init(r,o,n),pw.component.registerForChannel(s,i),h[n].push(s),t._ui=!0}})},push:function(t){var n=t.channel,e=t.payload,i=e.instruct;(p[n]||[]).forEach(function(t){i?t.instruct(n,i):t.message(n,e)})},register:function(t,n){var e=l.prototype;Object.getOwnPropertyNames(e).forEach(function(t){n.prototype[t]=e[t]}),d[t]=n},buildConfigObject:function(t){return t?t.split(";").reduce(function(t,n){var e=n.trim().split(":");return t[e[0].trim()]=e[1].trim(),t},{}):{}},registerForChannel:function(t,n){p[n]||(p[n]=[]),p[n].push(t)},registerForBroadcast:function(t,n,e){f[t]||(f[t]=[]),f[t].push([n,e])},deregisterForBroadcast:function(t,n){var e=f[t],i=e.find(function(t){return t[1]==n}),o=e.indexOf(i);e.splice(o,1)},broadcast:function(t,n){(f[t]||[]).forEach(function(t){t[0].call(t[1],n)})}};var l=function(t,n,e){};l.prototype={init:function(t,n,e){var i=t.node;this.view=t,this.node=i,this.config=n,this.name=e,this.templates={};var o=this;if(pw.node.toA(i.querySelectorAll(":scope > *[data-template]")).forEach(function(t){var n=t.cloneNode(!0);pw.node.remove(t);var e=n.getAttribute("data-scope");this.templates[e]?this.templates[e].views.push(pw.view.init(n)):this.templates[e]=pw.collection.init(pw.view.init(n)),n.removeAttribute("data-template")},this),this.state=pw.state.init(this.node),this.dCb){var r=pw.node.component(this.node.parentNode);r&&(r.addEventListener("mutated",function(t){o.transform(o.dCb(t.target._evtData))}),o.transform(o.dCb(pw.state.init(r).current())))}var a=function(t){var n=pw.node.scope(t.target);n&&(t.preventDefault(),o.mutated(n))};i.addEventListener("submit",a),i.addEventListener("change",function(t){pw.node.inForm(t.target)||a(t)}),this.inited&&this.inited()},listen:function(t,n){pw.component.registerForBroadcast(t,n,this)},ignore:function(t){pw.component.deregisterForBroadcast(t,this)},bubble:function(t,n){var e=pw.node.component(this.node.parentNode);(f[t]||[]).forEach(function(t){t[1].node==e&&t[0].call(t[1],n)})},trickle:function(t,n){var e=f[t]||[];pw.node.toA(this.node.getElementsByTagName("*")).forEach(function(t){e.forEach(function(e){e[1].node==t&&e[0].call(e[1],n)})})},instruct:function(t,n){this.endpoint=pw.instruct;var e=this.state.current();if(1===e.length){var i=this.view.scope(e[0].scope),o=i.views[0].node;if("empty"===o.getAttribute("data-version")){var r=this;return void pw.instruct.template(i,function(t){var e=o.parentNode;e.replaceChild(t.node,o),n.forEach(function(t){r[t[0]](t[1])})})}}n.forEach(function(t){this[t[0]](t[1])},this)},message:function(t,n){},mutated:function(t){this.mutation(this.state.diffNode(t)),this.state.update(),pw.node.trigger("mutated",this.node,this.state.current())},mutation:function(t){},transform:function(t){this._transform(t)},_transform:function(t){t&&(t.length>0?this.view.scope(t[0].scope).setEndpoint(this.endpoint||this).apply(t):pw.node.breadthFirst(this.view.node,function(){this.hasAttribute("data-scope")&&pw.node.remove(this)}),pw.node.trigger("mutated",this.node,this.state.current()))},revert:function(){this.transform(this.state.revert())},rollback:function(){this.transform(this.state.rollback())},template:function(t,n){var e;(e=this.templates[t.scope])&&n(e)},remove:function(t){this.state.remove(t),this.transform(this.state.current())},append:function(t){this.state.append(t),this.transform(this.state.current())},prepend:function(t){this.state.prepend(t),this.transform(this.state.current())},parent:function(){var t=pw.node.scope(this.node);return t?pw.state.init(t).current()[0]:void 0},dependent:function(t){this.dCb=t}},pw.init.register(function(){pw.socket.init({cb:function(t){window.socket=t,pw.component.broadcast("socket:available")}})}),pw.socket={init:function(t){return pw.socket.connect(t.host,t.port,t.protocol,t.connId,t.cb)},connect:function(t,n,e,i,o){if("undefined"==typeof t&&(t=window.location.hostname),"undefined"==typeof n&&(n=window.location.port),"undefined"==typeof e&&(e=window.location.protocol),"undefined"==typeof i&&(i=document.getElementsByTagName("body")[0].getAttribute("data-socket-connection-id")),i){var r="";return"http:"===e?r+="ws://":"https:"===e&&(r+="wss://"),r+=t,n&&(r+=":"+n),r+="/?socket_connection_id="+i,new w(r,o)}}};var w=function(t,n){var e=this;this.callbacks={},this.url=t,this.initCb=n,this.ws=new WebSocket(t),this.id=t.split("socket_connection_id=")[1];var i;this.ws.onmessage=function(t){pw.component.broadcast("socket:loaded");var n=JSON.parse(t.data);if(n.id){var i=e.callbacks[n.id];if(i)return void i.call(this,n)}e.message(n)},this.ws.onclose=function(t){console.log("socket closed"),clearInterval(i),e.reconnect()},this.ws.onopen=function(t){console.log("socket open"),e.initCb&&e.initCb(e),i=setInterval(function(){e.send({action:"ping"})},3e4)}};w.prototype={send:function(t,n){pw.component.broadcast("socket:loading"),t.id=pw.util.guid(),t.input||(t.input={}),t.input.socket_connection_id=this.id,this.callbacks[t.id]=n,this.ws.send(JSON.stringify(t))},message:function(t){console.log("received message"),console.log(t);var n='*[data-channel="'+t.channel+'"]';if(t.channel&&"component"===t.channel.split(":")[0])return void pw.component.push(t);var e=pw.node.toA(document.querySelectorAll(n));0!==e.length&&pw.instruct.process(pw.collection.fromNodes(e,n),t,this)},reconnect:function(){var t=this;t.wait?t.wait*=1.25:t.wait=100,console.log("reconnecting socket in "+t.wait+"ms"),setTimeout(function(){pw.socket.init({cb:t.initCb})},t.wait)},fetchView:function(t,n){var e;if(window.location.hash){var i=window.location.hash.split("#:")[1].split("/");i.shift(),e=i.join("/")}else e=window.location.pathname+window.location.search;this.send({action:"fetch-view",lookup:t,uri:e},function(t){var e=pw.view.fromStr(t.body);e.node?(e.node.removeAttribute("data-id"),n(e)):n()})}},pw.instruct={process:function(t,n,e){1===t.length()&&"empty"===t.views[0].node.getAttribute("data-version")?pw.instruct.fetchView(n,e,t.views[0].node):pw.instruct.perform(t,n.payload)},fetchView:function(t,n,e){n.fetchView({channel:t.channel},function(n){if(n){var i=e.parentNode;i.replaceChild(n.node,e);var o='*[data-channel="'+t.channel+'"]',r=pw.node.toA(i.querySelectorAll(o));pw.instruct.perform(pw.collection.fromNodes(r,o),t.payload)}else console.log("trouble fetching view :(")})},template:function(t,n){var e={};if(!t||!t.first())return n();var i=t.first().node;if(i.hasAttribute("data-channel"))e.channel=t.first().node.getAttribute("data-channel");else{if(!i.hasAttribute("data-ui")||!i.hasAttribute("data-scope"))return void n();e.component=pw.node.component(i).getAttribute("data-ui"),e.scope=i.getAttribute("data-scope")}window.socket.fetchView(e,function(t){n(t)})},perform:function(t,n,e){function i(n,e){var i=e[0],r=e[1],s=e[2];if("with"===i&&(i="invoke"),"for"===i&&(i="invokeWithData"),!t[i])return void console.log("could not find method named: "+i);if("invoke"==i||"invokeWithData"==i||"bind"==i||"repeat"==i||"apply"==i||"version"==i){var c=t.length(),u=0,d=function(){u++,u==c&&o()};return void t.setEndpoint(a)[i].call(t,r,function(t){pw.instruct.perform(this,s[r.indexOf(t)],d)})}if("attrs"==i)return void a.performAttr(t.attrs(),s);if("use"==i)return t.setEndpoint(a),void t.use(r,o);var p=t[i].call(t,r);return s instanceof Array?void pw.instruct.perform(p,s,o):(p&&(t=p),void o())}function o(){s<n.length?i(t,n[s++]):r()}function r(){e?e():pw.component.findAndInit(t.node)}var a=this;n=n||[];var s=0;o()},performAttr:function(t,n){n.forEach(function(n){var e=n[0],i=n[1],o=n[2];i?t.set(e,i):t[o[0][0]](e,o[0][1])})}},Array.prototype.flatten||(Array.prototype.flatten=function(){return this.reduce(function(t,n){return t.concat(Array.isArray(n)?n.flatten():n)},[])}),Array.prototype.find||(Array.prototype.find=function(t){if(null==this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n,e=Object(this),i=e.length>>>0,o=arguments[1],r=0;i>r;r++)if(n=e[r],t.call(o,n,r,e))return n;return void 0}),Array.ensure=function(t){return t instanceof Array?t:[t]},NodeList.prototype.forEach=Array.prototype.forEach,Object.prototype.pairs||Object.defineProperty(Object.prototype,"pairs",{value:function(){return Object.keys(this).map(function(t){return[t,this[t]]},this)},enumerable:!1}),"function"==typeof define&&define.amd?define(pw):"object"==typeof module&&module.exports?module.exports=pw:this.pw=pw}();
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --format documentation
data/lib/pakyow.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'version'
1
+ require 'pakyow/version'
2
2
 
3
3
  %w[
4
4
  pakyow-support
@@ -0,0 +1,79 @@
1
+ require "thor"
2
+
3
+ module Pakyow
4
+ class CommandLineInterface < Thor
5
+ map ["--version", "-v"] => :version
6
+
7
+ desc "new DESTINATION", <<DESC
8
+ Description:
9
+ The 'pakyow new' command creates a new Pakyow application at the path
10
+ specified.
11
+
12
+ Example:
13
+ pakyow new path/to/application
14
+
15
+ This generates a new Pakyow application in path/to/application.
16
+ DESC
17
+ def new(destination)
18
+ require "generators/pakyow/app/app_generator"
19
+ Pakyow::Generators::AppGenerator.start(destination)
20
+ end
21
+
22
+ desc "console ENVIRONMENT", <<DESC
23
+ Description:
24
+ The 'pakyow console' command stages the application and starts an interactive
25
+ session. If environment is not specified, the default_environment defined by
26
+ your application will be used.
27
+
28
+ Example:
29
+ pakyow console development
30
+
31
+ This starts the console with the 'development' configuration.
32
+ DESC
33
+ def console(environment = :development)
34
+ require "pakyow/commands/console"
35
+ Pakyow::Commands::Console
36
+ .new(environment: environment)
37
+ .run
38
+ rescue LoadError => e
39
+ raise Thor::Error, <<ERR
40
+ Error: #{e.message}
41
+ You must run the `pakyow console` command in a Pakyow application's root directory.
42
+ ERR
43
+ end
44
+
45
+ desc "server ENVIRONMENT", <<DESC
46
+ Description:
47
+ The 'pakyow server' command starts the application server.
48
+
49
+ If environment is not specified, the default_environment defined
50
+ by your application will be used.
51
+
52
+ If port is not specified, the port defined
53
+ by your application will be used (defaults to 3000).
54
+
55
+ Example:
56
+ pakyow server development -p 3001
57
+
58
+ This starts the application server on port 3001 with the 'development' configuration.
59
+ DESC
60
+ option :port, type: :numeric, aliases: :p, default: 3000
61
+ def server(environment = :development)
62
+ require "pakyow/commands/server"
63
+ Pakyow::Commands::Server
64
+ .new(environment: environment, port: options[:port])
65
+ .run
66
+ rescue LoadError => e
67
+ raise Thor::Error, <<ERR
68
+ Error: #{e.message}
69
+ You must run the `pakyow server` command in a Pakyow application's root directory.
70
+ ERR
71
+ end
72
+
73
+ desc "version", "Display the installed Pakyow version"
74
+ def version
75
+ require "pakyow/version"
76
+ puts "Pakyow #{Pakyow::VERSION}"
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,27 @@
1
+ require "pakyow/commands/console_methods.rb"
2
+
3
+ module Pakyow
4
+ module Commands
5
+ class Console
6
+ def initialize(environment: ENV['RACK_ENV'] || :development)
7
+ ENV['RACK_ENV'] = environment.to_s
8
+ end
9
+
10
+ def run
11
+ load_app
12
+ Pakyow::App.stage(ENV['RACK_ENV'])
13
+ require 'irb'
14
+ ARGV.clear
15
+ IRB::ExtendCommandBundle.include(ConsoleMethods)
16
+ IRB.start
17
+ end
18
+
19
+ private
20
+
21
+ def load_app
22
+ $LOAD_PATH.unshift(Dir.pwd)
23
+ require 'app/setup'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module Pakyow
2
+ module Commands
3
+ module ConsoleMethods
4
+ def reload
5
+ puts "Reloading..."
6
+ Pakyow.app.reload
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ require 'pakyow/version'
2
+
3
+ module Pakyow
4
+ module Commands
5
+ class Server
6
+ attr_reader :port
7
+
8
+ def initialize(environment: ENV['RACK_ENV'] || :development, port: 3000)
9
+ ENV['RACK_ENV'] = environment.to_s
10
+ @port = port
11
+ end
12
+
13
+ def run
14
+ load_app
15
+ Pakyow::Config.server.port = port
16
+ v = 'v' + Pakyow::VERSION
17
+
18
+ msg = ' __ ' + "\n"\
19
+ ' ____ ____ _/ /____ ______ _ __' + "\n"\
20
+ ' / __ \/ __ `/ //_/ / / / __ \ | /| / /' + "\n"\
21
+ ' / /_/ / /_/ / ,< / /_/ / /_/ / |/ |/ / ' + "\n"\
22
+ ' / .___/\__,_/_/|_|\__, /\____/|__/|__/ ' + v + "\n"\
23
+ '/_/ /____/ ' + "\n"
24
+
25
+ puts Pakyow::Logger::COLOR_SEQ % (30 + Pakyow::Logger::COLOR_TABLE.index(:red)) + msg + Pakyow::Logger::RESET_SEQ
26
+
27
+ Pakyow::App.run(ENV['RACK_ENV'])
28
+ end
29
+
30
+ private
31
+
32
+ def load_app
33
+ $LOAD_PATH.unshift(Dir.pwd)
34
+ require 'app/setup'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Pakyow
2
+ VERSION = '0.11.0'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-16 00:00:00.000000000 Z
12
+ date: 2016-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pakyow-support
@@ -17,112 +17,112 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.10.2
20
+ version: 0.11.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 0.10.2
27
+ version: 0.11.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pakyow-core
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 0.10.2
34
+ version: 0.11.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 0.10.2
41
+ version: 0.11.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: pakyow-presenter
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - '='
47
47
  - !ruby/object:Gem::Version
48
- version: 0.10.2
48
+ version: 0.11.0
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: 0.10.2
55
+ version: 0.11.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: pakyow-mailer
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 0.10.2
62
+ version: 0.11.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.10.2
69
+ version: 0.11.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: pakyow-realtime
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - '='
75
75
  - !ruby/object:Gem::Version
76
- version: 0.10.2
76
+ version: 0.11.0
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - '='
82
82
  - !ruby/object:Gem::Version
83
- version: 0.10.2
83
+ version: 0.11.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: pakyow-ui
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - '='
89
89
  - !ruby/object:Gem::Version
90
- version: 0.10.2
90
+ version: 0.11.0
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - '='
96
96
  - !ruby/object:Gem::Version
97
- version: 0.10.2
97
+ version: 0.11.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: pakyow-rake
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - '='
103
103
  - !ruby/object:Gem::Version
104
- version: 0.10.2
104
+ version: 0.11.0
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - '='
110
110
  - !ruby/object:Gem::Version
111
- version: 0.10.2
111
+ version: 0.11.0
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: pakyow-test
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - '='
117
117
  - !ruby/object:Gem::Version
118
- version: 0.10.2
118
+ version: 0.11.0
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - '='
124
124
  - !ruby/object:Gem::Version
125
- version: 0.10.2
125
+ version: 0.11.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: bundler
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +137,34 @@ dependencies:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
139
  version: '1.10'
140
+ - !ruby/object:Gem::Dependency
141
+ name: thor
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.19'
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.19'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rspec
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '3.0'
140
168
  description: Modern web framework for Ruby
141
169
  email: bryan@metabahn.com
142
170
  executables:
@@ -148,12 +176,6 @@ files:
148
176
  - LICENSE
149
177
  - README.md
150
178
  - bin/pakyow
151
- - lib/commands/USAGE
152
- - lib/commands/USAGE-CONSOLE
153
- - lib/commands/USAGE-NEW
154
- - lib/commands/USAGE-SERVER
155
- - lib/commands/console.rb
156
- - lib/commands/server.rb
157
179
  - lib/generators/pakyow/app/app_generator.rb
158
180
  - lib/generators/pakyow/app/templates/Gemfile
159
181
  - lib/generators/pakyow/app/templates/README.md
@@ -165,12 +187,17 @@ files:
165
187
  - lib/generators/pakyow/app/templates/app/views/_templates/default.html
166
188
  - lib/generators/pakyow/app/templates/app/views/index.html
167
189
  - lib/generators/pakyow/app/templates/config.ru
190
+ - lib/generators/pakyow/app/templates/env
191
+ - lib/generators/pakyow/app/templates/env.example
192
+ - lib/generators/pakyow/app/templates/gitignore
168
193
  - lib/generators/pakyow/app/templates/public/apple-touch-icon-precomposed.png
169
194
  - lib/generators/pakyow/app/templates/public/apple-touch-icon.png
170
195
  - lib/generators/pakyow/app/templates/public/favicon.ico
171
196
  - lib/generators/pakyow/app/templates/public/scripts/ring/LICENSE
172
197
  - lib/generators/pakyow/app/templates/public/scripts/ring/components/fastlink.js
173
198
  - lib/generators/pakyow/app/templates/public/scripts/ring/components/fastlink.min.js
199
+ - lib/generators/pakyow/app/templates/public/scripts/ring/components/ga.js
200
+ - lib/generators/pakyow/app/templates/public/scripts/ring/components/ga.min.js
174
201
  - lib/generators/pakyow/app/templates/public/scripts/ring/components/loader.js
175
202
  - lib/generators/pakyow/app/templates/public/scripts/ring/components/loader.min.js
176
203
  - lib/generators/pakyow/app/templates/public/scripts/ring/components/modal.js
@@ -189,10 +216,15 @@ files:
189
216
  - lib/generators/pakyow/app/templates/public/styles/pakyow-css/structure.css
190
217
  - lib/generators/pakyow/app/templates/public/styles/pakyow-css/syntax.css
191
218
  - lib/generators/pakyow/app/templates/public/styles/pakyow-css/theme.css
219
+ - lib/generators/pakyow/app/templates/rspec
192
220
  - lib/generators/pakyow/app/templates/spec/integration/app_spec.rb
193
221
  - lib/generators/pakyow/app/templates/spec/spec_helper.rb
194
222
  - lib/pakyow.rb
195
- - lib/version.rb
223
+ - lib/pakyow/command_line_interface.rb
224
+ - lib/pakyow/commands/console.rb
225
+ - lib/pakyow/commands/console_methods.rb
226
+ - lib/pakyow/commands/server.rb
227
+ - lib/pakyow/version.rb
196
228
  homepage: http://pakyow.org
197
229
  licenses:
198
230
  - MIT
@@ -213,9 +245,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
245
  version: '0'
214
246
  requirements: []
215
247
  rubyforge_project:
216
- rubygems_version: 2.4.5
248
+ rubygems_version: 2.5.1
217
249
  signing_key:
218
250
  specification_version: 4
219
251
  summary: Pakyow
220
252
  test_files: []
221
- has_rdoc:
data/lib/commands/USAGE DELETED
@@ -1,9 +0,0 @@
1
- Usage:
2
- pakyow command
3
-
4
- There are three commands:
5
- new Create a new Pakyow application
6
- server Start the application server
7
- console Start the application console
8
-
9
- Run a command with -h for more information.
@@ -1,12 +0,0 @@
1
- Usage:
2
- pakyow console [environment]
3
-
4
- Description:
5
- The 'pakyow console' command stages the application and starts an interactive
6
- session. If environment is not specified, the default_environment defined by
7
- your application will be used.
8
-
9
- Example:
10
- pakyow console development
11
-
12
- This starts the console with the 'development' configuration.
@@ -1,11 +0,0 @@
1
- Usage:
2
- pakyow new application
3
-
4
- Description:
5
- The 'pakyow new' command creates a new Pakyow application at the path
6
- specified.
7
-
8
- Example:
9
- pakyow new path/to/application
10
-
11
- This generates a new Pakyow application in path/to/application.