Skip to content

Commit

Permalink
initial replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
isstaif committed May 30, 2012
1 parent b2ab9f0 commit 17ff66a
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions lib/express-expose.js
Expand Up @@ -48,8 +48,7 @@ exports.name = 'javascript';
*/

res.expose =
HTTPServer.prototype.expose =
HTTPSServer.prototype.expose = function(obj, namespace, name){
express.application.expose = function(obj, namespace, name){
var app = this.app || this;

app._exposed = app._exposed || {};
Expand All @@ -67,6 +66,7 @@ HTTPSServer.prototype.expose = function(obj, namespace, name){
if (!app._exposed[name]) {
var helpers = {};
app._exposed[name] = true;
/*
helpers[name] = function(req, res){
var appjs = app.exposed(name)
, resjs = res.exposed(name)
Expand All @@ -80,6 +80,21 @@ HTTPSServer.prototype.expose = function(obj, namespace, name){
return js;
};
app.dynamicHelpers(helpers);
*/
app.locals.use(function(req, res) {
var appjs = app.exposed(name)
, resjs = res.exposed(name)
, js = '';

if (appjs || resjs) {
js += '// app: \n' + appjs;
js += '// res: \n' + resjs;
}

return js;
res.locals.helpers[name] = js;
});

}

// buffer string
Expand Down Expand Up @@ -115,8 +130,7 @@ HTTPSServer.prototype.expose = function(obj, namespace, name){
*/

res.exposeRequire =
HTTPServer.prototype.exposeRequire =
HTTPSServer.prototype.exposeRequire = function(){
express.application.exposeRequire = function(){
if (this._require) return this;
this._require = true;
var js = fs.readFileSync(__dirname + '/require.js', 'ascii');
Expand All @@ -137,8 +151,7 @@ HTTPSServer.prototype.exposeRequire = function(){
*/

res.exposeModule =
HTTPServer.prototype.exposeModule =
HTTPSServer.prototype.exposeModule = function(path, namespace, name){
express.application.exposeModule = function(path, namespace, name){
var path = require.resolve(path)
, js = fs.readFileSync(path, 'utf8')
, namespace = namespace || basename(path, extname(path));
Expand All @@ -164,10 +177,8 @@ HTTPSServer.prototype.exposeModule = function(path, namespace, name){
* @return {String}
* @api private
*/

res.exposed =
HTTPServer.prototype.exposed =
HTTPSServer.prototype.exposed = function(name){
express.application.exposed = function(name){
name = name || exports.name;
this.js = this.js || {};
return this.js[name]
Expand Down Expand Up @@ -211,7 +222,7 @@ function renderNamespace(str){
var parts = []
, split = str.split('.')
, len = split.length;

return str.split('.').map(function(part, i){
parts.push(part);
part = parts.join('.');
Expand Down Expand Up @@ -257,4 +268,5 @@ function string(obj) {
} else {
return JSON.stringify(obj);
}
}
}

0 comments on commit 17ff66a

Please sign in to comment.