Permalink
Browse files

- no more gitmodules!

- add PHONY to Makefile
- create npm dev dependencies
- make better copyright that isn't so lame
- revamp readme with new updated dev dependencies
- bump version
  • Loading branch information...
1 parent 332fa55 commit 1b822b38729a9de4145af77543ce1ac87ec8e13c @ded committed Sep 12, 2011
Showing with 166 additions and 147 deletions.
  1. +1 −0 .gitignore
  2. +0 −6 .gitmodules
  3. +2 −1 Makefile
  4. +99 −75 README.md
  5. +0 −1 build/sink
  6. +0 −1 build/uglify
  7. +4 −5 klass.js
  8. +5 −6 klass.min.js
  9. +11 −11 make/build.js
  10. +18 −14 package.json
  11. +4 −5 src/copyright.js
  12. +2 −2 src/ender.js
  13. +5 −5 test/test.html
  14. +15 −15 test/tests.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
6 .gitmodules
@@ -1,6 +0,0 @@
-[submodule "build/sink"]
- path = build/sink
- url = git://github.com/ded/sink-test.git
-[submodule "build/uglify"]
- path = build/uglify
- url = https://github.com/mishoo/UglifyJS.git
View
3 Makefile
@@ -1,4 +1,5 @@
+.PHONY: boosh test
boosh:
node make/build.js
-tests:
+test:
node test/tests.js
View
174 README.md
@@ -1,122 +1,146 @@
-Klass.js
+Klass
--------
-An expressive, cross platform JavaScript Class provider with a slick, classical interface to prototypal inheritance.
+An expressive, cross platform JavaScript Class provider with a classical interface to prototypal inheritance.
-Interface
+API
---------
<h3>creating a Class...</h3>
- var Person = klass(function (name) {
- this.name = name;
- })
- .statics({
- head: ':)',
- feet: '_|_'
- })
- .methods({
- walk: function () {}
- });
+``` js
+var Person = klass(function (name) {
+ this.name = name
+})
+ .statics({
+ head: ':)',
+ feet: '_|_'
+ })
+ .methods({
+ walk: function () {}
+ })
+```
<h3>Subclassing...</h3>
- var SuperHuman = Person.extend(function (name) {
- // super class is automagically called
- })
- .methods({
- walk: function() {
- this.supr();
- this.fly();
- },
+``` js
+var SuperHuman = Person.extend(function (name) {
+ // super class is automagically called
+})
+ .methods({
+ walk: function() {
+ this.supr()
+ this.fly()
+ },
- fly: function() {}
+ fly: function() {}
- });
+ })
- new SuperHuman('Zelda').walk()
+new SuperHuman('Zelda').walk()
+```
<h3>Object Literals...</h3>
-because sometimes you want to use little curlies ;)
-
- var Foo = klass({
- foo: 0,
- initialize: function() {
- this.foo = 1;
- },
- getFoo: function () {
- return this.foo;
- },
- setFoo: function (x) {
- this.foo = x;
- return this.getFoo();
- }
- });
+``` js
+var Foo = klass({
+ foo: 0,
+ initialize: function() {
+ this.foo = 1
+ },
+ getFoo: function () {
+ return this.foo
+ },
+ setFoo: function (x) {
+ this.foo = x;
+ return this.getFoo()
+ }
+})
+```
*note: initialize will be called on class invocation*
<h3>Implementing...</h3>
because sometimes you want to overwrite OR mixin an instance method
- // note you can optionally pass an object literal to extend too ;)
- var Alien = SuperHuman.extend({
- beam: function() {
- this.supr();
- // beam into space
- }
- });
-
- var Spazoid = new Alien('Zoopo');
-
- if (beamIsDown) {
- Spazoid.implement({
- beam: function() {
- this.supr();
- // fallback to jets
- this.jets();
- }
- });
+``` js
+// note you can optionally pass an object literal to extend too ;)
+var Alien = SuperHuman.extend({
+ beam: function() {
+ this.supr()
+ // beam into space
+ }
+});
+
+var Spazoid = new Alien('Zoopo')
+
+if (beamIsDown) {
+ Spazoid.implement({
+ beam: function() {
+ this.supr()
+ // fallback to jets
+ this.jets()
}
+ })
+}
+```
Environments
------------
Klass is [Common JS](http://commonjs.org) compliant and provides the [Modules 1.1](http://wiki.commonjs.org/wiki/Modules/1.1) interface to allow two flavors of development. See the implementations below:
<h3>browser environment</h3>
- <script src="path/to/klass.js"></script>
- <!-- klass() is exposed to context -->
+``` html
+<script src="path/to/klass.js"></script>
+<!-- klass() is exposed to context -->
- <script type="text/javascript">
- var Foo = klass(fn1);
- var Bar = Foo.extend(fn2);
- Bar.implement({ ... });
- </script>
+<script type="text/javascript">
+ var Foo = klass(fn1)
+ var Bar = Foo.extend(fn2)
+ Bar.implement({ ... })
+</script>
+``` html
<h3>as a module</h3>
- // your-application.js
- var klass = require('path/to/klass');
+``` js
+// your-application.js
+var klass = require('path/to/klass')
- var Foo = klass(...);
-
-Running the tests
------------------
-If you want to see shiny passing tests, run the _tests_ make command
-
- % make tests
+var Foo = klass(...)
+```
Install the Package!
--------------------
By far the easiest way to get started with klass is to simply install the package and hit the ground running!!
- % npm install klass
+ $ npm install klass
// in your Node application
var klass = require('klass')
+Ender compatibility
+-------------
+add `klass` to your ender compliation
+
+ $ ender add klass
+
+Use it:
+
+``` js
+$.klass(...)
+```
+
+Developers
+----------
+
+ $ npm install --dev
+ $ make
+ $ make test
+
+Keep your edits localized to `src/klass.js`
+
Contributors
------------
* [Dustin Diaz](https://github.com/ded/klass/commits/master?author=ded)
* [Jacob Thornton](https://github.com/ded/klass/commits/master?author=fat)
- * Follow our Software [@dedfat](http://twitter.com/dedfat)
1 build/sink
@@ -1 +0,0 @@
-Subproject commit 58bddc040a849f36f840da9b8311ffd0ebd3d6a3
1 build/uglify
@@ -1 +0,0 @@
-Subproject commit 175b4cb8c8ee0fce8566e08b832d82793c186f06
View
9 klass.js
@@ -1,9 +1,8 @@
-/**
- * Klass.js - copyright @dedfat
- * version 1.0
+/*!
+ * klass: a classical JS OOP façade
* https://github.com/ded/klass
- * Follow our software http://twitter.com/dedfat :)
- * MIT License
+ * (c) Dustin Diaz & Jacob Thornton
+ * License MIT
*/
!function (context, f) {
var fnTest = /xyz/.test(function () {
View
11 klass.min.js
@@ -1,8 +1,7 @@
-/**
- * Klass.js - copyright @dedfat
- * version 1.0
+/*!
+ * klass: a classical JS OOP façade
* https://github.com/ded/klass
- * Follow our software http://twitter.com/dedfat :)
- * MIT License
+ * (c) Dustin Diaz & Jacob Thornton
+ * License MIT
*/
-!function(a,b){function j(a,b){function c(){}c[e]=this[e];var d=this,g=new c,h=f(a),j=h?a:this,k=h?{}:a,l=function(){this.initialize?this.initialize.apply(this,arguments):(b||h&&d.apply(this,arguments),j.apply(this,arguments))};l.methods=function(a){i(g,a,d),l[e]=g;return this},l.methods.call(l,k).prototype.constructor=l,l.extend=arguments.callee,l[e].implement=l.statics=function(a,b){a=typeof a=="string"?function(){var c={};c[a]=b;return c}():a,i(this,a,d);return this};return l}function i(a,b,d){for(var g in b)b.hasOwnProperty(g)&&(a[g]=f(b[g])&&f(d[e][g])&&c.test(b[g])?h(g,b[g],d):b[g])}function h(a,b,c){return function(){var d=this.supr;this.supr=c[e][a];var f=b.apply(this,arguments);this.supr=d;return f}}function g(a){return j.call(f(a)?a:d,a,1)}var c=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,d=function(){},e="prototype",f=function(a){return typeof a===b};if(typeof module!="undefined"&&module.exports)module.exports=g;else{var k=a.klass;g.noConflict=function(){a.klass=k;return this},a.klass=g}}(this,"function")
+!function(a,b){function g(a){return j.call(f(a)?a:d,a,1)}function h(a,b,c){return function(){var d=this.supr;this.supr=c[e][a];var f=b.apply(this,arguments);return this.supr=d,f}}function i(a,b,d){for(var g in b)b.hasOwnProperty(g)&&(a[g]=f(b[g])&&f(d[e][g])&&c.test(b[g])?h(g,b[g],d):b[g])}function j(a,b){function c(){}c[e]=this[e];var d=this,g=new c,h=f(a),j=h?a:this,k=h?{}:a,l=function(){this.initialize?this.initialize.apply(this,arguments):(b||h&&d.apply(this,arguments),j.apply(this,arguments))};return l.methods=function(a){return i(g,a,d),l[e]=g,this},l.methods.call(l,k).prototype.constructor=l,l.extend=arguments.callee,l[e].implement=l.statics=function(a,b){return a=typeof a=="string"?function(){var c={};return c[a]=b,c}():a,i(this,a,d),this},l}var c=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,d=function(){},e="prototype",f=function(a){return typeof a===b};if(typeof module!="undefined"&&module.exports)module.exports=g;else{var k=a.klass;g.noConflict=function(){return a.klass=k,this},a.klass=g}}(this,"function")
View
22 make/build.js
@@ -1,14 +1,14 @@
-var fs = require('fs'),
- ugly = require('../build/uglify');
+var fs = require('fs')
+ , ugly = require('uglify-js')
+ , file = fs.readFileSync('./src/klass.js', 'utf-8')
+ , header = fs.readFileSync('./src/copyright.js', 'utf-8')
+ , ast = ugly.parser.parse(file)
+ , min
-var file = fs.readFileSync('./src/klass.js', 'utf-8');
-var header = fs.readFileSync('./src/copyright.js', 'utf-8');
+ast = ugly.uglify.ast_mangle(ast)
+ast = ugly.uglify.ast_squeeze(ast)
-var ast = ugly.parser.parse(file);
-ast = ugly.uglify.ast_mangle(ast);
-ast = ugly.uglify.ast_squeeze(ast);
+min = ugly.uglify.gen_code(ast);
-var min = ugly.uglify.gen_code(ast);
-
-fs.writeFileSync('./klass.min.js', [header, min].join(''), 'utf-8');
-fs.writeFileSync('./klass.js', [header, file].join(''), 'utf-8');
+fs.writeFileSync('./klass.min.js', [header, min].join(''), 'utf-8')
+fs.writeFileSync('./klass.js', [header, file].join(''), 'utf-8')
View
32 package.json
@@ -1,17 +1,21 @@
{
- "name": "klass",
- "description": "Class provider with classical inheritance interface",
- "version": "1.0.6",
- "homepage": "http://dustindiaz.com/klass",
- "authors": ["Dustin Diaz <@ded>", "Jacob Thornton <@fat>"],
- "repository": {
- "type": "git",
- "url": "http://github.com/ded/klass.git"
- },
- "main": "./klass.js",
- "ender": "./src/ender.js",
- "keywords": ["ender", "class", "prototype", "inheritance", "oop"],
- "engines": {
- "node": ">= 0.0.1"
+ "name": "klass"
+ , "description": "Class provider with classical inheritance interface"
+ , "version": "1.1.0"
+ , "homepage": "http://dustindiaz.com/klass"
+ , "author": "Dustin Diaz <polvero@gmail.com> (http://dustindiaz.com)"
+ , "main": "./klass.js"
+ , "ender": "./src/ender.js"
+ , "keywords": ["ender", "class", "prototype", "inheritance", "oop"]
+ , "repository": {
+ "type": "git"
+ , "url": "http://github.com/ded/klass.git"
+ }
+ , "engines": {
+ "node": ">= 0.4.0"
+ }
+ , "devDependencies": {
+ "sink-test": ">= 0.0.8"
+ , "uglify-js": ">= 1.0.0"
}
}
View
9 src/copyright.js
@@ -1,7 +1,6 @@
-/**
- * Klass.js - copyright @dedfat
- * version 1.0
+/*!
+ * klass: a classical JS OOP façade
* https://github.com/ded/klass
- * Follow our software http://twitter.com/dedfat :)
- * MIT License
+ * (c) Dustin Diaz & Jacob Thornton
+ * License MIT
*/
View
4 src/ender.js
@@ -1,3 +1,3 @@
-$.ender({
+ender.ender({
klass: require('klass')
-});
+})
View
10 test/test.html
@@ -3,16 +3,16 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>klass tests</title>
- <link rel="stylesheet" href="../build/sink/src/sink.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script src="../build/sink/src/sink.js"></script>
+ <link rel="stylesheet" href="../node_modules/sink-test/src/sink.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <script src="../node_modules/sink-test/src/sink.js"></script>
<script>
- var klass = function () {
- return 'success';
+ function klass() {
+ return 'success'
}
</script>
<script src="../src/klass.js"></script>
<script>
- $k = klass.noConflict();
+ $k = klass.noConflict()
</script>
</head>
<body>
View
30 test/tests.js
@@ -1,45 +1,45 @@
if (typeof module !== 'undefined' && module.exports) {
- var sink = require('../build/sink'),
- start = sink.start,
- sink = sink.sink;
- var $k = require('../src/klass');
+ var sink = require('sink-test')
+ , start = sink.start
+ , sink = sink.sink
+ , $k = require('../src/klass')
}
else {
sink('no conflict', function (test, ok) {
test('should return old klass back to context', 1, function () {
- ok(klass() == 'success', 'old klass called');
- });
- });
+ ok(klass() == 'success', 'old klass called')
+ })
+ })
}
sink('klass', function (test, ok, before, after) {
- var Base;
+ var Base
before(function () {
Base = $k(function (n) {
- this.n = n;
+ this.n = n
});
});
test('should not call constructor twice', 2, function () {
- var called = 0;
- var thing = $k(function () {
- ok(++called == 1, 'constructor called only once');
+ var called = 0
+ , thing = $k(function () {
+ ok(++called == 1, 'constructor called only once')
if (called == 2) {
clearTimeout(timer);
}
});
- new thing();
+ new thing()
var timer = setTimeout(function () {
ok(true, 'second constructor never called');
- }, 200);
+ }, 200)
});
test('should create a Base class', 1, function () {
- ok((new Base(5).n == 5), 'created Base class');
+ ok((new Base(5).n == 5), 'created Base class')
});
test('should allow optional hash as constructor for methods', 1, function () {

0 comments on commit 1b822b3

Please sign in to comment.