node package manager


Nail is a cutomizable, framework-independent tool for js/coffee class creation.

nail - simple modular classes

Nail is a simple but flexble tool for creating coffe/java script classes.

Nail uses the powefull nail-core API to handlethe propertiesmethods and iheritance with seperate replacable modules.

Class definitions in nail are well strcutured and tool friendly.

This Document

To ensure that the examle code is up to date it is run as a test- This requires underscore, should and an instrumented version of nail. In your productive code nail = require 'nail' should be enough.

nail    = require '../coverage/instrument/lib/module.js'
should  = require 'should'
_       = require 'underscore'


The nail concept:

  • class definitions are objects
  • every key in the definition is a class
  • every aspect of a class has a seperate block

Nail uses the API defined by nail-core and modules from nail-common.


The following code defines the class Person and adds it to exports and the namespace 'my-module'. exports, 'my-module', Person:
    firstName:  null
    lastName:   null
      get:-> "#{@lastName}, #{@firstName}"
    greet: -> return "hello, #{@fullName}"

Now our package exports the constructor for Person.

describe 'Person', ->
  it 'is a function', ->
    (_.isFunction exports.Person)

Values are injected into the new Instance.

dalia = new exports.Person
  firstName: 'Dalia'
  lastName:  'Scarlet'
it 'injects data', ->
  dalia.firstName.should.equal 'Dalia'
  dalia.lastName.should.equal  'Scarlet'
it 'creates properties', ->
  dalia.fullName.should.equal  'Scarlet, Dalia'
it 'creates methods', ->
  dalia.greet().should.equal 'hello, Scarlet, Dalia'

Using namespaces will give every class a unique name.

This simple generic factory functionm creates instance of Person from JSON.

it "can be loaded from json", ->
  sampleJSON ="""
                "type": "my-module.Person",
                  "firstName": "Nick",
                  "lastName":  "Pudel"
  loadObject = (data) -> new nail.lib[data.type]

  nick  = loadObject(JSON.parse sampleJSON)
  nick.firstName.should.equal 'Nick'
  nick.lastName.should.equal 'Pudel'
  nick.fullName.should.equal "Pudel, Nick"

Install with npm:

npm install nail

Clone with GIT:

git clone

Head here → docs