Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
347 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'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 GE = require('@adonisjs/generic-exceptions') | ||
const Macroable = require('macroable') | ||
const RouteStore = require('./Store') | ||
const Route = require('./index') | ||
|
||
class BriskRoute extends Macroable { | ||
constructor (routePath) { | ||
super() | ||
this.routePath = routePath | ||
this._handlerDefined = false | ||
} | ||
|
||
/** | ||
* Sets the handler for brisk route. | ||
* | ||
* @method setHandler | ||
* | ||
* @param {Function|String} handler | ||
* @param {Array} verbs | ||
* | ||
* @return {Route} | ||
* | ||
* @throws {RuntimeException} If trying to re-define handler for the route | ||
*/ | ||
setHandler (handler, verbs) { | ||
if (this._handlerDefined) { | ||
throw GE.RuntimeException.invoke('Cannot re-define handler for brisk route') | ||
} | ||
|
||
const routeInstance = new Route(this.routePath, handler, verbs) | ||
RouteStore.add(routeInstance) | ||
this._handlerDefined = true | ||
return routeInstance | ||
} | ||
|
||
/** | ||
* Render a view from the route | ||
* | ||
* @method render | ||
* | ||
* @param {String} template | ||
* @param {Object} data | ||
* | ||
* @return {Route} | ||
*/ | ||
render (template, data = {}) { | ||
return this.setHandler(({ view }) => { | ||
return view.render(template, data) | ||
}, ['GET', 'HEAD']) | ||
} | ||
} | ||
|
||
/** | ||
* Defining _macros and _getters property | ||
* for Macroable class | ||
* | ||
* @type {Object} | ||
*/ | ||
BriskRoute._macros = {} | ||
BriskRoute._getters = {} | ||
|
||
module.exports = BriskRoute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello {{ name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.