Permalink
Browse files

Refactor and move stuff around

  • Loading branch information...
1 parent 09c626b commit 5514e53621c55e1eeec3110ba415886fb54590cf @Sutto committed Jul 24, 2011
View
@@ -0,0 +1 @@
+node_modules
View
@@ -10,10 +10,26 @@ run = (args, cb) ->
process.exit(1) if status != 0
cb() if typeof cb is 'function'
+isDirectory = (f) ->
+ path.existsSync(f) and fs.statSync(f).isDirectory()
+
buildUnder = (input, output) ->
files = fs.readdirSync input
- files = (input + '/' + file for file in files when file.match(/\.coffee$/))
- run ['-c', '-o', output].concat(files)
+ compiling = []
+ directories = []
+ for file in files
+ fullPath = "#{input}/#{file}"
+ if file.match /\.coffee$/
+ compiling.push fullPath
+ else if isDirectory fullPath
+ directories.push [fullPath, "#{output}/#{file}"]
+ if compiling.length
+ unless isDirectory output
+ fs.mkdirSync output, 0755
+ run ['-c', '-o', output].concat(compiling)
+ if directories.length
+ for directory in directories
+ buildUnder directory[0], directory[1]
task 'build:library', 'builds the library from coffee-script library', bl = ->
console.log "Building the private server JavaScript..."
View
@@ -16,6 +16,30 @@ I built prior versions for earlier rumbles.
First, make sure you have [node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
+### Writing a Publisher
+
+Publishers are just the general idea of a configurable item which can push things to the notifications list.
+For example, to implement a simple publisher, you can do (in CoffeeScript):
+
+```coffeescript
+Base = require('chainsaw/base).Base
+
+class MyPublisher extends Base
+ name: "my-publisher"
+
+ setup: ->
+ # Called automatically.
+ stored_name = @get "name" # gets name in the my-publisher key in the configuration
+ setInterval((=>
+ @emit some: "data"
+ ), 10000)
+```
+
+You define a setup method that starts doing processing, configure a name (and optionally, `namespace`
+for events and `configNamespace` for the configuration json namespace). This simple yet flexible architecture
+makes it possible to build a wide variety of publishers.
+
+
### Configuration
Chainsaw uses a standard `config.json` file which uses nested keys according to:
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,48 @@
+(function() {
+ var Base, sys;
+ sys = require('sys');
+ Base = (function() {
+ Base.prototype.name = "unknown";
+ function Base(runner) {
+ var _ref, _ref2;
+ this.runner = runner;
+ if ((_ref = this.configNamespace) != null) {
+ _ref;
+ } else {
+ this.configNamespace = this.name;
+ };
+ if ((_ref2 = this.namespace) != null) {
+ _ref2;
+ } else {
+ this.namespace = this.name;
+ };
+ }
+ Base.prototype.isEnabled = function() {
+ return this.runner.get('chainsaw.enabled', []).indexOf(this.name) > -1;
+ };
+ Base.prototype.run = function() {
+ if (this.isEnabled()) {
+ sys.puts("Starting publisher: " + this.name);
+ return this.setup();
+ }
+ };
+ Base.prototype.get = function(key, defaultValue) {
+ return this.runner.get("" + this.configNamespace + "." + key, defaultValue);
+ };
+ Base.prototype.config = function() {
+ return this.runner.get(this.configNamespace);
+ };
+ Base.prototype.emit = function(key, message) {
+ if (message != null) {
+ key = "" + this.namespace + ":" + key;
+ } else {
+ message = key;
+ key = this.namespace;
+ }
+ this.runner.io.sockets.emit(key, message);
+ return this.runner.redis.addHistory(key, JSON.stringify(message));
+ };
+ return Base;
+ })();
+ exports.Base = Base;
+}).call(this);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 5514e53

Please sign in to comment.