Skip to content

Commit

Permalink
Started implementing plugins support (currently not assync).
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrofranceschi committed Dec 13, 2010
1 parent e4054d1 commit 1812ff9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
29 changes: 27 additions & 2 deletions blogode.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
var express = require("express")
var sys = require("sys");
var fs = require("fs");
var app = express.createServer();
var faye = require('faye');

var posts = require('./lib/posts');
var users = require('./lib/users');
var comments = require('./lib/comments');
var config = require('./lib/config');

var app = express.createServer();

var blogConfig;
config.getAllBlogConfigKeyValues(function(value) {
blogConfig = value;
});


app.configure(function() {
app.use(express.logger());
app.use(express.bodyDecoder());
Expand All @@ -26,8 +27,20 @@ app.configure(function() {
app.set('view options', {
layout: 'layout'
});
loadPlugins();
});

var loadedPlugins = new Array();
function loadPlugins() {
fs.readdir('./plugins/', function(err, files) {
for (var i=0; i < files.length; i++) {
var plugin = require('./plugins/' + files[i] + '/plugin.js');
var pluginInfo = plugin.initialize();
loadedPlugins[pluginInfo[0].toString()] = plugin;
}
});
}

app.dynamicHelpers({
blogName: function(){
return blogConfig['blog_name'];
Expand All @@ -40,6 +53,18 @@ app.dynamicHelpers({
}
});

app.helpers({
pluginFunction: function(pluginName, functionToCall, parametersArray) {
var plugin = loadedPlugins[pluginName];
var response = "__WAITING_FOR_RESPONSE__";
plugin[functionToCall](parametersArray, function(callbackParameters){
response = callbackParameters
});
while(response == "__WAITING_FOR_RESPONSE__") {}
return response;
}
});

bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
Expand Down
15 changes: 15 additions & 0 deletions plugins/test_plugin/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var sys = require('sys');

// <%= pluginFunction('test_plugin', 'returnFirstElement', ['ASD']) %>

exports.initialize = function() {
return ['test_plugin', "A Test plugin", "Pedro Franceschi", "pedrohfranceschi@gmail.com", "1.0"]
}

exports.returnFirstElement = function(numbersParam, callback) {
callback(numbersParam[0]);
}

exports.returnFirstElement = function(numbersParam, callback) {
callback(numbersParam[0]);
}

0 comments on commit 1812ff9

Please sign in to comment.