Skip to content

Commit

Permalink
Merge branch 'release-3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 29, 2016
2 parents 94ee998 + f83871e commit 88e5f64
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 17 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,14 @@
<a name="3.0.1"></a>
## [3.0.1](https://github.com/adonisjs/adonis-framework/compare/v3.0.0...v3.0.1) (2016-07-29)


### Features

* **resource:middleware:** chain middleware method on route resource([04d6acc](https://github.com/adonisjs/adonis-framework/commit/04d6acc))
* **route:resource:** resource members & coll accepts callback([6603d4f](https://github.com/adonisjs/adonis-framework/commit/6603d4f))



<a name="3.0.0"></a>
# [3.0.0](https://github.com/adonisjs/adonis-framework/compare/v2.0.9...v3.0.0) (2016-06-26)

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "adonis-framework",
"version": "3.0.0",
"version": "3.0.1",
"description": "Adonis framework makes it easy for you to write webapps with less code",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"cat-log": "^1.0.2",
"co": "^4.6.0",
"dotenv": "^2.0.0",
"eventemitter2": "^1.0.2",
"eventemitter2": "^2.0.0",
"lodash": "^4.11.2",
"mkdirp": "^0.5.1",
"node-cookie": "^1.0.2",
Expand Down
88 changes: 88 additions & 0 deletions src/Route/ResourceCollection.js
@@ -0,0 +1,88 @@
'use strict'

/**
* adonis-framework
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const helpers = require('./helpers')
const util = require('../../lib/util')
const CatLog = require('cat-log')
const logger = new CatLog('adonis:framework')

class ResourceCollection {

constructor (route) {
this.route = route
}

/**
* binds action to the route, it will override
* the old action
*
* @param {String|Function} action
*
* @return {Object}
*
* @public
*/
bindAction (action) {
this.route.handler = action
return this
}

/**
* @see this.middleware
*/
middlewares () {
logger.warn('collection@middlewares: consider using method middleware, instead of middlewares')
return this.middleware.apply(this, arguments)
}

/**
* appends middlewares to the route
*
* @return {Object}
*
* @public
*/
middleware () {
helpers.appendMiddleware(
this.route,
util.spread.apply(this, arguments)
)
return this
}

/**
* assign name to the route
*
* @param {String} name
*
* @return {Object}
*
* @public
*/
as (name) {
this.route.name = name
return this
}

/**
* return json representation of the route
*
* @return {Object}
*
* @public
*/
toJSON () {
return this.route
}

}

module.exports = ResourceCollection
88 changes: 88 additions & 0 deletions src/Route/ResourceMember.js
@@ -0,0 +1,88 @@
'use strict'

/**
* adonis-framework
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const helpers = require('./helpers')
const util = require('../../lib/util')
const CatLog = require('cat-log')
const logger = new CatLog('adonis:framework')

class ResourceMember {

constructor (route) {
this.route = route
}

/**
* binds action to the route, it will override
* the old action
*
* @param {String|Function} action
*
* @return {Object}
*
* @public
*/
bindAction (action) {
this.route.handler = action
return this
}

/**
* @see this.middleware
*/
middlewares () {
logger.warn('member@middlewares: consider using method middleware, instead of middlewares')
return this.middleware.apply(this, arguments)
}

/**
* appends middlewares to the route
*
* @return {Object}
*
* @public
*/
middleware () {
helpers.appendMiddleware(
this.route,
util.spread.apply(this, arguments)
)
return this
}

/**
* assign name to the route
*
* @param {String} name
*
* @return {Object}
*
* @public
*/
as (name) {
this.route.name = name
return this
}

/**
* return json representation of the route
*
* @return {Object}
*
* @public
*/
toJSON () {
return this.route
}

}

module.exports = ResourceMember
14 changes: 9 additions & 5 deletions src/Route/index.js
Expand Up @@ -12,6 +12,8 @@ const Resource = require('./resource')
const domains = require('./domains')
const util = require('../../lib/util')
const _ = require('lodash')
const CatLog = require('cat-log')
const logger = new CatLog('adonis:framework')

/**
* holding reference to registered routes
Expand Down Expand Up @@ -313,7 +315,7 @@ Route._lastRoute = function () {
/**
* assign array of named middlewares to route
*
* @method middlewares
* @method middleware
* @synonym middleware
*
* @param {Mixed} keys - an array of middleware or multiple parameters
Expand All @@ -325,7 +327,7 @@ Route._lastRoute = function () {
*
* @public
*/
Route.middlewares = function () {
Route.middleware = function () {
helpers.appendMiddleware(
Route._lastRoute(),
util.spread.apply(this, arguments)
Expand All @@ -334,10 +336,12 @@ Route.middlewares = function () {
}

/**
* @see module:Route~middlewares
* @method middleware
* @see module:Route~middleware
*/
Route.middleware = Route.middlewares
Route.middlewares = function () {
logger.warn('route@middlewares: consider using method middleware, instead of middlewares')
Route.middleware.apply(Route, arguments)
}

/**
* create a new group of routes to apply rules on a group
Expand Down

0 comments on commit 88e5f64

Please sign in to comment.