• Stars
    star
    604
  • Rank 74,189 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

an MVC framework for Node

Matador

DEPRECATION WARNING: Matador has been deprecated and is no longer actively maintained. We do not recommend continuing to use Matador.

Build Status

Sane defaults and a simple structure, scaling as your application grows.

Matador is a clean, organized framework for Node.js architected to suit MVC enthusiasts. It gives you a well-defined development environment with flexible routing, easy controller mappings, and basic request filtering. It’s built on open source libraries such as SoyNode for view rendering, and connect.js to give a bundle of other Node server related helpers.

Installation

Get the CLI

$ npm install matador -g

Create an app

$ matador init my-app
$ cd my-app && npm install matador

Start your app

$ node server.js

Dancing with the Bulls

Build on your app

// app/config/routes.js
'/hello/:name': { 'get': 'Home.hello' }

// app/controllers/HomeController.js
hello: function (request, response, name) {
  response.send('hello ' + name)
}

View Rendering

Uses SoyNode to render Closure Templates.

// app/controllers/HomeController.js
this.render(response, 'index', {
  title: 'Hello Bull Fighters'
})
<!-- app/views/layout.soy -->

{namespace views.layout}

/**
 * Renders the index page.
 * @param title Title of the page.
 */
{template .layout autoescape="contextual"}
  <!DOCTYPE html>
  <html>
    <head>
      <meta http-equiv='Content-type' content='text/html; charset=utf-8'>
      <title>{$title}</title>
      <link rel='stylesheet' href='/css/main.css' type='text/css'>
    </head>
    <body>
      {$ij.bodyHtml |noAutoescape}
    </body>
  </html>
{/template}

{namespace views.index}

/**
 * Renders a welcome message.
 * @param title Title of the page
 */
{template .welcome}
  <h1>Welcome to {$title}</h1>
  (rendered with Closure Templates)
{/template}

Routing

The app/config/routes.js file is where you specify an array of tuples indicating where incoming requests will map to a controller and the appropriate method. If no action is specified, it defaults to 'index' as illustrated below:

module.exports = function (app) {
  return {
    '/': 'Home' // maps to ./HomeController.js => index
  , '/admin': 'Admin.show' // maps to ./admin/AdminController.js => show
  }
}

You can also specify method names to routes:

module.exports = function (app) {
  return {
    '/posts': {
      'get': 'Posts.index', // maps to PostsController.js => #index
      'post': 'Posts.create' // maps to PostsController.js => #create
    }
  }
}

How can I organize my Models?

By default, Models are thin with just a Base and Application Model in place. You can give them some meat, for example, and embed Mongo Schemas. See the following as a brief illustration:

// app/models/ApplicationModel.js
module.exports = function (app, config) {
  var BaseModel = app.getModel('Base', true)

  function ApplicationModel() {
    BaseModel.call(this)
    this.mongo = require('mongodb')
    this.mongoose = require('mongoose')
    this.Schema = this.mongoose.Schema
    this.mongoose.connect('mongodb://localhost/myapp')
  }
  util.inherits(ApplicationModel, BaseModel)
  return ApplicationModel
}

Then create, for example, a UserModel.js that extended it...

module.exports = function (app, config) {
  var ApplicationModel = app.getModel('Application', true)

  function UserModel() {
    ApplicationModel.call(this)
    this.DBModel = this.mongoose.model('User', new this.Schema({
        name: { type: String, required: true, trim: true }
      , email: { type: String, required: true, lowercase: true, trim: true }
    }))
  }
  util.inherits(UserModel, ApplicationModel)
  return DBModel

  UserModel.prototype.create = function (name, email, callback) {
    var user = new this.DBModel({
        name: name
      , email: email
    })
    user.save(callback)
  }

  UserModel.prototype.find = function (id, callback) {
    this.DBModel.findById(id, callback)
  }

}

This provides a proper abstraction between controller logic and how your models interact with a database then return data back to controllers.

Take special note that models do not have access to requests or responses, as they rightfully shouldn't.

Model & Controller Inheritance

Matador uses the default node inheritance patterns via util.inherits.

Scaffolding

$ matador controller [name]
$ matador model [name]

Contributing & Development

Questions, pull requests, bug reports are all welcome. Submit them here on Github. When submitting pull requests, please run through the linter to conform to the framework style

$ npm install -d
$ npm run-script lint

Authors

Obviously, Dustin Senos & Dustin Diaz

License

Copyright 2012 Obvious Corporation

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

More Repositories

1

medium-api-docs

Documentation for Medium's OAuth2 API
2,235
star
2

phantomjs

NPM wrapper for installing phantomjs
JavaScript
1,419
star
3

snowflake

Medium's engineering growth visualization tool
JavaScript
725
star
4

sus

simple data-uri stylesheet generator
JavaScript
693
star
5

medium-sdk-nodejs

A NodeJS SDK for Medium's OAuth2 API https://medium.com
JavaScript
345
star
6

opensource

Umbrella project for open source efforts at Medium
290
star
7

medium-policy

Medium’s Policies and Guidelines.
245
star
8

shepherd

Asynchronous dependency injection for node
JavaScript
233
star
9

dynamite

A promise-based DynamoDB client
JavaScript
212
star
10

kew

a lightweight promise library optimized for node.js
JavaScript
211
star
11

medium-wordpress-plugin

The official WordPress plugin for cross-posting to Medium.
PHP
207
star
12

variants

Implementations of a variants (experiments, mods) system. Allows for dynamic flag evaluation based on conditions.
JavaScript
202
star
13

medium-sdk-python

Python SDK for Medium's OAuth2 API
Python
187
star
14

medium-sdk-go

A Golang SDK for Medium's OAuth2 API
Go
139
star
15

sculpt

Manipulate streams.
JavaScript
130
star
16

falkor-archived

HTTP Level Functional Testing Library (nodeunit compatible)
JavaScript
124
star
17

soynode

Utility for working with Closure Templates, aka Soy, from with a node.js application.
JavaScript
91
star
18

local-dynamo

A Node.js wrapper of AWS DynamoDB Local and utilities
JavaScript
88
star
19

pipette

Stream and pipe utilities for Node
JavaScript
43
star
20

oid

Utilities for object identity and hashing
JavaScript
40
star
21

node-bloomd

A NodeJS client for BloomD
JavaScript
35
star
22

medium-logos

Versions of the Medium logo and wordmark in popular formats.
23
star
23

pbnj

JavaScript protocol buffer schema parser and template based code generator
JavaScript
20
star
24

canoe

Node.js 0.10-friendly S3 utility library
JavaScript
20
star
25

picchu

Medium Picchu Kubernetes Operator
Go
18
star
26

daemonsauce

Node module to make it easy to be a proper *nix daemon
JavaScript
17
star
27

draccus

A tool for stashing messages queued up in Amazon's SQS.
JavaScript
10
star
28

zcache

Multi-layer cache API
JavaScript
9
star
29

typ

Type predicates and assertions for Node.
JavaScript
8
star
30

asdf-operator-sdk

Operator SDK plugin for asdf version manager https://github.com/asdf-vm/asdf
Shell
7
star
31

brigade

An S3 bucket proxy (think “bucket brigade”)
Go
2
star
32

nodeunitq

Utilities for nodeunit with promises
JavaScript
2
star
33

medium-transparency

1
star