Merge lp:~thomir-deactivatedaccount/spi-webui/trunk-start-bootstrapping into lp:spi-webui
- trunk-start-bootstrapping
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Fabian Popa |
Approved revision: | 10 |
Merged at revision: | 3 |
Proposed branch: | lp:~thomir-deactivatedaccount/spi-webui/trunk-start-bootstrapping |
Merge into: | lp:spi-webui |
Diff against target: |
198 lines (+150/-7) 7 files modified
.bzrignore (+6/-0) Makefile (+73/-1) README (+25/-6) package.json (+29/-0) src/example.tag (+5/-0) src/index.html (+10/-0) src/riot.min.js (+2/-0) |
To merge this branch: | bzr merge lp:~thomir-deactivatedaccount/spi-webui/trunk-start-bootstrapping |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Fabian Popa (community) | Approve | ||
Thomi Richards (community) | Approve | ||
Review via email: mp+273174@code.launchpad.net |
Commit message
Add the beginnings of a project structure.
Description of the change
Add the beginnings of a project structure. I've never used npm or gulp or riot before, so this may be all wrong.
Feel free to do whatever you like with this, including ignoring it entirely :D
Tanuki Bot (tanuki-bot) wrote : | # |
The attempt to merge lp:~thomir/spi-webui/trunk-start-bootstrapping into lp:spi-webui failed. Below is the output from the failed tests.
'npm' not found. Run 'sudo apt-get install npm'.
make: *** [npm-installed] Error 1
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
self-approving to get this landed. We have plans to improve the build process, but as discussed this morning, this is probably "good enough" for us to start tackling the important stuff.
Tanuki Bot (tanuki-bot) wrote : | # |
The attempt to merge lp:~thomir/spi-webui/trunk-start-bootstrapping into lp:spi-webui failed. Below is the output from the failed tests.
Downloading vendored tarballs.
Installing dependencies
"node/bin/npm" install
Branched 1 revision.
npm WARN package.json spi-webui@0.0.0 No repository field.
npm ERR! Linux 3.13.0-65-generic
npm ERR! argv "/tmp/tarmac/
npm ERR! node v4.1.2
npm ERR! npm v2.14.4
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect
npm ERR! network connect ETIMEDOUT 185.31.19.162:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! /tmp/tarmac/
make: *** [bootstrap] Error 1
Thomi Richards (thomir-deactivatedaccount) : | # |
Tanuki Bot (tanuki-bot) wrote : | # |
The attempt to merge lp:~thomir/spi-webui/trunk-start-bootstrapping into lp:spi-webui failed. Below is the output from the failed tests.
Downloading vendored tarballs.
Installing dependencies
"node/bin/npm" install
Branched 1 revision.
npm WARN package.json spi-webui@0.0.0 No repository field.
npm ERR! Linux 3.13.0-65-generic
npm ERR! argv "/tmp/tarmac/
npm ERR! node v4.1.2
npm ERR! npm v2.14.4
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect
npm ERR! network connect ETIMEDOUT 185.31.18.162:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! /tmp/tarmac/
make: *** [bootstrap] Error 1
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
*sigh*.
Tanuki Bot (tanuki-bot) wrote : | # |
There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.
Fabian Popa (fabpopa) wrote : | # |
if this doesn't work, I'm making a new branch
Preview Diff
1 | === added file '.bzrignore' | |||
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 | |||
3 | +++ .bzrignore 2015-10-07 02:24:18 +0000 | |||
4 | @@ -0,0 +1,6 @@ | |||
5 | 1 | node_modules | ||
6 | 2 | public/* | ||
7 | 3 | .watch.pid | ||
8 | 4 | .serve.pid | ||
9 | 5 | node | ||
10 | 6 | vendor_tarballs | ||
11 | 0 | 7 | ||
12 | === modified file 'Makefile' (properties changed: -x to +x) | |||
13 | --- Makefile 2015-10-01 23:08:48 +0000 | |||
14 | +++ Makefile 2015-10-07 02:24:18 +0000 | |||
15 | @@ -1,2 +1,74 @@ | |||
16 | 1 | #!/usr/bin/make -f | ||
17 | 2 | |||
18 | 3 | # The location we get tarballs from: | ||
19 | 4 | DEP_BRANCH := "lp:~tanuki/spi-webui/dependencies" | ||
20 | 5 | # The location we download them to: | ||
21 | 6 | TARBALL_PATH := "vendor_tarballs" | ||
22 | 7 | |||
23 | 8 | NPM := "node/bin/npm" | ||
24 | 9 | PWD := $(shell pwd) | ||
25 | 10 | WATCH_PIDFILE := ".watch.pid" | ||
26 | 11 | SERVE_PIDFILE := ".serve.pid" | ||
27 | 12 | |||
28 | 13 | all: bootstrap run | ||
29 | 14 | |||
30 | 15 | bootstrap: | ||
31 | 16 | # We vendor node, since we want a very specific version. | ||
32 | 17 | @if [ ! -d ${TARBALL_PATH} ] ; then \ | ||
33 | 18 | echo "Downloading vendored tarballs." ; \ | ||
34 | 19 | bzr branch ${DEP_BRANCH} ${TARBALL_PATH} ; \ | ||
35 | 20 | fi | ||
36 | 21 | @if [ ! -d node ] ; then \ | ||
37 | 22 | mkdir node ; \ | ||
38 | 23 | tar -xC node -f "${TARBALL_PATH}/node-v4.1.2-linux-x64.tar.gz" --strip-components=1; \ | ||
39 | 24 | fi | ||
40 | 25 | |||
41 | 26 | @echo "Installing dependencies" | ||
42 | 27 | ${NPM} install | ||
43 | 28 | |||
44 | 29 | # Commented out for now because we don't have a way to manage dependencies for | ||
45 | 30 | # CI. Ideally we'd put all our dependency tarballs in ${DEP_BRANCH}, and have | ||
46 | 31 | # npm install them for us. However, this feature does not exist in node yet. | ||
47 | 32 | # see: https://github.com/npm/npm/issues/4210 for more information | ||
48 | 33 | # check: bootstrap | ||
49 | 1 | check: | 34 | check: |
51 | 2 | @echo "Testing UI..." | 35 | #${NPM} test |
52 | 36 | |||
53 | 37 | build: bootstrap | ||
54 | 38 | ${NPM} run build | ||
55 | 39 | |||
56 | 40 | # buildwatch and stopbuildwatch start and stop persistent watching & building | ||
57 | 41 | # of files. You probably don't want to use this target directly. Instead, use | ||
58 | 42 | # the 'devserver' target instead. | ||
59 | 43 | buildwatch: bootstrap | ||
60 | 44 | start-stop-daemon --start --background --make-pidfile \ | ||
61 | 45 | --pidfile ${WATCH_PIDFILE} --chdir ${PWD} \ | ||
62 | 46 | --exec ${NPM} -- run build:watch | ||
63 | 47 | |||
64 | 48 | stopbuildwatch: | ||
65 | 49 | start-stop-daemon --stop --pidfile ${WATCH_PIDFILE} | ||
66 | 50 | rm ${WATCH_PIDFILE} | ||
67 | 51 | |||
68 | 52 | devserver: bootstrap buildwatch | ||
69 | 53 | start-stop-daemon --start --background --make-pidfile \ | ||
70 | 54 | --pidfile ${SERVE_PIDFILE} --chdir ${PWD} \ | ||
71 | 55 | --exec ${NPM} -- run serve | ||
72 | 56 | @echo "Development server running on http://localhost:8080/" | ||
73 | 57 | @echo "To stop it, run 'make stopserver'" | ||
74 | 58 | |||
75 | 59 | stopserver: stopbuildwatch | ||
76 | 60 | # kill -s SIGINT "-$(shell cat ${SERVE_PIDFILE})" | ||
77 | 61 | # Less than ideal, but http-server does some funky things with child processes | ||
78 | 62 | # that I need to figure out. | ||
79 | 63 | killall node | ||
80 | 64 | rm ${SERVE_PIDFILE} | ||
81 | 65 | |||
82 | 66 | @echo "Development server stopped." | ||
83 | 67 | |||
84 | 68 | # A simple alias for 'devserver', since that's what most people expect 'make run' | ||
85 | 69 | # to do. | ||
86 | 70 | run: devserver | ||
87 | 71 | |||
88 | 72 | |||
89 | 73 | clean: bootstrap | ||
90 | 74 | ${NPM} run clean | ||
91 | 3 | 75 | ||
92 | === modified file 'README' | |||
93 | --- README 2015-10-01 21:38:49 +0000 | |||
94 | +++ README 2015-10-07 02:24:18 +0000 | |||
95 | @@ -1,9 +1,28 @@ | |||
96 | 1 | SPI Web User Interface | 1 | SPI Web User Interface |
97 | 2 | ###################### | 2 | ###################### |
98 | 3 | 3 | ||
105 | 4 | Coming soon: | 4 | What is it? |
106 | 5 | 5 | =========== | |
107 | 6 | - How to build it | 6 | |
108 | 7 | - How to test it | 7 | The web ui project that integrates SPI, the click store, and parts of launchpad. |
109 | 8 | - How to run it | 8 | |
110 | 9 | 9 | How do I build it? | |
111 | 10 | ================== | ||
112 | 11 | |||
113 | 12 | Everything is done by the makefile. We require a more modern version of npm and | ||
114 | 13 | node than what is available in the archives. However, the makefile will take | ||
115 | 14 | care of downloading and installing the correct version of node. This will create | ||
116 | 15 | two directories in the source tree: | ||
117 | 16 | |||
118 | 17 | * "vendor_tarballs" will contain the bzr branch that we store vendored tarballs | ||
119 | 18 | in | ||
120 | 19 | * "node" will contain the node distribution. The 'node' and 'npm' binaries in | ||
121 | 20 | ``node/bin`` are then used for all other operations. | ||
122 | 21 | |||
123 | 22 | Some common make targets you probably want to look at are listed below: | ||
124 | 23 | |||
125 | 24 | * Run the tests: ``make check`` | ||
126 | 25 | * Build the app: ``make build`` | ||
127 | 26 | * Build the app, watching for changes, and serve locally: ``make devserver`` | ||
128 | 27 | * Stop the devserver: ``make stopserver`` | ||
129 | 28 | * Clean the public/ directory of built files: ``make clean`` | ||
130 | 10 | 29 | ||
131 | === added file 'package.json' | |||
132 | --- package.json 1970-01-01 00:00:00 +0000 | |||
133 | +++ package.json 2015-10-07 02:24:18 +0000 | |||
134 | @@ -0,0 +1,29 @@ | |||
135 | 1 | { | ||
136 | 2 | "name": "spi-webui", | ||
137 | 3 | "version": "0.0.0", | ||
138 | 4 | "description": "Web UI for SPI", | ||
139 | 5 | "main": "index.js", | ||
140 | 6 | "scripts": { | ||
141 | 7 | "test": "echo \"Error: no test specified\" && exit 1", | ||
142 | 8 | |||
143 | 9 | "build": "npm run build:riot && npm run build:css && npm run build:html && npm run build:js", | ||
144 | 10 | "build:riot": "riot src/ public/", | ||
145 | 11 | "build:css": "copyup src/**.css public/", | ||
146 | 12 | "build:html": "copyup src/**.html public/", | ||
147 | 13 | "build:js": "copyup src/**.js public/", | ||
148 | 14 | |||
149 | 15 | "clean": "rm -rf public/*", | ||
150 | 16 | "serve": "http-server public/ -p 8080", | ||
151 | 17 | "build:watch": "watch 'npm run build' src" | ||
152 | 18 | }, | ||
153 | 19 | "author": "", | ||
154 | 20 | "license": "ISC", | ||
155 | 21 | "devDependencies": { | ||
156 | 22 | "watch": "latest", | ||
157 | 23 | "http-server": "latest", | ||
158 | 24 | "copyfiles": "latest" | ||
159 | 25 | }, | ||
160 | 26 | "dependencies": { | ||
161 | 27 | "riot": "^2.2.4" | ||
162 | 28 | } | ||
163 | 29 | } | ||
164 | 0 | 30 | ||
165 | === added directory 'public' | |||
166 | === added directory 'src' | |||
167 | === added file 'src/example.tag' | |||
168 | --- src/example.tag 1970-01-01 00:00:00 +0000 | |||
169 | +++ src/example.tag 2015-10-07 02:24:18 +0000 | |||
170 | @@ -0,0 +1,5 @@ | |||
171 | 1 | <example> | ||
172 | 2 | <p>This is { sample }</p> | ||
173 | 3 | |||
174 | 4 | this.sample = 'example' | ||
175 | 5 | </example> | ||
176 | 0 | 6 | ||
177 | === added file 'src/index.html' | |||
178 | --- src/index.html 1970-01-01 00:00:00 +0000 | |||
179 | +++ src/index.html 2015-10-07 02:24:18 +0000 | |||
180 | @@ -0,0 +1,10 @@ | |||
181 | 1 | <!doctype html> | ||
182 | 2 | <html> | ||
183 | 3 | <body> | ||
184 | 4 | <example></example> | ||
185 | 5 | |||
186 | 6 | <script src="riot.min.js"></script> | ||
187 | 7 | <script src="example.js"></script> | ||
188 | 8 | <script>riot.mount('example')</script> | ||
189 | 9 | </body> | ||
190 | 10 | </html> | ||
191 | 0 | \ No newline at end of file | 11 | \ No newline at end of file |
192 | 1 | 12 | ||
193 | === added file 'src/riot.min.js' | |||
194 | --- src/riot.min.js 1970-01-01 00:00:00 +0000 | |||
195 | +++ src/riot.min.js 2015-10-07 02:24:18 +0000 | |||
196 | @@ -0,0 +1,2 @@ | |||
197 | 1 | /* Riot v2.2.4, @license MIT, (c) 2015 Muut Inc. + contributors */ | ||
198 | 2 | (function(e,t){"use strict";var n={version:"v2.2.4",settings:{}},i=0,r="riot-",o=r+"tag",u="string",f="object",a="undefined",s="function",c=/^(?:opt(ion|group)|tbody|col|t[rhd])$/,l=["_item","_id","update","root","mount","unmount","mixin","isMounted","isLoop","tags","parent","opts","trigger","on","off","one"],p=(e&&e.document||{}).documentMode|0,d=Array.isArray;n.observable=function(e){e=e||{};var t={},n=0;e.on=function(i,r){if(M(r)){if(typeof r.id===a)r._id=n++;i.replace(/\S+/g,function(e,n){(t[e]=t[e]||[]).push(r);r.typed=n>0})}return e};e.off=function(n,i){if(n=="*")t={};else{n.replace(/\S+/g,function(e){if(i){var n=t[e];for(var r=0,o;o=n&&n[r];++r){if(o._id==i._id)n.splice(r--,1)}}else{t[e]=[]}})}return e};e.one=function(t,n){function i(){e.off(t,i);n.apply(e,arguments)}return e.on(t,i)};e.trigger=function(n){var i=[].slice.call(arguments,1),r=t[n]||[];for(var o=0,u;u=r[o];++o){if(!u.busy){u.busy=1;u.apply(e,u.typed?[n].concat(i):i);if(r[o]!==u){o--}u.busy=0}}if(t.all&&n!="all"){e.trigger.apply(e,["all",n].concat(i))}return e};return e};n.mixin=function(){var e={};return function(t,n){if(!n)return e[t];e[t]=n}}();(function(e,t,n){if(!n)return;var i=n.location,r=e.observable(),o=false,u;function f(){return i.href.split("#")[1]||""}function a(e){return e.split("/")}function s(e){if(e.type)e=f();if(e!=u){r.trigger.apply(null,["H"].concat(a(e)));u=e}}var c=e.route=function(e){if(e[0]){i.hash=e;s(e)}else{r.on("H",e)}};c.exec=function(e){e.apply(null,a(f()))};c.parser=function(e){a=e};c.stop=function(){if(o){if(n.removeEventListener)n.removeEventListener(t,s,false);else n.detachEvent("on"+t,s);r.off("*");o=false}};c.start=function(){if(!o){if(n.addEventListener)n.addEventListener(t,s,false);else n.attachEvent("on"+t,s);o=true}};c.start()})(n,"hashchange",e);var g=function(e){var t,i,r,o=/[{}]/g;return function(u){var f=n.settings.brackets||e;if(t!==f){t=f;r=f.split(" ");i=r.map(function(e){return e.replace(/(?=.)/g,"\\")})}return u instanceof RegExp?f===e?u:new RegExp(u.source.replace(o,function(e){return i[~~(e==="}")]}),u.global?"g":""):r[u]}}("{ }");var m=function(){var t={},n='"in d?d:'+(e?"window).":"global)."),i=/(['"\/])(?:[^\\]*?|\\.|.)*?\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function\s*\()|([A-Za-z_$]\w*)/g;return function(e,n){return e&&(t[e]||(t[e]=r(e)))(n)};function r(e,t){if(e.indexOf(g(0))<0){e=e.replace(/\n|\r\n?/g,"\n");return function(){return e}}e=e.replace(g(/\\{/g),"").replace(g(/\\}/g),"");t=f(e,a(e,g(/{/),g(/}/)));e=t.length===2&&!t[0]?o(t[1]):"["+t.map(function(e,t){return t%2?o(e,true):'"'+e.replace(/\n|\r\n?/g,"\\n").replace(/"/g,'\\"')+'"'}).join(",")+'].join("")';return new Function("d","return "+e.replace(/\uFFF0/g,g(0)).replace(/\uFFF1/g,g(1))+";")}function o(e,t){e=e.replace(/\n|\r\n?/g," ").replace(g(/^[{ ]+|[ }]+$|\/\*.+?\*\//g),"");return/^\s*[\w- "']+ *:/.test(e)?"["+a(e,/["' ]*[\w- ]+["' ]*:/,/,(?=["' ]*[\w- ]+["' ]*:)|}|$/).map(function(e){return e.replace(/^[ "']*(.+?)[ "']*: *(.+?),? *$/,function(e,t,n){return n.replace(/[^&|=!><]+/g,u)+'?"'+t+'":"",'})}).join("")+'].join(" ").trim()':u(e,t)}function u(e,t){e=e.trim();return!e?"":"(function(v){try{v="+e.replace(i,function(e,t,i){return i?'(("'+i+n+i+")":e})+"}catch(e){}return "+(t===true?'!v&&v!==0?"":v':"v")+"}).call(d)"}function f(e,t){var n=[];t.map(function(t,i){i=e.indexOf(t);n.push(e.slice(0,i),t);e=e.slice(i+t.length)});if(e)n.push(e);return n}function a(e,t,n){var i,r=0,o=[],u=new RegExp("("+t.source+")|("+n.source+")","g");e.replace(u,function(t,n,u,f){if(!r&&n)i=f;r+=n?1:-1;if(!r&&u!=null)o.push(e.slice(i,f+u.length))});return o}}();var v=function(e){var t={tr:"tbody",th:"tr",td:"tr",tbody:"table",col:"colgroup"},n="div";e=e&&e<10;function i(i){var o=i&&i.match(/^\s*<([-\w]+)/),u=o&&o[1].toLowerCase(),f=t[u]||n,a=R(f);a.stub=true;if(e&&u&&(o=u.match(c)))r(a,i,u,!!o[1]);else a.innerHTML=i;return a}function r(e,t,i,r){var o=R(n),u=r?"select>":"table>",f;o.innerHTML="<"+u+t+"</"+u;f=o.getElementsByTagName(i)[0];if(f)e.appendChild(f)}return i}(p);function h(e){var t=g(0),n=e.trim().slice(t.length).match(/^\s*(\S+?)\s*(?:,\s*(\S+))?\s+in\s+(.+)$/);return n?{key:n[1],pos:n[2],val:t+n[3]}:{val:e}}function y(e,t,n){var i={};i[e.key]=t;if(e.pos)i[e.pos]=n;return i}function b(e,t,n){A(e,"each");var i=S(e),r=e.outerHTML,o=!!U[i],u=U[i]||{tmpl:r},f=e.parentNode,a=document.createComment("riot placeholder"),s=[],l=O(e),p;f.insertBefore(a,e);n=h(n);t.one("premount",function(){if(f.stub)f=t.root;e.parentNode.removeChild(e)}).on("update",function(){var r=m(n.val,t);if(!d(r)){p=r?JSON.stringify(r):"";r=!r?[]:Object.keys(r).map(function(e){return y(n,e,r[e])})}var g=document.createDocumentFragment(),v=s.length,h=r.length;while(v>h){s[--v].unmount();s.splice(v,1)}for(v=0;v<h;++v){var b=!p&&!!n.key?y(n,r[v],v):r[v];if(!s[v]){(s[v]=new _(u,{parent:t,isLoop:true,hasImpl:o,root:c.test(i)?f:e.cloneNode(),item:b},e.innerHTML)).mount();g.appendChild(s[v].root)}else s[v].update(b);s[v]._item=b}f.insertBefore(g,a);if(l)t.tags[i]=s}).one("updated",function(){var e=Object.keys(t);F(f,function(n){if(n.nodeType==1&&!n.isLoop&&!n._looped){n._visited=false;n._looped=true;z(n,t,e)}})})}function w(e,t,n){F(e,function(e){if(e.nodeType==1){e.isLoop=e.isLoop||(e.parentNode&&e.parentNode.isLoop||e.getAttribute("each"))?1:0;var i=O(e);if(i&&!e.isLoop){n.push(E(i,e,t))}if(!e.isLoop)z(e,t,[])}})}function L(e,t,n){function i(e,t,i){if(t.indexOf(g(0))>=0){var r={dom:e,expr:t};n.push(k(r,i))}}F(e,function(e){var n=e.nodeType;if(n==3&&e.parentNode.tagName!="STYLE")i(e,e.nodeValue);if(n!=1)return;var r=e.getAttribute("each");if(r){b(e,t,r);return false}C(e.attributes,function(t){var n=t.name,r=n.split("__")[1];i(e,t.value,{attr:r||n,bool:r});if(r){A(e,n);return false}});if(O(e))return false})}function _(e,r,o){var s=n.observable(this),c=q(r.opts)||{},p=v(e.tmpl),h=r.parent,y=r.isLoop,b=r.hasImpl,_=j(r.item),N=[],x=[],A=r.root,O=e.fn,E=A.tagName.toLowerCase(),S={},F=[];if(O&&A._tag){A._tag.unmount(true)}this.isMounted=false;A.isLoop=y;A._tag=this;this._id=i++;k(this,{parent:h,root:A,opts:c,tags:{}},_);C(A.attributes,function(e){var t=e.value;if(g(/{.*}/).test(t))S[e.name]=t});if(p.innerHTML&&!/^(select|optgroup|table|tbody|tr|col(?:group)?)$/.test(E))p.innerHTML=D(p.innerHTML,o);function R(){var e=b&&y?s:h||s;C(A.attributes,function(t){c[t.name]=m(t.value,e)});C(Object.keys(S),function(t){c[t]=m(S[t],e)})}function I(e){for(var t in _){if(typeof s[t]!==a)s[t]=e[t]}}function V(){if(!s.parent||!y)return;C(Object.keys(s.parent),function(e){var t=!~l.indexOf(e)&&~F.indexOf(e);if(typeof s[e]===a||t){if(!t)F.push(e);s[e]=s.parent[e]}})}this.update=function(e){e=j(e);V();if(e&&typeof _===f){I(e);_=e}k(s,e);R();s.trigger("update",e);T(N,s);s.trigger("updated")};this.mixin=function(){C(arguments,function(e){e=typeof e===u?n.mixin(e):e;C(Object.keys(e),function(t){if(t!="init")s[t]=M(e[t])?e[t].bind(s):e[t]});if(e.init)e.init.bind(s)()})};this.mount=function(){R();if(O)O.call(s,c);L(p,s,N);z(true);if(e.attrs||b){$(e.attrs,function(e,t){A.setAttribute(e,t)});L(s.root,s,N)}if(!s.parent||y)s.update(_);s.trigger("premount");if(y&&!b){s.root=A=p.firstChild}else{while(p.firstChild)A.appendChild(p.firstChild);if(A.stub)s.root=A=h.root}if(!s.parent||s.parent.isMounted){s.isMounted=true;s.trigger("mount")}else s.parent.one("mount",function(){if(!B(s.root)){s.parent.isMounted=s.isMounted=true;s.trigger("mount")}})};this.unmount=function(e){var n=A,i=n.parentNode,r;if(i){if(h){r=H(h);if(d(r.tags[E]))C(r.tags[E],function(e,t){if(e._id==s._id)r.tags[E].splice(t,1)});else r.tags[E]=t}else while(n.firstChild)n.removeChild(n.firstChild);if(!e)i.removeChild(n);else i.removeAttribute("riot-tag")}s.trigger("unmount");z();s.off("*");A._tag=null};function z(e){C(x,function(t){t[e?"mount":"unmount"]()});if(h){var t=e?"on":"off";if(y)h[t]("unmount",s.unmount);else h[t]("update",s.update)[t]("unmount",s.unmount)}}w(p,this,x)}function N(t,n,i,r){i[t]=function(t){var o=r._item,u=r.parent,f;if(!o)while(u&&!o){o=u._item;u=u.parent}t=t||e.event;try{t.currentTarget=i;if(!t.target)t.target=t.srcElement;if(!t.which)t.which=t.charCode||t.keyCode}catch(a){}t.item=o;if(n.call(r,t)!==true&&!/radio|check/.test(i.type)){if(t.preventDefault)t.preventDefault();t.returnValue=false}if(!t.preventUpdate){f=o?H(u):r;f.update()}}}function x(e,t,n){if(e){e.insertBefore(n,t);e.removeChild(t)}}function T(e,t){C(e,function(e,n){var i=e.dom,u=e.attr,a=m(e.expr,t),s=e.dom.parentNode;if(e.bool)a=a?u:false;else if(a==null)a="";if(s&&s.tagName=="TEXTAREA")a=(""+a).replace(/riot-/g,"");if(e.value===a)return;e.value=a;if(!u){i.nodeValue=""+a;return}A(i,u);if(M(a)){N(u,a,i,t)}else if(u=="if"){var c=e.stub,l=function(){x(c.parentNode,c,i)},p=function(){x(i.parentNode,i,c)};if(a){if(c){l();i.inStub=false;if(!B(i)){F(i,function(e){if(e._tag&&!e._tag.isMounted)e._tag.isMounted=!!e._tag.trigger("mount")})}}}else{c=e.stub=c||document.createTextNode("");if(i.parentNode)p();else(t.parent||t).one("updated",p);i.inStub=true}}else if(/^(show|hide)$/.test(u)){if(u=="hide")a=!a;i.style.display=a?"":"none"}else if(u=="value"){i.value=a}else if(J(u,r)&&u!=o){if(a)i.setAttribute(u.slice(r.length),a)}else{if(e.bool){i[u]=a;if(!a)return}if(typeof a!==f)i.setAttribute(u,a)}})}function C(e,t){for(var n=0,i=(e||[]).length,r;n<i;n++){r=e[n];if(r!=null&&t(r,n)===false)n--}return e}function M(e){return typeof e===s||false}function A(e,t){e.removeAttribute(t)}function O(e){return e.tagName&&U[e.getAttribute(o)||e.tagName.toLowerCase()]}function E(e,t,n){var i=new _(e,{root:t,parent:n},t.innerHTML),r=S(t),o=H(n),u;i.parent=o;u=o.tags[r];if(u){if(!d(u))o.tags[r]=[u];if(!~o.tags[r].indexOf(i))o.tags[r].push(i)}else{o.tags[r]=i}t.innerHTML="";return i}function H(e){var t=e;while(!O(t.root)){if(!t.parent)break;t=t.parent}return t}function S(e){var t=O(e),n=e.getAttribute("name"),i=n&&n.indexOf(g(0))<0?n:t?t.name:e.tagName.toLowerCase();return i}function k(e){var t,n=arguments;for(var i=1;i<n.length;++i){if(t=n[i]){for(var r in t){e[r]=t[r]}}}return e}function j(e){if(!(e instanceof _)&&!(e&&typeof e.trigger==s))return e;var t={};for(var n in e){if(!~l.indexOf(n))t[n]=e[n]}return t}function F(e,t){if(e){if(t(e)===false)return;else{e=e.firstChild;while(e){F(e,t);e=e.nextSibling}}}}function $(e,t){var n,i=/([-\w]+) ?= ?(?:"([^"]*)|'([^']*)|({[^}]*}))/g;while(n=i.exec(e)){t(n[1].toLowerCase(),n[2]||n[3]||n[4])}}function B(e){while(e){if(e.inStub)return true;e=e.parentNode}return false}function R(e){return document.createElement(e)}function D(e,t){return e.replace(/<(yield)\/?>(<\/\1>)?/gi,t||"")}function I(e,t){return(t||document).querySelectorAll(e)}function V(e,t){return(t||document).querySelector(e)}function q(e){function t(){}t.prototype=e;return new t}function z(e,t,n){if(e._visited)return;var i,r=e.getAttribute("id")||e.getAttribute("name");if(r){if(n.indexOf(r)<0){i=t[r];if(!i)t[r]=e;else if(d(i))i.push(e);else t[r]=[i,e]}e._visited=true}}function J(e,t){return e.slice(0,t.length)===t}var P=[],U={},W;function X(e){if(n.render)return;if(!W){W=R("style");W.setAttribute("type","text/css")}var t=document.head||document.getElementsByTagName("head")[0];if(W.styleSheet)W.styleSheet.cssText+=e;else W.innerHTML+=e;if(!W._rendered)if(W.styleSheet){document.body.appendChild(W)}else{var i=V("style[type=riot]");if(i){i.parentNode.insertBefore(W,i);i.parentNode.removeChild(i)}else t.appendChild(W)}W._rendered=true}function Y(e,t,n){var i=U[t],r=e._innerHTML=e._innerHTML||e.innerHTML;e.innerHTML="";if(i&&e)i=new _(i,{root:e,opts:n},r);if(i&&i.mount){i.mount();P.push(i);return i.on("unmount",function(){P.splice(P.indexOf(i),1)})}}n.tag=function(e,t,n,i,r){if(M(i)){r=i;if(/^[\w\-]+\s?=/.test(n)){i=n;n=""}else i=""}if(n){if(M(n))r=n;else X(n)}U[e]={name:e,tmpl:t,attrs:i,fn:r};return e};n.mount=function(e,t,n){var i,r,a=[];function s(e){var t="";C(e,function(e){t+=", *["+o+'="'+e.trim()+'"]'});return t}function c(){var e=Object.keys(U);return e+s(e)}function l(e){var i;if(e.tagName){if(t&&(!(i=e.getAttribute(o))||i!=t))e.setAttribute(o,t);var r=Y(e,t||e.getAttribute(o)||e.tagName.toLowerCase(),n);if(r)a.push(r)}else if(e.length){C(e,l)}}if(typeof t===f){n=t;t=0}if(typeof e===u){if(e==="*")e=r=c();else e+=s(e.split(","));i=I(e)}else i=e;if(t==="*"){t=r||c();if(i.tagName)i=I(t,i);else{var p=[];C(i,function(e){p.push(I(t,e))});i=p}t=0}if(i.tagName)l(i);else C(i,l);return a};n.update=function(){return C(P,function(e){e.update()})};n.mountTo=n.mount;n.util={brackets:g,tmpl:m};if(typeof exports===f)module.exports=n;else if(typeof define==="function"&&define.amd)define(function(){return e.riot=n});else e.riot=n})(typeof window!="undefined"?window:void 0); |
LGTM