diff --git a/lib/dashing.js b/lib/dashing.js index 3e7da35..ece7519 100644 --- a/lib/dashing.js +++ b/lib/dashing.js @@ -2,36 +2,58 @@ var fs = require('fs') , path = require('path') , express = require('express') , Mincer = require('mincer') - , coffee = require('coffee-script'); + , coffee = require('coffee-script') + , _ = require('underscore'); global.SCHEDULER = require('node-schedule'); +/** + * OPTIONS for mincer and dashing server + */ +var OPTIONS = { + dashing: {}, + mincer: {} +}; + +OPTIONS.dashing.root = path.resolve(__dirname, '../../..'); +OPTIONS.dashing.public_folder = OPTIONS.dashing.root + '/public'; +OPTIONS.dashing.view = OPTIONS.dashing.root + '/dashboards'; +OPTIONS.mincer.asset_prefix = '/assets'; + module.exports.logger = logger = require('./logger'); -module.exports.Dashing = function Dashing() { +module.exports.Dashing = function Dashing(options) { var dashing = {}; - dashing.root = path.resolve(__dirname, '../../..'); - dashing.NODE_ENV = process.env.NODE_ENV || 'development'; + if(options.mincer){ + _.extend(OPTIONS.mincer, options.mincer); + } + + if(options.dashing){ + _.extend(OPTIONS.dashing, options.dashing); + } + + dashing.root = OPTIONS.dashing.root; + dashing.NODE_ENV = process.env.NODE_ENV || 'development'; dashing.view_engine = process.env.VIEW_ENGINE || 'jade'; dashing.mincer = {}; dashing.mincer.environment = new Mincer.Environment(); - dashing.mincer.assets_prefix = '/assets'; - dashing.mincer.environment.appendPath('assets/javascripts'); - dashing.mincer.environment.appendPath('assets/stylesheets'); - dashing.mincer.environment.appendPath('assets/fonts'); - dashing.mincer.environment.appendPath('assets/images'); - dashing.mincer.environment.appendPath('widgets'); + dashing.mincer.assets_prefix = OPTIONS.mincer.asset_prefix; + dashing.mincer.environment.appendPath(OPTIONS.dashing.root + '/assets/javascripts'); + dashing.mincer.environment.appendPath(OPTIONS.dashing.root + '/assets/stylesheets'); + dashing.mincer.environment.appendPath(OPTIONS.dashing.root + '/assets/fonts'); + dashing.mincer.environment.appendPath(OPTIONS.dashing.root + '/assets/images'); + dashing.mincer.environment.appendPath(OPTIONS.dashing.root + '/widgets'); dashing.mincer.environment.appendPath(path.resolve(__dirname, '../javascripts')); - dashing.public_folder = dashing.root + '/public'; - dashing.views = dashing.root + '/dashboards'; + dashing.public_folder = OPTIONS.dashing.public_folder; + dashing.views = OPTIONS.dashing.view; dashing.default_dashboard = null; dashing.port = (process.env.PORT || 3030); dashing._protected = function(req, res, next) { next(); - } + }; var expressLoggerOptions = { format: 'dev', diff --git a/templates/project/index.js b/templates/project/index.js new file mode 100644 index 0000000..9e287a5 --- /dev/null +++ b/templates/project/index.js @@ -0,0 +1,20 @@ +var dashing = require('dashing-js').Dashing({ + // optional override for overriding dashing server settings +}); + +// Set your auth token here +//dashing.auth_token = 'YOUR_AUTH_TOKEN'; + +/* +dashing._protected = function(req, res, next) { + // Put any authentication code you want in here. + // This method is run before accessing any resource. + // if (true) next(); +} +*/ + +// Set your default dashboard here +//dashing.default_dashboard = 'mydashboard'; + +// export dashing.app to be used within another module +exports = module.exports = dashing.app;