Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,370 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//require('underscore') | ||
|
||
/*require('my').load('lib/Tabish/type', function(type){ | ||
console.log(type.Class) | ||
})*/ | ||
|
||
|
||
/* | ||
require('my').load('lib/Tabish/iterator', function(m){ | ||
console.log(m.Iterator) | ||
console.log(m.StopIteration) | ||
var it = m.Iterator({a:1, b:2}) | ||
try { | ||
while (true) { | ||
console.log(it.next()) | ||
} | ||
} catch(e) {} | ||
}) | ||
require('my').load('lib/Tabish/matcher', function(m){ | ||
console.log(m.RegExpMatcherIterator) | ||
var it = m.RegExpMatcherIterator(/l/g, 'Hello world!') | ||
try { | ||
while (true) { | ||
console.log(it.next()) | ||
} | ||
} catch(e) {} | ||
}) | ||
*/ | ||
|
||
|
||
/*require('my').load('lib/Tabish/tabish', function(m){ | ||
console.log(m.parse('Hello!\n Hello 2!')) | ||
})*/ | ||
|
||
require('my').global.console = console | ||
|
||
require('my').load('jedi', function(jedi){ | ||
|
||
var source = 'html' | ||
var runtime = new jedi.JSRuntime() | ||
var template = runtime.eval(jedi.compileToJS(source)) | ||
template.echo = function(s){ | ||
console.log(s) | ||
} | ||
template() | ||
}) | ||
|
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,112 @@ | ||
var express = require('express') | ||
|
||
var app = express(), fs = require('fs') | ||
|
||
// Configuration | ||
app.configure(function(){ | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'jedi'); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(app.router); | ||
app.use(express.static(__dirname + '/public')); | ||
}); | ||
|
||
app.configure('development', function(){ | ||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | ||
}); | ||
|
||
app.configure('production', function(){ | ||
app.use(express.errorHandler()); | ||
}); | ||
|
||
require('my').load('jedi', function(jedi){ | ||
app.engine('jedi', function __express(path, options, callback) { | ||
//console.log(arguments) | ||
console.log(Object.keys(options)) | ||
fs.readFile(path, 'utf-8', function(err, data) { | ||
if (err) callback(err) | ||
else { | ||
try { | ||
var runtime = jedi.JSRuntime() | ||
var source = data | ||
var jsSrc = jedi.compileToJS(source) | ||
var template = runtime.eval(jsSrc) | ||
var result = '' | ||
template.echo = function(s){ | ||
result += s | ||
} | ||
template(options.model) | ||
callback(null, result) | ||
} catch(e) { | ||
e.message += jsSrc.replace(/&/g, '&').replace(/</g, '<') | ||
callback(e, jsSrc) | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
// Routes | ||
|
||
var http = require('http') | ||
|
||
|
||
app.get('/u/:uid/', function(req, res){ | ||
var graphRes = http.get('http://graph.baixing.com' + req.url.slice(2) + 'ad', function(graphRes){ | ||
graphRes.setEncoding('utf-8') | ||
var result = '' | ||
graphRes.on('data', function(data){ | ||
result += data | ||
}) | ||
graphRes.on('end', function(data){ | ||
var m = JSON.parse(result) | ||
console.log(m) | ||
ok(res, 'ad', m) | ||
}) | ||
}) | ||
var graphReq = http.get('http://graph.baixing.com' + req.url.slice(2, -1), function(graphRes){ | ||
graphRes.setEncoding('utf-8') | ||
var result = '' | ||
graphRes.on('data', function(data){ | ||
result += data | ||
}) | ||
graphRes.on('end', function(data){ | ||
var m = JSON.parse(result) | ||
console.log(m) | ||
ok(res, 'user', m) | ||
res.render('test', { | ||
model: m | ||
}) | ||
}) | ||
}) | ||
graphReq.on('error', function(e){ | ||
console.error(e) | ||
}) | ||
}) | ||
|
||
app.get('/*', function(req, res){ | ||
console.log('http://graph.baixing.com' + req.url) | ||
var graphReq = http.get('http://graph.baixing.com' + req.url, function(graphRes){ | ||
graphRes.setEncoding('utf-8') | ||
var result = '' | ||
graphRes.on('data', function(data){ | ||
result += data | ||
}) | ||
graphRes.on('end', function(data){ | ||
var m = JSON.parse(result) | ||
console.log(m) | ||
res.render('test', { | ||
model: m | ||
}) | ||
}) | ||
}) | ||
graphReq.on('error', function(e){ | ||
console.error(e) | ||
}) | ||
}); | ||
|
||
app.listen(3000, function(){}); | ||
|
||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,63 @@ | ||
var ometajs = require('ometajs'), | ||
//uglify = require('uglify-js'), | ||
utils = ometajs.utils, | ||
vm = require('vm'), | ||
//Module = require('module'), | ||
fail = ometajs.globals.fail; | ||
objectThatDelegatesTo = ometajs.globals.objectThatDelegatesTo; | ||
|
||
function compilationError(m, i) { | ||
throw objectThatDelegatesTo(fail, {errorPos: i}); | ||
}; | ||
|
||
function translationError(m, i) { | ||
throw fail; | ||
}; | ||
|
||
function wrapModule(code, options) { | ||
var buf = [ | ||
'var ometajs_ = require(\'', | ||
options.root || ometajs.root || 'ometajs', | ||
'\').globals;' | ||
]; | ||
|
||
Object.keys(ometajs.globals).forEach(function(key) { | ||
buf.push('var ', key, ' = ometajs_.', key, ';\n'); | ||
}); | ||
buf.push(code); | ||
|
||
return buf.join(''); | ||
}; | ||
|
||
function translateCode(code, options) { | ||
options || (options = {}); | ||
var tree = ometajs.BSOMetaJSParser.matchAll(code, "topLevel", undefined, | ||
compilationError); | ||
|
||
code = ometajs.BSOMetaJSTranslator.match(tree, "trans", undefined, | ||
translationError); | ||
|
||
//code = uglify.uglify.gen_code(uglify.parser.parse(code), { beautify: true }); | ||
|
||
if (options.noContext) return code; | ||
|
||
return wrapModule(code, options); | ||
}; | ||
exports.translateCode = translateCode; | ||
|
||
function evalCode(code, filename, options) { | ||
options || (options = {}); | ||
options.noContext = true; | ||
|
||
code = translateCode(code, options); | ||
return vm.runInNewContext('var exports = {};' + code + '\n;exports', | ||
utils.clone(ometajs.globals), | ||
filename || 'ometa'); | ||
}; | ||
exports.evalCode = evalCode; | ||
|
||
require.extensions['.ometajs'] = function(module, filename) { | ||
var code = translateCode(require('fs').readFileSync(filename).toString()); | ||
|
||
module._compile(code, filename); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.