Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use dashingjs as a module rather as a server #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions lib/dashing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary, add underscore.js as a dependency only for extend?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely not, sorry :) Please refactor as needed, it was the first thing on my head.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not a critic :) Did you see my other comment on this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiocaseri 🍻

Saw your other comments just now. I'll put up an example some where.


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',
Expand Down
20 changes: 20 additions & 0 deletions templates/project/index.js
Original file line number Diff line number Diff line change
@@ -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;