forked from effkay/brunch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed workaround by updating fusion and adding eco master
- Loading branch information
Nikolaus Graf
committed
Feb 16, 2011
1 parent
289a759
commit e3ba84c
Showing
10 changed files
with
293 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require("coffee-script"); | ||
module.exports = require("./eco/compiler"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
npm/template/base/config/fusion/vendor/eco/eco/compiler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\x22/g, '"');\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
75
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.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
npm/template/base/config/fusion/vendor/eco/eco/scanner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters