Skip to content

Commit

Permalink
Merge tag 'v0.12.3'
Browse files Browse the repository at this point in the history
0.12.3

* tag 'v0.12.3':
  0.12.3
  Clarify that these type of view filenames (i.e. with extra dots) are not allowed (in assertion msg.)
  Update changelog.
  Fixes balderdashy#3682
  Cleanup in route:typeUnknown event handler.
  Apply coding conventions.
  Trivial (clearer variable name for usage of sailsUtil to facilitate future cleanup).
  Added a couple of tests to ensure skipAssets is working as expected for controller/action route targets. (it is)
  Assorted cleanup of existing test file including skipAssets.
  Adjust todo.
  Add failing test re balderdashy#3682
  Stub out skipAssets test- extracting the improved helper that spawns a child proce that performs sails lift along the way.
  Switch to chalk
  • Loading branch information
ctartist621 committed Apr 6, 2016
2 parents 852dd4c + 6db6cc4 commit d84fe01
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 399 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
_A blank slate, as of 1459549711072. Just imagine all the possibilities._


### 0.12.3

* [BUGFIX] Allow `skipAssets` and `skipRegex` to be used with direct/static view route target syntax [3682](https://github.com/balderdashy/sails/issues/3682). Thanks [@dottodot](https://github.com/dottodot), [@nikhilbedi](https://github.com/nikhilbedi), and [@AlexanderKozhevin](https://github.com/AlexanderKozhevin)!
* [BUGFIX] Automatically route to `index/` in deeply nested views when using direct/static view route target syntax
* [BUGFIX] Add assertion about views which contain extra dots (`.`) in their paths when using direct/static view route target syntax


### 0.12.2

* [ENHANCEMENT] Allow use of `fn` in expanded route targets [e1790b7](https://github.com/balderdashy/sails/commit/e1790b70b35cd7dc50743a63bb169585f8a927f2)
Expand Down
6 changes: 3 additions & 3 deletions bin/sails-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var nodepath = require('path');
var REPL = require('repl');
var fs = require('fs');
var _ = require('lodash');
require('colors');
var chalk = require('chalk');
var CaptainsLog = require('captains-log');
var Sails = require('../lib/app');
var rconf = require('../lib/app/configuration/rc');
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = function() {
})();

console.log();
log.info('Starting app in interactive mode...'.debug);
log.info(chalk.blue('Starting app in interactive mode...'));
console.log();

// Lift Sails
Expand All @@ -80,7 +80,7 @@ module.exports = function() {
}

log.info('Welcome to the Sails console.');
log.info(('( to exit, type ' + '<CTRL>+<C>' + ' )').grey);
log.info(chalk.grey('( to exit, type ' + '<CTRL>+<C>' + ' )'));
console.log();

// Start a REPL
Expand Down
3 changes: 2 additions & 1 deletion bin/sails-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
var path = require('path');
var Womb = require('child_process');
var CaptainsLog = require('captains-log');
var chalk = require('chalk');
var Sails = require('../lib/app');


Expand Down Expand Up @@ -45,7 +46,7 @@ module.exports = function() {
console.log();
}

log.info(('( to exit, type ' + '<CTRL>+<C>' + ' )').grey);
log.info(chalk.grey('( to exit, type ' + '<CTRL>+<C>' + ' )'));
console.log();

// Spin up child process for Sails
Expand Down
4 changes: 2 additions & 2 deletions bin/sails-lift.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var nodepath = require('path');
var _ = require('lodash');
var chalk = require('chalk');
var captains = require('captains-log');
var package = require('../package.json');
var rconf = require('../lib/app/configuration/rc');
Expand Down Expand Up @@ -34,8 +35,7 @@ module.exports = function() {
// console.timeEnd('cli_rc');

console.log();
require('colors');
log.info('Starting app...'.grey);
log.info(chalk.grey('Starting app...'));
console.log();

// Build initial scope, mixing-in rc config
Expand Down
3 changes: 2 additions & 1 deletion errors/fatal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
var nodeutil = require('util');
var nodepath = require('path');
var chalk = require('chalk');

// Build logger using best-available information
// when this module is initially required.
Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = {
log.error('Or if you\'re stuck, check out the troubleshooting tips below.');
log.blank();

log.error('Troubleshooting tips:'.underline);
log.error(chalk.underline('Troubleshooting tips:'));
var relativePublicPath = (nodepath.resolve(process.cwd(), './.tmp'));
var uid = process.getuid && process.getuid() || 'YOUR_COMPUTER_USER_NAME';
log.error();
Expand Down
9 changes: 5 additions & 4 deletions lib/app/lift.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var async = require('async');
var _ = require('lodash');
var chalk = require('chalk');

/**
* Sails.prototype.lift()
Expand Down Expand Up @@ -65,11 +66,11 @@ function _printSuccessMsg(sails) {

sails.log.ship && sails.log.ship();
sails.log.info(('Server lifted in `' + sails.config.appPath + '`'));
sails.log.info(('To see your app, visit ' + (sails._getBaseUrl() || '').underline));
sails.log.info(chalk.underline('To see your app, visit ' + (sails._getBaseUrl() || '')));
sails.log.info(('To shut down Sails, press <CTRL> + C at any time.'));
sails.log.blank();
sails.log('--------------------------------------------------------'.grey);
sails.log((':: ' + new Date()).grey);
sails.log(chalk.grey(Array(56).join('-')));
sails.log(chalk.grey(':: ' + new Date()));
sails.log.blank();
sails.log('Environment : ' + sails.config.environment);

Expand All @@ -78,6 +79,6 @@ function _printSuccessMsg(sails) {
sails.log('Host : ' + sails.getHost()); // 12 - 4 = 8 spaces
}
sails.log('Port : ' + sails.config.port); // 12 - 4 = 8 spaces
sails.log('--------------------------------------------------------'.grey);
sails.log(chalk.grey(Array(56).join('-')));
}
}
162 changes: 82 additions & 80 deletions lib/hooks/blueprints/onRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,109 +15,111 @@ var _ = require('lodash');
* Expose route parser.
* @type {Function}
*/
module.exports = function (sails) {


return interpretRouteSyntax;



/**
* interpretRouteSyntax
*
* "Teach" router to understand direct references to blueprints
* as a target to sails.router.bind()
* (i.e. in the `routes.js` file)
*
* @param {[type]} route [description]
* @return {[type]} [description]
* @api private
*/
function interpretRouteSyntax (route) {
var target = route.target,
path = route.path,
verb = route.verb,
options = route.options;

// Support referencing blueprints in explicit routes
// (`{ blueprint: 'create' }` et. al.)
if (
_.isObject(target) &&
!_.isFunction(target) &&
!_.isArray(target) &&
_.isString(target.blueprint)) {

// On a match, merge leftover items in the target object into route options:
options = _.merge(options, _.omit(target, 'blueprint'));
return bindBlueprintAction(path, target.blueprint, verb, options);
}

// Ignore unknown route syntax
// If it needs to be understood by another hook, the hook would have also received
// the typeUnknown event, so we're done.
return;
}



/**
* Bind explicit route to a blueprint action.
*
* @param {[type]} path [description]
* @param {[type]} blueprintActionID [description]
* @param {[type]} verb [description]
* @param {[type]} options [description]
* @return {[type]} [description]
* @api private
*/
function bindBlueprintAction ( path, blueprintActionID, verb, options ) {

// Look up appropriate blueprint action and make sure it exists
var blueprint = sails.middleware.blueprints[blueprintActionID];

// If a 'blueprint' was specified, but it doesn't exist, warn the user and ignore it.
if ( ! ( blueprint && _.isFunction(blueprint) )) {
sails.log.error(
blueprintActionID,
':: Ignoring attempt to bind route (' + path + ') to unknown blueprint action (`'+blueprintActionID+'`).'
);
return;
}
module.exports = function(sails) {

/**
* interpretRouteSyntax
*
* "Teach" router to understand direct references to blueprints
* as a target to sails.router.bind()
* (i.e. in the `routes.js` file)
*
* @param {[type]} route [description]
* @return {[type]} [description]
* @api private
*/
return function interpretRouteSyntax(route) {
var target = route.target,
path = route.path,
verb = route.verb,
options = route.options;

// Support referencing blueprints in explicit routes
// (`{ blueprint: 'create' }` et. al.)
if (
_.isObject(target) &&
!_.isFunction(target) &&
!_.isArray(target) &&
_.isString(target.blueprint)) {

// On a match, merge leftover items in the target object into route options:
options = _.merge(options, _.omit(target, 'blueprint'));
// Note: this (^) could be moved up into lib/router/bind.js, since its
// only pertinent for core options such as `skipAssets`. There would need
// to be changes in other hooks as well.

return bindBlueprintAction(path, target.blueprint, verb, options);
}

// Ignore unknown route syntax
// If it needs to be understood by another hook, the hook would have also received
// the typeUnknown event, so we're done.
return;
};



/**
* Bind explicit route to a blueprint action.
*
* @param {[type]} path [description]
* @param {[type]} blueprintActionID [description]
* @param {[type]} verb [description]
* @param {[type]} options [description]
* @return {[type]} [description]
* @api private
*/
function bindBlueprintAction(path, blueprintActionID, verb, options) {

// Look up appropriate blueprint action and make sure it exists
var blueprint = sails.middleware.blueprints[blueprintActionID];

// If a 'blueprint' was specified, but it doesn't exist, warn the user and ignore it.
if (!(blueprint && _.isFunction(blueprint))) {
sails.log.error(
blueprintActionID,
':: Ignoring attempt to bind route (' + path + ') to unknown blueprint action (`' + blueprintActionID + '`).'
);
return;
}

// If a model wasn't provided with the options, try and guess it
if (!options.model) {
var matches = path.match(/^\/(\w+).*$/);
if (matches && matches[1] && sails.models[matches[1]]) {
options.model = matches[1];
}
else {
} else {
sails.log.error(
blueprintActionID,
':: Ignoring attempt to bind route (' + path + ') to blueprint action (`'+blueprintActionID+'`), but no valid model was specified and we couldn\'t guess one based on the path.'
':: Ignoring attempt to bind route (' + path + ') to blueprint action (`' + blueprintActionID + '`), but no valid model was specified and we couldn\'t guess one based on the path.'
);
return;
}
}

// If associations weren't provided with the options, try and get them
if (!options.associations) {
options = _.merge({ associations: _.cloneDeep(sails.models[options.model].associations) }, options);
options = _.merge({
associations: _.cloneDeep(sails.models[options.model].associations)
}, options);
}
// Otherwise make sure it's an array of strings of valid association aliases
else {
options.associations = options.associations.map(function(alias) {
if (typeof(alias) != 'string') {
if (!_.isString(alias)) {
sails.log.error(
blueprintActionID,
':: Ignoring invalid association option for '+path+'.'
':: Ignoring invalid association option for ' + path + '.'
);
return;
}
var association;
if (!(association = _.findWhere(sails.models[options.model].associations, {alias: alias}))) {
if (!(association = _.findWhere(sails.models[options.model].associations, {
alias: alias
}))) {
sails.log.error(
blueprintActionID,
':: Ignoring invalid association option `'+alias+'` for '+path+'.'
':: Ignoring invalid association option `' + alias + '` for ' + path + '.'
);
return;
}
Expand All @@ -126,13 +128,13 @@ module.exports = function (sails) {
}

// If "populate" wasn't provided in the options, use the default
if (typeof (options.populate) == 'undefined') {
if (_.isUndefined(options.populate)) {
options.populate = sails.config.blueprints.populate;
}

sails.router.bind(path, blueprint, verb, options);
sails.router.bind(path, blueprint, verb, options);

return;
}
return;
}

};
6 changes: 4 additions & 2 deletions lib/hooks/controllers/to-interpret-route-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ module.exports = function to(sails) {
// `{ controller: 'UserController' }`
if (_.isObject(target) && !_.isFunction(target) && !_.isArray(target)) {

// Merge target into `options` to get hold of relevant
// route options:
// Merge target into `options` to get hold of relevant route options:
options = _.merge(options, target);
// Note: this (^) could be moved up into lib/router/bind.js, since its
// only pertinent for core options such as `skipAssets`. There would need
// to be changes in other hooks as well.

// Support { controller: 'FooController' } notation (with or without `action`)
if ( !_.isUndefined(target.controller) ) {
Expand Down
9 changes: 6 additions & 3 deletions lib/hooks/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Module dependencies
*/

var _ = require('lodash');
var configure = require('./configure');
var defaults = require('./defaults');
var onRoute = require('./onRoute');
Expand All @@ -25,7 +24,9 @@ module.exports = function (sails) {

defaults: defaults,

configure: _.partial(configure, sails),
configure: function (){
configure(sails);
},

render: render,

Expand Down Expand Up @@ -66,7 +67,9 @@ module.exports = function (sails) {
});

// Register `{view:'/foo'}` route target syntax.
sails.on('route:typeUnknown', _.partial(onRoute, sails));
sails.on('route:typeUnknown', function (route){
return onRoute(sails, route);
});

// Declare hook loaded when ejs layouts have been applied,
// views have been inventoried, and view-serving middleware has been prepared
Expand Down
Loading

0 comments on commit d84fe01

Please sign in to comment.