Permalink
Browse files

no message

  • Loading branch information...
sburel committed Oct 30, 2014
1 parent 859d54a commit 0b17ef6be4290948012f9ebe99e60dc1b0f5407f
Showing with 144 additions and 255 deletions.
  1. +97 −206 bin/wkc
  2. +1 −0 documentation.md
  3. +2 −4 lib/client/webkool.js
  4. +0 −2 lib/less.js
  5. +0 −4 lib/mustache.js
  6. +0 −2 lib/sass.js
  7. +18 −36 lib/square.js
  8. +26 −1 sources/wkc.ts
View
303 bin/wkc

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1 @@
#webkool
View
@@ -669,11 +669,9 @@ Application.prototype = Object.create(Object.prototype, {
},
reportError: { value:
function(handler, error) {
var message;
var message = error.toString();
if (error.stack)
message = error.stack.toString();
else
message = error.toString();
message += '\n' + error.stack.toString();
while (handler.parent)
handler = handler.parent;
View
@@ -1,9 +1,7 @@
var Less;
(function (Less) {
'use strict';
var less = require('less');
exports.compile = function compile(buffer, stream) {
var m = less.render(buffer, function (e, css) {
if (e)
View
@@ -1,9 +1,7 @@
var Mustache;
(function (Mustache) {
'use strict';
var hogan = require('hogan.js');
var Parser = (function () {
function Parser(buffer, p) {
this.path = '';
@@ -14,7 +12,6 @@ var Mustache;
Parser.prototype.parse = function (buffer) {
this.compiled = hogan.compile(buffer, { asString: true });
};
Parser.prototype.print = function (stream) {
stream.write('function (context, model) {');
stream.write("var result = '';");
@@ -25,7 +22,6 @@ var Mustache;
};
return Parser;
})();
exports.parse = function parse(buffer, path) {
return new Parser(buffer, path);
};
View
@@ -1,9 +1,7 @@
var Sass;
(function (Sass) {
'use strict';
var sass = require('node-sass');
exports.compile = function compile(buffer, stream) {
stream.write(sass.renderSync({
data: buffer,
View
@@ -1,7 +1,6 @@
var Square;
(function (Square) {
'use strict';
var Block = (function () {
function Block(container) {
this.container = container;
@@ -13,7 +12,6 @@ var Square;
contents[i].prepare(buffer);
}
};
Block.prototype.print = function (stream, carriageReturn) {
var contents = this.contents, c = contents.length, i;
if (c > 0) {
@@ -26,7 +24,6 @@ var Square;
};
return Block;
})();
var Text = (function () {
function Text(container, offset) {
this.start = 0;
@@ -38,7 +35,6 @@ var Square;
Text.prototype.prepare = function (buffer) {
this.buffer = buffer.toString(null, this.start, this.stop);
};
Text.prototype.print = function (stream, carriageReturn) {
var text = this.buffer;
text = text.replace('\n', ' ');
@@ -49,7 +45,6 @@ var Square;
};
return Text;
})();
var Variable = (function () {
function Variable(container, start, stop, path, line) {
this.start = 0;
@@ -69,7 +64,6 @@ var Square;
contents[i].prepare(buffer);
}
};
Variable.prototype.print = function (stream, carriageReturn) {
var blocks = this.contents;
switch (blocks.length) {
@@ -97,7 +91,6 @@ var Square;
case 3:
blocks[0].print(stream, carriageReturn);
carriageReturn(stream, 0);
stream.write(this.script);
stream.write('.forEach(function ($, $i, $$) {');
carriageReturn(stream, 1);
@@ -106,15 +99,13 @@ var Square;
blocks[1].print(stream, carriageReturn);
carriageReturn(stream, -1);
stream.write('});');
carriageReturn(stream, 0);
blocks[2].print(stream, carriageReturn);
break;
}
};
return Variable;
})();
var Parser = (function () {
function Parser(buffer, path) {
this.line = 0;
@@ -151,27 +142,30 @@ var Square;
if (c === 123) {
offset += 1;
start = offset;
for (; ;) {
for (;;) {
c = buffer[offset];
if (c === 10) {
this.line += 1;
offset += 1;
} else if (c === 13) {
}
else if (c === 13) {
this.line += 1;
offset += 1;
c = buffer[offset];
if (c === 10)
offset += 1;
} else if ((c === 125) && ((buffer[offset + 1] === 35) || (buffer[offset + 1] === 91)))
}
else if ((c === 125) && ((buffer[offset + 1] === 35) || (buffer[offset + 1] === 91)))
break;
else
offset += 1;
}
stop = offset;
offset += 1;
c = buffer[offset];
} else {
for (; ;) {
}
else {
for (;;) {
c = buffer[offset];
if (((48 <= c) && (c <= 57)) || ((65 <= c) && (c <= 90)) || ((97 <= c) && (c <= 122)) || (c === 36) || (c === 95) || (c === 46))
offset += 1;
@@ -190,7 +184,8 @@ var Square;
}
offset += 1;
this.startText(offset);
} else if (c === 91) {
}
else if (c === 91) {
this.stopText(former);
if (start === stop)
this.reportError('missing id');
@@ -212,7 +207,8 @@ var Square;
this.popVariable();
offset += 1;
this.startText(offset);
} else if (c === 91) {
}
else if (c === 91) {
this.stopText(former);
this.popBlock();
this.pushBlock();
@@ -230,7 +226,8 @@ var Square;
former = offset + 9 + tail + 3;
else
this.reportError('missing ]]>');
} else if (head.indexOf('<!--') === 0) {
}
else if (head.indexOf('<!--') === 0) {
head = buffer.toString(null, offset + 4);
tail = head.indexOf('-->');
if (tail >= 0)
@@ -266,61 +263,53 @@ var Square;
}
this.stopText(offset);
};
Parser.prototype.popBlock = function () {
if (this.currentBlock.container) {
this.currentBlock = this.currentBlock.container;
} else
}
else
this.reportError('unexpected ]');
};
Parser.prototype.popVariable = function () {
if (this.currentBlock.container) {
this.currentBlock = this.currentBlock.container;
} else
}
else
this.reportError('unexpected ]]');
};
Parser.prototype.prepare = function (buffer) {
var contents = this.contents, c = contents.length, i;
for (i = 0; i < c; i += 1) {
contents[i].prepare(buffer);
}
};
Parser.prototype.pushBlock = function () {
var block = new Block(this.currentBlock);
this.currentBlock.contents.push(block);
this.currentBlock = block;
};
Parser.prototype.pushVariable = function (start, stop) {
var variable = new Variable(this.currentBlock, start, stop, this.path, this.line);
this.currentBlock.contents.push(variable);
this.currentBlock = variable;
};
Parser.prototype.reportError = function (message) {
console.log(this.path + ':' + this.line + ': error:' + message);
};
Parser.prototype.startText = function (offset) {
var text = new Text(this.currentBlock, offset);
this.currentBlock.contents.push(text);
this.currentText = text;
};
Parser.prototype.stopText = function (offset) {
if (this.currentText.start < offset)
this.currentText.stop = offset;
else
this.currentBlock.contents.pop();
this.currentText = null;
};
Parser.prototype.print = function (stream) {
var contents = this.contents, c = contents.length, i, tab = 0;
function carriageReturn(stream, delta) {
stream.write("\n");
tab += delta;
@@ -332,18 +321,14 @@ var Square;
}
carriageReturn(stream, 1);
stream.write('function (handler, scope) {');
//
carriageReturn(stream, 1);
stream.write('/*jshint -W085 */');
stream.write('with (scope) {');
carriageReturn(stream, 1);
stream.write("try {");
//
carriageReturn(stream, 1);
stream.write('var result = \'\';');
for (i = 0; i < c; i += 1) {
carriageReturn(stream, 0);
@@ -352,7 +337,6 @@ var Square;
carriageReturn(stream, 0);
stream.write('return result;');
carriageReturn(stream, -1);
//
stream.write('}');
stream.write('catch (e) {');
@@ -361,14 +345,12 @@ var Square;
stream.write('}');
stream.write('/*jshint +W085 */');
carriageReturn(stream, -1);
//
stream.write('},');
carriageReturn(stream, -1);
};
return Parser;
})();
exports.parse = function parse(buffer, path) {
return new Parser(buffer, path);
};
View
@@ -529,14 +529,27 @@ module Webkool {
class Router {
client;
server;
both;
constructor() {
this.both = {};
this.client = {};
this.server = {};
}
addHandler(side, method, url, file, line, column) {
var sideHandler = side == SideType.CLIENT ? this.client : this.server;
var sideHandler;
switch (side) {
case SideType.CLIENT:
sideHandler = this.client;
break;
case SideType.SERVER:
sideHandler = this.server;
break;
default:
sideHandler = this.both;
break
}
if (!sideHandler.hasOwnProperty(url))
sideHandler[url] = {};
if (sideHandler[url].hasOwnProperty(method)) {
@@ -547,6 +560,18 @@ module Webkool {
logger.warning(filename, line, column, 'handler "' + url + '"');
logger.warning(filenamePrev, info.line, info.column, 'previously defined here.');
}
if (sideHandler != this.both) {
if (!this.both.hasOwnProperty(url))
this.both[url] = {};
if (this.both[url].hasOwnProperty(method)) {
var info = this.both[url][method];
var filename = pr.resolveCheck(file, options.includes);
var filenamePrev = pr.resolveCheck(info.file, options.includes);
logger.warning(filename, line, column, 'handler "' + url + '"');
logger.warning(filenamePrev, info.line, info.column, 'previously defined here.');
}
}
sideHandler[url][method] = {
file: file,
line: line,

0 comments on commit 0b17ef6

Please sign in to comment.