Permalink
Browse files

Allow app env to be passed in for mode config.

Cassette defaults the mode to 'debug' so if anything other than 'debug'
is passed in for the mode config value, it will use the production mode.
Since express uses 'development' as it's env by default, this will
convert 'development' to 'debug' when saving the mode config value.
  • Loading branch information...
1 parent 768ad3b commit d96793e475d98365571987130cd6b78b9309c432 @kevinkuebler kevinkuebler committed Aug 10, 2012
Showing with 107 additions and 108 deletions.
  1. +2 −3 EXAMPLE/app.js
  2. +105 −105 lib/cassette.js
View
@@ -5,11 +5,10 @@
var express = require('express')
, routes = require('./routes')
-
- // require cassette...
- , cassette = require('cassette-express')(); // we added an entry to package.json here..
+ , cassette
var app = module.exports = express.createServer();
+var cassette = require('cassette-express')({mode: app.settings.env});
// make the cassette middleware available inside templates..
app.locals( {assets : cassette.middleware()} );
View
@@ -1,105 +1,105 @@
-var base = require('base-framework'),
- _ = require('underscore'),
- Manifest = require('./manifest.js');
-
-// some defaults for an Express environment.
-var assetsPath = './public/javascripts/';
-var nodeModulesPath = './node_modules';
-var outputPath = '/javascripts';
-var nodeModules = '/node_modules';
-var buildPath = './public/javascripts/cassette';
-
-
-var cassette = base.createChild().addInstanceMethods({
-
- init : function( config ){
-
- if(config){
-
- if(config.assetsPath){
-
- assetsPath = config.assetsPath;
-
- }
-
- if(config.outputPath){
-
- outputPath = config.outputPath;
-
- }
-
- if(config.buildPath){
-
- buildPath = config.buildPath;
-
- }
-
- if(config.mode){
-
- this.mode = config.mode;
-
- }
-
- if(config.nodeModules){
-
- nodeModules = config.nodeModules;
-
- }
-
-
- if(config.scanNodeModules){
-
- this.scanNodeModules = config.scanNodeModules;
-
- } else {
-
- this.scanNodeModules = false;
-
- }
-
- } else {
-
- this.mode = 'debug';
- this.scanNodeModules = false;
-
- }
-
- this.manifest = Manifest(assetsPath, outputPath, nodeModules, this.scanNodeModules);
- this.assemblies = {};
-
- return this;
-
- },
-
- middleware : function(){
-
- var self = this;
-
- return {
-
- useAsset : function( asset ){
-
- var str;
-
- if(self.mode==='debug'){
-
- str = self.manifest.getAssembly( asset, 'forceCheck' ).getDebugTags( outputPath );
-
- } else {
-
- str = self.manifest.getAssembly( asset ).getTag( outputPath );
-
- }
-
- return str;
-
- }
-
- };
-
- }
-
-});
-
-
-exports = module.exports = cassette;
+var base = require('base-framework'),
+ _ = require('underscore'),
+ Manifest = require('./manifest.js');
+
+// some defaults for an Express environment.
+var assetsPath = './public/javascripts/';
+var nodeModulesPath = './node_modules';
+var outputPath = '/javascripts';
+var nodeModules = '/node_modules';
+var buildPath = './public/javascripts/cassette';
+
+
+var cassette = base.createChild().addInstanceMethods({
+
+ init : function( config ){
+
+ if(config){
+
+ if(config.assetsPath){
+
+ assetsPath = config.assetsPath;
+
+ }
+
+ if(config.outputPath){
+
+ outputPath = config.outputPath;
+
+ }
+
+ if(config.buildPath){
+
+ buildPath = config.buildPath;
+
+ }
+
+ if(config.mode){
+
+ this.mode = config.mode === 'development' ? 'debug' : config.mode;
+
+ }
+
+ if(config.nodeModules){
+
+ nodeModules = config.nodeModules;
+
+ }
+
+
+ if(config.scanNodeModules){
+
+ this.scanNodeModules = config.scanNodeModules;
+
+ } else {
+
+ this.scanNodeModules = false;
+
+ }
+
+ } else {
+
+ this.mode = 'debug';
+ this.scanNodeModules = false;
+
+ }
+
+ this.manifest = Manifest(assetsPath, outputPath, nodeModules, this.scanNodeModules);
+ this.assemblies = {};
+
+ return this;
+
+ },
+
+ middleware : function(){
+
+ var self = this;
+
+ return {
+
+ useAsset : function( asset ){
+
+ var str;
+
+ if(self.mode==='debug'){
+
+ str = self.manifest.getAssembly( asset, 'forceCheck' ).getDebugTags( outputPath );
+
+ } else {
+
+ str = self.manifest.getAssembly( asset ).getTag( outputPath );
+
+ }
+
+ return str;
+
+ }
+
+ };
+
+ }
+
+});
+
+
+exports = module.exports = cassette;

0 comments on commit d96793e

Please sign in to comment.