-
Notifications
You must be signed in to change notification settings - Fork 5
/
README
133 lines (85 loc) · 3.39 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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.