Skip to content

Commit

Permalink
removed workaround by updating fusion and adding eco master
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaus Graf committed Feb 16, 2011
1 parent 289a759 commit e3ba84c
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 6 deletions.
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"yaml": "0.1.1",
"coffee-script": ">= 1.0.0",
"underscore": ">= 1.1.4",
"fusion": ">= 0.0.5",
"fusion": ">= 0.0.6",
"glob": ">= 1.1.0",
"eco": ">= 1.0.1",
"nomnom": ">=0.1.2",
Expand Down
9 changes: 5 additions & 4 deletions npm/template/base/config/fusion/hook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var eco = require('eco');
exports.compileTemplate = function(content) {
return eco.compile(content);
};
var eco = require('./vendor/eco/eco');
var fusion = require('fusion');
exports.createTemplateObject = function(content, source, directoryPrefix) {
return eco.compile(content, { identifier: fusion.templateNamespace(source, directoryPrefix)});
};
2 changes: 2 additions & 0 deletions npm/template/base/config/fusion/vendor/eco/eco.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("coffee-script");
module.exports = require("./eco/compiler");
18 changes: 18 additions & 0 deletions npm/template/base/config/fusion/vendor/eco/eco/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
var eco, fs;
fs = "fs";
eco = require("eco");
exports.run = function() {
var source, stdin;
source = "";
stdin = process.openStdin();
stdin.on("data", function(buffer) {
if (buffer) {
return source += buffer.toString();
}
});
return stdin.on("end", function() {
return console.log(eco.compile(source));
});
};
}).call(this);
35 changes: 35 additions & 0 deletions npm/template/base/config/fusion/vendor/eco/eco/compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function() {
var CoffeeScript, compile, eco, indent, preprocess;
CoffeeScript = require("coffee-script");
preprocess = require("./preprocessor").preprocess;
indent = require("./util").indent;
module.exports = eco = function(source) {
var module;
(new Function("module", compile(source)))(module = {});
return module.exports;
};
eco.preprocess = preprocess;
eco.compile = compile = function(source, options) {
var identifier, script, _ref;
identifier = (_ref = options != null ? options.identifier : void 0) != null ? _ref : "module.exports";
if (!identifier.match(/\./)) {
identifier = "var " + identifier;
}
script = CoffeeScript.compile(preprocess(source), {
noWrap: true
});
return "" + identifier + " = function(__obj) {\n if (!__obj) __obj = {};\n var __out = [], __capture = function(callback) {\n var out = __out, result;\n __out = [];\n callback.call(this);\n result = __out.join('');\n __out = out;\n return __safe(result);\n }, __sanitize = function(value) {\n if (value && value.ecoSafe) {\n return value;\n } else if (typeof value !== 'undefined' && value != null) {\n return __escape(value);\n } else {\n return '';\n }\n }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;\n __safe = __obj.safe = function(value) {\n if (value && value.ecoSafe) {\n return value;\n } else {\n if (!(typeof value !== 'undefined' && value != null)) value = '';\n var result = new String(value);\n result.ecoSafe = true;\n return result;\n }\n };\n if (!__escape) {\n __escape = __obj.escape = function(value) {\n return ('' + value)\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\x22/g, '&quot;');\n };\n }\n (function() {\n" + (indent(script, 4)) + "\n }).call(__obj);\n __obj.safe = __objSafe, __obj.escape = __escape;\n return __out.join('');\n};";
};
eco.render = function(source, data) {
return (eco(source))(data);
};
if (require.extensions) {
require.extensions[".eco"] = function(module, filename) {
var source;
source = require("fs").readFileSync(filename, "utf-8");
return module._compile(compile(source), filename);
};
} else if (require.registerExtension) {
require.registerExtension(".eco", compile);
}
}).call(this);
75 changes: 75 additions & 0 deletions npm/template/base/config/fusion/vendor/eco/eco/preprocessor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions npm/template/base/config/fusion/vendor/eco/eco/scanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
(function() {
var Scanner, StringScanner, trim;
StringScanner = require("strscan").StringScanner;
trim = require("./util").trim;
module.exports = Scanner = (function() {
Scanner.modePatterns = {
data: /(.*?)(<%%|<%(([=-])?)|\n|$)/,
code: /(.*?)(((:|(->|=>))\s*)?%>|\n|$)/
};
Scanner.dedentablePattern = /^(end|when|else|catch|finally)(?:\W|$)/;
Scanner.scan = function(source) {
var scanner, tokens;
tokens = [];
scanner = new Scanner(source);
while (!scanner.done) {
scanner.scan(function(token) {
return tokens.push(token);
});
}
return tokens;
};
function Scanner(source) {
this.source = source.replace(/\r\n?/g, "\n");
this.scanner = new StringScanner(this.source);
this.mode = "data";
this.buffer = "";
this.lineNo = 1;
this.done = false;
}
Scanner.prototype.scan = function(callback) {
if (this.done) {
return callback();
} else if (this.scanner.hasTerminated()) {
this.done = true;
switch (this.mode) {
case "data":
return callback(["printString", this.flush()]);
case "code":
return callback(["fail", "unexpected end of template"]);
}
} else {
this.advance();
switch (this.mode) {
case "data":
return this.scanData(callback);
case "code":
return this.scanCode(callback);
}
}
};
Scanner.prototype.advance = function() {
this.scanner.scanUntil(Scanner.modePatterns[this.mode]);
this.buffer += this.scanner.getCapture(0);
this.tail = this.scanner.getCapture(1);
this.directive = this.scanner.getCapture(3);
return this.arrow = this.scanner.getCapture(4);
};
Scanner.prototype.scanData = function(callback) {
if (this.tail === "<%%") {
this.buffer += "<%";
return this.scan(callback);
} else if (this.tail === "\n") {
this.buffer += this.tail;
this.lineNo++;
return this.scan(callback);
} else if (this.tail) {
this.mode = "code";
callback(["printString", this.flush()]);
return callback([
"beginCode", {
print: this.directive != null,
safe: this.directive === "-"
}
]);
}
};
Scanner.prototype.scanCode = function(callback) {
var code;
if (this.tail === "\n") {
return callback(["fail", "unexpected newline in code block"]);
} else if (this.tail) {
this.mode = "data";
code = trim(this.flush());
if (this.arrow) {
code += " " + this.arrow;
}
if (this.isDedentable(code)) {
callback(["dedent"]);
}
callback(["recordCode", code]);
if (this.directive) {
return callback(["indent", this.arrow]);
}
}
};
Scanner.prototype.flush = function() {
var buffer;
buffer = this.buffer;
this.buffer = "";
return buffer;
};
Scanner.prototype.isDedentable = function(code) {
return code.match(Scanner.dedentablePattern);
};
return Scanner;
})();
}).call(this);
48 changes: 48 additions & 0 deletions npm/template/base/config/fusion/vendor/eco/eco/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion npm/template/base/src/app/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ window.app = {}
app.controllers = {}
app.models = {}
app.views = {}
window.module = {} # dirty workaround until eco's namespace is fixed

# app bootstrapping on document ready
$(document).ready ->
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ and run tests via

* more & improved documentation
* tests
* come up with a require solution
* move concatination.js to app.js
* directly call fusion, stylus and coffeescript instead of spawning child process

### other stuff
Expand Down

0 comments on commit e3ba84c

Please sign in to comment.