Created
October 10, 2012 22:56
-
-
Save zoobestik/3869070 to your computer and use it in GitHub Desktop.
Yate templates rendering with nodejs
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
module "index" | |
match / { | |
html('<!doctype html>') | |
<html class="no-js" lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | |
<title></title> | |
<meta name="description" content="" /> | |
<meta name="viewport" content="width=device-width" /> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> | |
} |
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
/* | |
* author: kb.chernenko@gmail.com | |
* description: yate templates rendering with nodejs | |
* | |
* yate: https://github.com/pasaran/yate | |
* algorithm based: https://github.com/mctep/yate-express | |
*/ | |
var fs = require('fs'), | |
yate = require('yate'); | |
module.exports = YateRuntime = function(opts) { | |
opts = opts || {} | |
var runtimePath = opts.runtimePath || './node_modules/yate/lib/runtime.js'; | |
this.runtime = new Function(fs.readFileSync(runtimePath)+';return yr;')(); | |
}; | |
YateRuntime.prototype.addModule = function(path) { | |
var js = yate.compile(path).js; | |
new Function('yr', js)(this.runtime); | |
return this; | |
} | |
YateRuntime.prototype.apply = function() { | |
return this.runtime.run.apply(this.runtime, arguments); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Хм.. Я как-то пробовал сделать один экземпляр рантайма, на все шаблоны, но он ругался на, то, что в нем уже создан модуль 'main'. Поэтому пришлось рантайм делать на каждый шаблон отдельно.
В твоем случае addModule каждый раз будет вызывать yr.register('main', M); Не будет ли той-же проблемы? Или я что-то путаю?