GithubHelp home page GithubHelp logo

trinte's Introduction

Build Status Dependency Status NPM version

TrinteJS Javascript MVC Framework for NodeJS

A MVC boilerplate for ExpressJS backed by CaminteJS and Bootstrap.

Description

This application help to create a Webapp MVC style in few minutes. TrinteJS tuned for ExpressJS 3.x, jQuery 2.x and Twitter Bootstrap 3.x.

Dependencies

Installation

Installation is done using the NodeJS Package Manager (npm). If you don't have npm installed on your system you can download it from npmjs.org To install trinte:

$ sudo npm install trinte -g

Table of contents

Usage overview:

  $ trinte [command(s)] [argument(s)]

Command format:

  cluster *port=3000                      : Run the application using the cluster module.
  server *port=3000                       : Run the application as a server.
  test                                    : Run all tests.
  test unit|integration|functional        : Run a particular type of test.
  g, script help *<name>                  : This help script, optional script name for additional help.
  g, script <name> *args                  : Run a script with <name>, with params

  Available scripts (generators):

  controller, create-controller  args     : Creates a controller
  model, create-model  args               : Creates a model
  test, create-test  args                 : Creates a test
  view, create-view  args                 : Creates a view
  crud, generate-all  args                : Creates a scaffold
  help                                    : Show help

Create and initialize Application

  $ trinte create-app HelloWorld    # Create application
  $ cd HelloWorld && npm -l install # intall dependencies

  # generate scaffold
  $ trinte script generate-all User name email password active
  $ trinte server                   # running server (default in cluster mode)

Create Application with Theme

Available 7 themes default, black, blue, green, orange, pink, violet. Default theme violet.

  $ trinte init AppName theme

Shows help:

  // Shows help
  $ trinte help
  $ trinte script help generate-all

Create a scaffold:

  // Creates all (model, views, controller, tests)
  $ trinte script generate-all User
  or the same
  $ trinte g crud User

  // create User model and etc. with fields: name, email, password, active
  $ trinte script generate-all User name email password active:boolean
  • See all valid field types here.

Create a model:

  // format: trinte script create-model [model name] [field(s)]

  // Create Post model without fields
  $ trinte script create-model Post
  or the same
  $ trinte g model Post

  // create User model with fields name, email, password, active: Boolean
  $ trinte script create-model User name email password active:boolean
  • See all valid field types here.

Create a controller:

  // Creates a controller
  $ trinte script create-controller Post
  or the same
  $ trinte g controller Post

Create a views:

  // Creates views
  $ trinte script create-view Post
  or the same
  $ trinte g view Post

Create a test:

  // Creates tests
  $ trinte script create-test HelloWorld

Create a scaffold or other scripts with namespace:

  // Creates all (model, views, controller, tests)
  // all scripts will be generated in the folder 'namespase' name
  // as example app/admin/*
  $ trinte script generate-all admin#User
  or the same
  $ trinte g crud admin#User

  // create User model and etc. with fields: name, email, password, active
  $ trinte script generate-all admin#User name email password active:boolean
  • See all valid field types here.

Runs server:

  $ trinte                         // Runs server in cluster mode
  $ trinte server                  // Runs server in simple mode
  $ trinte cluster                 // Runs server in cluster mode

  # Runs server in simple mode on different port
  $ trinte server port=3000

Field types:

Following are all valid field types.

  String
  Number
  Date
  Boolean
  Text

Learn more on CaminteJS.

Created application

Application configuration

/config/configuration.js

module.exports = {
    port : 3000,
    session: {
        maxAge : 8640000,
        key : "trinte",
        secret : "Web-based Application"
    },
    parser : {
        encoding : "utf-8",
        keepExtensions : true
    } ...

Database configuration

/config/database.js

module.exports = {
    db: {
        driver     : "mongoose",
        host       : "localhost",
        port       : "27017",
        username   : "",
        password   : "",
        database   : "trinte-dev"
    } ...

Directory structure

On initialization directories tree generated, like that:

.
|-- config
|   |-- configuration.js
|   |-- database.js
|   |-- development.js
|   |-- production.js
|   `-- test.js
|-- tools
|   `-- inflection.js
|-- app
|   |-- models
|   |   |-- Category.js
|   |   |-- Post.js
|   |   `-- User.js
|   |-- controllers
|   |   |-- AppController.js
|   |   `-- PostsController.js
|   |-- heplers
|   |   |-- ApplicationHelper.js
|   |   `-- ModelsHelper.js
|   |-- lib
|   |   `-- pager.js
|   `-- views
|       |-- app
|       |   `-- index.ejs
|       `-- posts
|       |   |-- edit.ejs
|       |   |-- index.ejs
|       |   `-- new.ejs
|       |-- errors
|       |   |-- 404.ejs
|       }   `-- 500.ejs
|       |-- default_layout.ejs
|       |-- error_layout.ejs
|       `-- messages.ejs
|-- public
|   |-- css
|   |   `-- ...
|   |-- js
|   |   `-- ...
|   `-- img
|   |   `-- ...
|-- package.json
|-- app.js
`-- app-cluster.js

Routing

/config/routes.js

Features

  • resourceful routes
  • generic routes
  • url helpers
  • namespaces
  • custom helper names / paths for resources
  • named parameters in url helpers

Named route params

Example:

map.get('/test/:param1/:param2', 'controller#action');
map.pathTo.test({param1: 'foo', param2: 'bar'}); // '/test/foo/bar'

Singleton resources

Example:

map.resource('post');

Will generate the following routes:

method    route            controller#action   helper method
--------------------------------------------------------------------------
GET       /posts           posts#index         pathTo.posts()
GET       /post/:id        posts#show          pathTo.show_post(id)
POST      /post            posts#create        pathTo.create_posts()
GET       /post/new        posts#new           pathTo.new_post()
GET       /post/edit/:id   posts#edit          pathTo.edit_post(id)
DELETE    /post/:id        posts#destroy       pathTo.destroy_post(id)
PUT       /post/:id        posts#update        pathTo.update_post(id)
DELETE    /posts           posts#destroyall    pathTo.destroy_posts()

Singleton resources can also have nested resources. For example:

map.resource('users', function(users) {
  users.resources('posts');
});

Will generate the following routes:

method   route                         controller#action   helper method
--------------------------------------------------------------------------
GET     /users/:user_id/posts           posts#index        pathTo.users_posts(user_id)
GET     /users/:user_id/post/:id        posts#show         pathTo.show_users_post(user_id, id)
POST    /users/:user_id/post            posts#create       pathTo.create_users_posts(user_id)
GET     /users/:user_id/post/new        posts#new          pathTo.new_users_post(user_id)
GET     /users/:user_id/post/edit/:id   posts#edit         pathTo.edit_users_post(user_id, id)
DELETE  /users/:user_id/post/:id        posts#destroy      pathTo.destroy_users_post(user_id, id)
PUT     /users/:user_id/post/:id        posts#update       pathTo.update_users_post(user_id, id)
DELETE  /users/:user_id/posts           posts#destroyall   pathTo.destroy_users_posts(user_id)

Params

app.param('id', /^[A-Za-z0-9]+$/);
app.param('controller', /^[a-zA-Z]+$/);
app.param('action', /^[a-zA-Z]+$/);
app.param('format', /^[a-zA-Z]+$/);
app.param('from', /^\d+$/);
app.param('to', /^\d+$/);

Used Middleware

Recommend extensions

  • CaminteJS - Cross-db ORM for NodeJS
  • 2CO - is the module that will provide nodejs adapters for 2checkout API payment gateway.

In the Wild

The following projects use TrinteJS.

If you are using TrinteJS in a project, app, or module, get on the list below by getting in touch or submitting a pull request with changes to the README.

Startups & Apps

Credits

  • Node.js: Amazing javascript asynchronous IO library, install manually.
  • NPM: Node package manager, used to install:
  • Express.Js: Application Framework for Node.js
  • Caminte.Js: Node.JS ORM for Any DB.
  • EJS: Embedded Javascript Templating Library.
  • jQuery: Best Javascript Library.
  • Bootstrap: Powerful front-end CSS/JS framework
  • Glyphicons: Fantastic library of precisely prepared monochromatic icons and symbols.

Author

Aleksej Gordejev ([email protected]).

Copyright & License

(The MIT License)

Copyright (c) 2012 Aleksej Gordejev [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

trinte's People

Contributors

ashokgelal avatar ben-lin avatar biggora avatar cliftonc avatar srod avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.