nameless

1.0.7 • Public • Published

nameless (beta) -- Easy MVC sync Framework

INSTALLING

via npm

  • npm install nameless
  • You're done!

from source

  • git clone https://github.com/StarmanMartin/nameless.git
  • cd nameless
  • npm install

via cli

What is nameless

Nameless is a sync Model-View-Controller framework. It is developed after the pattern of Ruby on Rails. The developing with nameless is based on the convention over configuration pattern. Nameless covers three data storage, routing and socket connections. Nameless uses Fiber to synchronise the function calls. For routing Nameless uses express.js.

Controller


To manage the routing nameless provides a controller method. All your controllers have to be in the controller directory inside your project. The name of the controller file has to be as followed: NAME_controller.js (replace NAME by your controller name). To register a controller add the following to your app.js: (!important add it between the "controller Start" and "controller End" commends)

  1. name of the controller
  2. a prefix. to change Controllers URL -> prefix/controller_name/method (optional)
  3. list of routes.
 app.controller(name[, prefix], routeList);
/********* Controller Start **************/
app.controller('user', ['index', 'post#login', 'getuser/:id->get<-showuser']).root();
app.controller('team', 'intern', ['post#create']);
/********* Controller End **************/

Route

Routes get registert via the route list parameter. The pattern to register a route is:
[HTTP METHOD]#[URL]->[CONTOLLER METHOD]<-[VIEW] for example:

'del#del/:teamId/:id->createUser<-success'

The Routing rules:

  • Default HTTP method is GET
  • The view ist just a file name and not a path (path/to is not allowed)
  • The <-[view] part is not needed if the view has the same name as the controller method
  • The [URL]-> is not needed if the url is prefx/controller_name/method
  • If the URL is the same but one parameter the folowing syntax can be used:
app.controller('user', ['user:id']);

You can use the nameless-cli tool to handle all routes.

Controller properties

Controllers have four important properties.

  • First one is the model which is a reference to the model with the same name (if existing).
  • Second is the getModel which is a getter to get a reference to all other models.
  • Third is the getSocket to get a socket by id or list of socket in a specified room.
  • Fourth is the wait() function witch has to be be called on external async functions.
  • Fifth is the run witch is the same as the thread.run function.
controller.user = function(req, res, thread){
 var thisModel = this.model.new() // Referenz of the model object with the same name
 // thisModel is a new model-object already saved in the MySQL DB 
 this.getModel('name') // To get other Models
 
 res.redirect = '/home'; // Redirects client to new URL after next() got called
 var parameter = { name: 'No name'};
 res.render('Path/to/jade', parameter); // Renders a view and send to client
 res.callController('controller.method', parameter); // calls another Controller
 
 
 // To call async functions, call the wait mathod of the controller. After your 
 // async function has returned call the threads run method;
 setTimeout(function(){
   // Returns to the last wait.
   thread.run(true) //The Parameter will be the return value of the wait method
 }, 1000); 
 
 this.wait(); // Makes the Contoller Wait. Gives the V8 interpreter Thread free.
}

config/db


To use nameless all MySQL data has to be set. Just fill in user and password information at the config/db.json.

SORRY REST IS COMING UP SOON

Package Sidebar

Install

npm i nameless

Weekly Downloads

10

Version

1.0.7

License

none

Last publish

Collaborators

  • starman