Skip to content

readmill/m.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

m.js
====

A module system for websites.

Usage
-----

Development and production builds are available from the releases[1] section
of the repository. Download and extract the m.zip file it contains the
m.js (development) and m.min.js (production) builds ready for use.

The whole library minified and gzipped currently weighs in at around 3.5kb.

[1]: https://github.com/readmill/m.js/releases

Dependencies
------------

m requires that the jQuery[1] and underscore[2] libraries are available on
the page before the m.js script is included.


m also works using Zepto[3], a lightweight alternative to jQuery designed
for modern browsers and mobile devices. Just include Zepto instead of jQuery
in your document.

__NOTE:__ One known caveat with using Zepto is that the .teardown() method on
a module will not be called when a dom element is removed from the document.
You'll need to manage this yourself or port the special events API to Zepto.

[1]: http://jquery.com
[2]: http://underscorejs.org
[3]: http://zeptojs.com/

Development
-----------

It's very simple, hack on the code, ensure the lint and tests pass and submit
a pull request. Rinse and repeat.

To install the developer packages you'll need node and npm installed on your
machine. Then run:

    $ npm install

To run the linter:

    $ make lint

Production
----------

To produce a concatenated build run:

    $ make build

To produce a development and production (minified) build ready for distribution run:

    $ make package

This will output a `pkg` directory containing the development, production files
as well as a zip file containing both files and the license. make package will
also output filesize info for the two files and a minified gzipped example for
reference.

Testing
-------

The entire test suite is run on Travis CI on each push you can check the current
state at any time by visiting: https://travis-ci.org/readmill/m.js

To run the suite locally using phantomjs[1] run:

    $ make test

To run only a subset of tests a `GREP` variable can be passed to make.

    $ make test GREP=build

Alternatively tests can be run in the browser:

    $ make test

And open the browser at http://localhost:8000. You can choose a port by providing
a `PORT` env variable to make.

    $ make test PORT=4567

Finally, you can run the tests using an alternative DOM library such as Zepto
by passing the `DOM_LIBRARY` variable to make.

    $ make test DOM_LIBRARY=zepto

[1]: http://phantomjs.org

### Writing specs

These should be placed in the test/specs directory and the filename should
be the module name ending with `-spec.js`.

### Libraries

- Mocha[1]: Test runner, we use the `bdd` style.
- Chai[2]: Assertion library, we use `assert` style.
- Sinon[3]: Mocking and stubbing library.

[1]: http://visionmedia.github.com/mocha/
[2]: http://chaijs.com/api/assert/
[3]: http://sinonjs.org/docs

### Let Helper

There is also a `this.let` helper that allows you to assign lazy loaded properties
within your tests. For example:

    this.let('subject', 4);
    this.subject; // => 4

    this.let('subject', Math.random());
    this.subject; // => 0.1856299617793411
    this.subject; // => 0.1856299617793411

    this.let('fixture', document.createElement('div'));
    this.let('subject', function () {
      // Same scope available within lazy functions.
      this.fixture.nodeName === 'DIV';
    });

License
-------

Available under the MIT license. See LICENSE file for details.