1
0
Fork 0

Foxx: Foxx.Application is now Foxx.Controller [BREAKING CHANGE]

The naming was confusing, because Foxx Application had two meanings.
Now we are using the terminology used in MVC frameworks.
This commit is contained in:
Lucas Dohmen 2013-09-04 10:43:39 +02:00
parent 95e409763d
commit afef07b425
8 changed files with 92 additions and 92 deletions

View File

@ -9,7 +9,7 @@ Foxx: Build APIs and simple web applications in ArangoDB{#UserManualFoxxIntro}
Foxx is an easy way to create APIs and simple web applications from within
ArangoDB. It is inspired by Sinatra, the classy Ruby web framework. If
FoxxApplication is Sinatra, @ref UserManualActions are the corresponding `Rack`.
Foxx is Sinatra, @ref UserManualActions are the corresponding `Rack`.
They provide all the HTTP goodness.
If you just want to install an existiting application, please use the
@ -36,7 +36,7 @@ After that, create a sub-directory `my_app` in the `apps` directory and
save the following content in a file named `app.js` there:
var Foxx = require("org/arangodb/foxx");
var app = new Foxx.Application(applicationContext);
var app = new Foxx.Controller(applicationContext);
app.get("/meadow", function(req, res) {
res.set("Content-Type", "text/plain");
@ -104,37 +104,37 @@ If you do not redefine it, all requests that go to the root of your
application will be redirected to `index.html`.
Details on FoxxApplication{#UserManualFoxxDetailsApplication}
Details on FoxxController{#UserManualFoxxDetailsController}
=============================================================
@copydetails JSF_foxx_application_initializer
@copydetails JSF_foxx_controller_initializer
HTTP Methods
------------
### Get
@copydetails JSF_foxx_application_get
@copydetails JSF_foxx_controller_get
### Head
@copydetails JSF_foxx_application_head
@copydetails JSF_foxx_controller_head
### Post
@copydetails JSF_foxx_application_post
@copydetails JSF_foxx_controller_post
### Put
@copydetails JSF_foxx_application_put
@copydetails JSF_foxx_controller_put
### Patch
@copydetails JSF_foxx_application_patch
@copydetails JSF_foxx_controller_patch
### Delete
@copydetails JSF_foxx_application_delete
@copydetails JSF_foxx_controller_delete
Documenting and Constraining the Routes
---------------------------------------
@ -189,17 +189,17 @@ example).
### Before
@copydetails JSF_foxx_application_before
@copydetails JSF_foxx_controller_before
### After
@copydetails JSF_foxx_application_after
@copydetails JSF_foxx_controller_after
The Request and Response Objects
--------------------------------
When you have created your FoxxApplication you can now define routes on it.
When you have created your FoxxController you can now define routes on it.
You provide each with a function that will handle the request. It gets two
arguments (four, to be honest. But the other two are not relevant for now):
@ -381,7 +381,7 @@ The content is a JSON object with the following keys:
* `repository`: An object with information about where you can find the repository: `type` and `url`
* `keywords`: An array of keywords to help people find your Foxx app
* `engines`: Should be an object with `arangodb` set to the ArangoDB version your Foxx app is compatible with.
* `apps`: Map routes to FoxxApplications
* `apps`: Map routes to FoxxControllers
* `lib`: Base path for all required modules
* `files`: Deliver files
* `assets`: Deliver pre-processed files
@ -437,9 +437,9 @@ collections you have created.
* The `key` is the route you want to mount at
* The `value` is the path to the JavaScript file containing the
`FoxxApplication` you want to mount
`FoxxController` you want to mount
You can add multiple applications in one manifest this way.
You can add multiple controllers in one manifest this way.
The `files`
------------
@ -499,17 +499,17 @@ We will offer the option to process all assets at once and write the files
to disk for production with the option to run `Uglify2.js` and similar
tools in order to compress them.
Controlling Access to Foxx Applications
Controlling Access to Foxx Controllers
---------------------------------------
At the moment, access to Foxx applications is controlled by the regular
At the moment, access to Foxx.Controllers is controlled by the regular
authentication mechanisms present in ArangoDB. The server can be run with
or without HTTP authentication.
If authentication is turned off, all Foxx applications and routes will be
If authentication is turned off, all Foxx.Controllers and routes will be
callable by everyone with access to the server. If authentication is turned on,
then every access to the server is authenticated via HTTP authentication. This
includes Foxx applications and routes. The global authentication can be toggled
includes Foxx.Controllers and routes. The global authentication can be toggled
via the configuration option @ref CommandLineArangoDisableAuthentication
"server.disable-authentication".
@ -554,15 +554,15 @@ Authentication
We built an authentication system you can use in your Foxx application (but you can of course roll your own if you want). Currently we only support cookie-based authentication, but we will add the possibility to use Auth Tokens and external OAuth providers in the near future. To use the authentication in your app, first activate it:
@copydetails JSF_foxx_application_activateAuthentication
@copydetails JSF_foxx_controller_activateAuthentication
### Adding a login route
@copydetails JSF_foxx_application_login
@copydetails JSF_foxx_controller_login
### Adding a logout route
@copydetails JSF_foxx_application_logout
@copydetails JSF_foxx_controller_logout
### Restricting routes
@ -575,7 +575,7 @@ To use this plugin, please require it first:
TemplateMiddleware = require("org/arangodb/foxx/template_middleware").TemplateMiddleware;
The `TemplateMiddleware` can be used to give a Foxx.Application the capability
The `TemplateMiddleware` can be used to give a Foxx.Controller the capability
of using templates. Currently you can only use Underscore Templates. It
expects documents in the following form in this collection:
@ -590,7 +590,7 @@ The `content` is the string that will be rendered by the template processor.
The `contentType` is the type of content that results from this call. And with
the `templateLanguage` you can choose your template processor. There is only
one choice now: `underscore`. Which would set the body of the response to
`hello Application` with the template defined above. It will also set the
`hello Controller` with the template defined above. It will also set the
`contentType` to `text/plain` in this case. In addition to the attributes
you provided, you also have access to all your view helpers.

View File

@ -99,7 +99,7 @@ function BaseMiddlewareSpec () {
error = e;
}
assertEqual(error, new Error("No template collection has been provided when creating a new FoxxApplication"));
assertEqual(error, new Error("No template collection has been provided when creating a new FoxxController"));
},
testMiddlewareCallsTheAction: function () {

View File

@ -1,7 +1,7 @@
require("internal").flushModuleCache();
var jsunity = require("jsunity"),
FoxxApplication = require("org/arangodb/foxx").Application,
FoxxController = require("org/arangodb/foxx").Controller,
db = require("org/arangodb").db,
fakeContext;
@ -14,10 +14,10 @@ fakeContext = {
collectionName: function () {}
};
function CreateFoxxApplicationSpec () {
function CreateFoxxControllerSpec () {
return {
testCreationWithoutParameters: function () {
var app = new FoxxApplication(fakeContext),
var app = new FoxxController(fakeContext),
routingInfo = app.routingInfo;
assertEqual(routingInfo.routes.length, 0);
@ -25,7 +25,7 @@ function CreateFoxxApplicationSpec () {
},
testCreationWithURLPrefix: function () {
var app = new FoxxApplication(fakeContext, {urlPrefix: "/wiese"}),
var app = new FoxxController(fakeContext, {urlPrefix: "/wiese"}),
routingInfo = app.routingInfo;
assertEqual(routingInfo.routes.length, 0);
@ -33,7 +33,7 @@ function CreateFoxxApplicationSpec () {
},
testAdditionOfBaseMiddlewareInRoutingInfo: function () {
var app = new FoxxApplication(fakeContext),
var app = new FoxxController(fakeContext),
routingInfo = app.routingInfo,
hopefully_base = routingInfo.middleware[0];
@ -43,12 +43,12 @@ function CreateFoxxApplicationSpec () {
};
}
function SetRoutesFoxxApplicationSpec () {
function SetRoutesFoxxControllerSpec () {
var app;
return {
setUp: function () {
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
},
testSettingRoutes: function () {
@ -173,7 +173,7 @@ function DocumentationAndConstraintsSpec () {
return {
setUp: function () {
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
routes = app.routingInfo.routes;
},
@ -356,12 +356,12 @@ function DocumentationAndConstraintsSpec () {
};
}
function AddMiddlewareFoxxApplicationSpec () {
function AddMiddlewareFoxxControllerSpec () {
var app;
return {
setUp: function () {
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
},
testAddABeforeMiddlewareForAllRoutes: function () {
@ -431,7 +431,7 @@ function CommentDrivenDocumentationSpec () {
return {
setUp: function () {
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
routingInfo = app.routingInfo;
noop = function () {};
},
@ -504,7 +504,7 @@ function HelperFunctionSpec () {
return {
setUp: function () {
fakeContext.collectionPrefix = "fancy";
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
},
testGetACollection: function () {
@ -535,7 +535,7 @@ function SetupAuthorization () {
testWorksWithAllParameters: function () {
var err;
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
try {
app.activateAuthentication({
@ -554,7 +554,7 @@ function SetupAuthorization () {
testRefusesUnknownAuthTypes: function () {
var err;
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
try {
app.activateAuthentication({
@ -573,7 +573,7 @@ function SetupAuthorization () {
testRefusesMissingCookieLifetime: function () {
var err;
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
try {
app.activateAuthentication({
@ -591,7 +591,7 @@ function SetupAuthorization () {
testRefusesMissingCookieName: function () {
var err;
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
try {
app.activateAuthentication({
@ -609,7 +609,7 @@ function SetupAuthorization () {
testRefusesMissingSessionLifetime: function () {
var err;
app = new FoxxApplication(fakeContext);
app = new FoxxController(fakeContext);
try {
app.activateAuthentication({
@ -626,10 +626,10 @@ function SetupAuthorization () {
};
}
jsunity.run(CreateFoxxApplicationSpec);
jsunity.run(SetRoutesFoxxApplicationSpec);
jsunity.run(CreateFoxxControllerSpec);
jsunity.run(SetRoutesFoxxControllerSpec);
jsunity.run(DocumentationAndConstraintsSpec);
jsunity.run(AddMiddlewareFoxxApplicationSpec);
jsunity.run(AddMiddlewareFoxxControllerSpec);
jsunity.run(CommentDrivenDocumentationSpec);
jsunity.run(HelperFunctionSpec);
jsunity.run(SetupAuthorization);

View File

@ -28,11 +28,11 @@
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var Application = require("org/arangodb/foxx/application").Application,
var Controller = require("org/arangodb/foxx/controller").Controller,
Model = require("org/arangodb/foxx/model").Model,
Repository = require("org/arangodb/foxx/repository").Repository;
exports.Application = Application;
exports.Controller = Controller;
exports.Model = Model;
exports.Repository = Repository;

View File

@ -2,7 +2,7 @@
/*global module, require, exports */
////////////////////////////////////////////////////////////////////////////////
/// @brief Foxx application
/// @brief Foxx Controller
///
/// @file
///
@ -28,7 +28,7 @@
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var Application,
var Controller,
RequestContext = require("org/arangodb/foxx/request_context").RequestContext,
db = require("org/arangodb").db,
BaseMiddleware = require("org/arangodb/foxx/base_middleware").BaseMiddleware,
@ -73,16 +73,16 @@ defaultsFor.logout = {
};
// -----------------------------------------------------------------------------
// --SECTION-- Application
// --SECTION-- Controller
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_initializer
/// @brief Create a new Application
/// @fn JSF_foxx_controller_initializer
/// @brief Create a new Controller
///
/// @FUN{new FoxxApplication(@FA{applicationContext}, @FA{options})}
/// @FUN{new FoxxController(@FA{applicationContext}, @FA{options})}
///
/// This creates a new Application. The first argument is the application
/// This creates a new Controller. The first argument is the controller
/// context available in the variable `applicationContext`. The second one is an
/// options array with the following attributes:
///
@ -91,13 +91,13 @@ defaultsFor.logout = {
/// @EXAMPLES
///
/// @code
/// app = new Application(applicationContext, {
/// app = new Controller(applicationContext, {
/// urlPrefix: "/meadow"
/// });
/// @endcode
////////////////////////////////////////////////////////////////////////////////
Application = function (context, options) {
Controller = function (context, options) {
'use strict';
var urlPrefix, baseMiddleware;
@ -150,7 +150,7 @@ Application = function (context, options) {
this.applicationContext = context;
};
extend(Application.prototype, {
extend(Controller.prototype, {
currentPriority: 0,
collection: function (name) {
@ -173,7 +173,7 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_handleRequest
/// @fn JSF_foxx_controller_handleRequest
/// @brief Handle a request
///
/// The `handleRequest` method is the raw way to create a new route. You
@ -206,10 +206,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_head
/// @fn JSF_foxx_controller_head
/// @brief Handle a `head` request
///
/// @FUN{FoxxApplication::head(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::head(@FA{path}, @FA{callback})}
///
/// This handles requests from the HTTP verb `head`. You have to give a
/// function as @FA{callback}. It will get a request and response object as its
@ -222,10 +222,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_get
/// @fn JSF_foxx_controller_get
/// @brief Manage a `get` request
///
/// @FUN{FoxxApplication::get(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::get(@FA{path}, @FA{callback})}
///
/// This handles requests from the HTTP verb `get`.
///
@ -249,10 +249,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_post
/// @fn JSF_foxx_controller_post
/// @brief Tackle a `post` request
///
/// @FUN{FoxxApplication::post(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::post(@FA{path}, @FA{callback})}
///
/// This handles requests from the HTTP verb `post`. See above for the
/// arguments you can give.
@ -272,10 +272,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_put
/// @fn JSF_foxx_controller_put
/// @brief Sort out a `put` request
///
/// @FUN{FoxxApplication::put(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::put(@FA{path}, @FA{callback})}
///
/// This handles requests from the HTTP verb `put`. See above for the arguments
/// you can give.
@ -295,10 +295,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_patch
/// @fn JSF_foxx_controller_patch
/// @brief Take charge of a `patch` request
///
/// @FUN{FoxxApplication::patch(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::patch(@FA{path}, @FA{callback})}
///
/// This handles requests from the HTTP verb `patch`. See above for the
/// arguments you can give.
@ -318,10 +318,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_delete
/// @fn JSF_foxx_controller_delete
/// @brief Respond to a `delete` request
///
/// @FUN{FoxxApplication::delete(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::delete(@FA{path}, @FA{callback})}
///
/// This handles requests from the HTTP verb `delete`. See above for the
/// arguments you can give.
@ -354,10 +354,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_before
/// @fn JSF_foxx_controller_before
/// @brief Before
///
/// @FUN{FoxxApplication::before(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::before(@FA{path}, @FA{callback})}
///
/// The before function takes a @FA{path} on which it should watch and a
/// function that it should execute before the routing takes place. If you do
@ -393,10 +393,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_after
/// @fn JSF_foxx_controller_after
/// @brief After
///
/// @FUN{FoxxApplication::after(@FA{path}, @FA{callback})}
/// @FUN{FoxxController::after(@FA{path}, @FA{callback})}
///
/// This works pretty similar to the before function. But it acts after the
/// execution of the handlers (Big surprise, I suppose).
@ -427,10 +427,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_activateAuthentication
/// @fn JSF_foxx_controller_activateAuthentication
/// @brief Activate authentication for this app
///
/// @FUN{FoxxApplication::activateAuthentication(@FA{opts})}
/// @FUN{FoxxController::activateAuthentication(@FA{opts})}
///
/// To activate authentication for this authentication, first call this function.
/// Provide the following arguments:
@ -507,10 +507,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_login
/// @fn JSF_foxx_controller_login
/// @brief Add a login handler
///
/// @FUN{FoxxApplication::login(@FA{path}, @FA{opts})}
/// @FUN{FoxxController::login(@FA{path}, @FA{opts})}
///
/// Add a route for the login. You can provide further customizations via the
/// the options:
@ -558,10 +558,10 @@ extend(Application.prototype, {
},
////////////////////////////////////////////////////////////////////////////////
/// @fn JSF_foxx_application_logout
/// @fn JSF_foxx_controller_logout
/// @brief Add a logout handler
///
/// @FUN{FoxxApplication::logout(@FA{path}, @FA{opts})}
/// @FUN{FoxxController::logout(@FA{path}, @FA{opts})}
///
/// This works pretty similar to the logout function and adds a path to your
/// app for the logout functionality. You can customize it with a custom `onSuccess`
@ -603,7 +603,7 @@ extend(Application.prototype, {
}
});
exports.Application = Application;
exports.Controller = Controller;
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE

View File

@ -45,14 +45,14 @@ var Repository,
/// Create a new instance of Repository
///
/// A Foxx Repository is always initialized with a collection object. You can
/// your collection object by asking your Foxx application for it via the
/// your collection object by asking your Foxx.Controller for it via the
/// `collection` method that takes the name of the collection (and will prepend
/// the prefix of your application). It also takes two optional arguments:
///
/// 1. Model: The prototype of a model. If you do not provide it, it will default
/// to Foxx.Model
/// 2. Prefix: You can provide the prefix of the application if you need it in
/// your Repository (for some AQL queries probably). Get it from the Foxx application
/// your Repository (for some AQL queries probably). Get it from the Foxx.Controller
/// via the `collectionPrefix` attribute.
///
/// @EXAMPLES

View File

@ -167,7 +167,7 @@ extend(RequestContext.prototype, {
/// @fn JSF_foxx_RequestContext_queryParam
/// @brief Describe a Query Parameter
///
/// @FUN{FoxxApplication::queryParam(@FA{id}, @FA{options})}
/// @FUN{FoxxController::queryParam(@FA{id}, @FA{options})}
///
/// Describe a query parameter:
///
@ -211,7 +211,7 @@ extend(RequestContext.prototype, {
/// @fn JSF_foxx_RequestContext_summary
/// @brief Set the summary for this route in the documentation
///
/// @FUN{FoxxApplication::summary(@FA{description})}
/// @FUN{FoxxController::summary(@FA{description})}
///
/// Set the summary for this route in the documentation. Can't be longer than 60.
/// characters
@ -230,7 +230,7 @@ extend(RequestContext.prototype, {
/// @fn JSF_foxx_RequestContext_notes
/// @brief Set the notes for this route in the documentation
///
/// @FUN{FoxxApplication::notes(@FA{description})}
/// @FUN{FoxxController::notes(@FA{description})}
///
/// Set the notes for this route in the documentation
////////////////////////////////////////////////////////////////////////////////
@ -245,7 +245,7 @@ extend(RequestContext.prototype, {
/// @fn JSF_foxx_RequestContext_errorResponse
/// @brief Define an error response
///
/// @FUN{FoxxApplication::errorResponse(@FA{errorClass}, @FA{code}, @FA{description})}
/// @FUN{FoxxController::errorResponse(@FA{errorClass}, @FA{code}, @FA{description})}
///
/// Define a reaction to a thrown error for this route: If your handler throws an error
/// of the defined errorClass, it will be caught and the response will have the given
@ -288,7 +288,7 @@ extend(RequestContext.prototype, {
/// @fn JSF_foxx_RequestContext_onlyIf
/// @brief Only let the request get through if a condition holds
///
/// @FUN{FoxxApplication::onlyIf(@FA{check})}
/// @FUN{FoxxController::onlyIf(@FA{check})}
///
/// Provide it with a function that throws an exception if the normal processing should
/// not be executed. Provide an `errorResponse` to define the behavior in this case.
@ -313,7 +313,7 @@ extend(RequestContext.prototype, {
/// @fn JSF_foxx_RequestContext_onlyIfAuthenticated
/// @brief Only let the request get through if the user is logged in
///
/// @FUN{FoxxApplication::onlyIf(@FA{code}, @FA{reason})}
/// @FUN{FoxxController::onlyIf(@FA{code}, @FA{reason})}
///
/// Please activate authentification for this app if you want to use this function.
/// If the user is logged in, it will do nothing. Otherwise it will respond with

View File

@ -38,7 +38,7 @@ var TemplateMiddleware,
///
/// Initialize with the name of a collection or a collection and optionally
/// a set of helper functions.
/// Then use `before` to attach the initialized middleware to your Foxx.Application
/// Then use `before` to attach the initialized middleware to your Foxx.Controller
///
/// @EXAMPLES
///
@ -69,7 +69,7 @@ TemplateMiddleware = function (templateCollection, helper) {
///
/// When the TemplateMiddleware is included, you will have access to the
/// `render` function on the response object.
/// If you call render, Application will look into the this collection and
/// If you call render, Controller will look into the this collection and
/// search by the path attribute. It will then render the template with the
/// given data.
///