Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ender-js/ender-js into plugin-compat
Browse files Browse the repository at this point in the history
Conflicts:
	ender.js
  • Loading branch information
fat committed Sep 18, 2011
2 parents 55d083c + 6407b9e commit 921d503
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ If you're building a Mobile Webkit or Android application, it may be a good idea

$._select = function (selector, root) {
return (root || document).querySelectorAll(selector);
};
}

<h3>CommonJS like Module system</h3>

Expand All @@ -77,11 +77,11 @@ Ender exposes a module API which is based on CommonJS Modules spec v1.1.1. There
The first method is require. Require takes a string which corresponds to a package name and returns a package object. For example:


var _ = require('underscore'); //return the underscore object
var _ = require('underscore') //return the underscore object

To register a package use the provide method. The provide method looks like this:

provide("myPackage", myPackageObj);
provide("myPackage", myPackageObj)

These methods are particularly useful when working with microlibs which are already CommonJS compliant (like underscore, backbone, etc.). It is also great when you run into libs who are competing for the same namespace. So for example, if microlib "foo" and microlib "bar" both expose a method <code>baz</code> -- you could use require to gain access to the method being overridden -- as well as set which method you would prefer to be on ender's internal chain... for example:

Expand Down
75 changes: 36 additions & 39 deletions ender.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,86 @@
/*!
* Ender-JS: open module JavaScript framework (client-lib)
* Ender: open module JavaScript framework (client-lib)
* copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat)
* https://ender.no.de
* http://ender.no.de
* License MIT
*/
!function (context) {

// a global object for node.js module compatiblity
// ============================================

context['global'] = context;
context['global'] = context

// Implements simple module system
// losely based on CommonJS Modules spec v1.1.1
// ============================================

var modules = {};
var modules = {}
, old = context.$

function require (identifier) {
var module = modules[identifier] || window[identifier];
if (!module) throw new Error("Requested module '" + identifier + "' has not been defined.");
return module;
var module = modules[identifier] || window[identifier]
if (!module) throw new Error("Requested module '" + identifier + "' has not been defined.")
return module
}

function provide (name, what) {
return modules[name] = what;
return (modules[name] = what)
}

context['provide'] = provide;
context['require'] = require;
context['provide'] = provide
context['require'] = require

// Implements Ender's $ global access object
// =========================================

function aug(o, o2) {
for (var k in o2) {
k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k]);
}
return o;
for (var k in o2) k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k])
return o
}

function boosh(s, r, els) {
// string || node || nodelist || window
// string || node || nodelist || window
if (ender._select && (typeof s == 'string' || s.nodeName || s.length && 'item' in s || s == window)) {
els = ender._select(s, r);
els.selector = s;
} else {
els = isFinite(s.length) ? s : [s];
}
return aug(els, boosh);
els = ender._select(s, r)
els.selector = s
} else els = isFinite(s.length) ? s : [s]
return aug(els, boosh)
}

function ender(s, r) {
return boosh(s, r);
return boosh(s, r)
}

aug(ender, {
_VERSION: '0.2.5',
ender: function (o, chain) {
aug(chain ? boosh : ender, o);
},
fn: boosh // for easy compat with jQuery plugins
});
_VERSION: '0.3.4'
, fn: boosh // for easy compat to jQuery plugins
, ender: function (o, chain) {
aug(chain ? boosh : ender, o)
}
, _select: function (s, r) {
return (r || document).querySelectorAll(s)
}
})

aug(boosh, {
forEach: function (fn, scope, i) {
// opt out of native forEach so we can intentionally call our own scope
// defaulting to the current item and be able to return self
for (i = 0, l = this.length; i < l; ++i) {
i in this && fn.call(scope || this[i], this[i], i, this);
}
for (i = 0, l = this.length; i < l; ++i) i in this && fn.call(scope || this[i], this[i], i, this)
// return self for chaining
return this;
return this
},
$: ender // handy reference to self
});
})

var old = context.$;
ender.noConflict = function () {
context.$ = old;
return this;
};
context.$ = old
return this
}

(typeof module !== 'undefined') && module.exports && (module.exports = ender);
if (typeof module !== 'undefined' && module.exports) module.exports = ender
// use subscript notation as extern for Closure compilation
context['ender'] = context['$'] = context['ender'] || ender;
context['ender'] = context['$'] = context['ender'] || ender

}(this);
24 changes: 24 additions & 0 deletions make.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require('smoosh').config({
"JAVASCRIPT": {
"DIST_DIR": "./"
, "ender": ["./ender.js"]
}
, "JSHINT_OPTS": {
"boss": true
, "forin": false
, "curly": false
, "debug": false
, "devel": false
, "evil": false
, "regexp": false
, "undef": false
, "sub": true
, "white": false
, "indent": 2
, "whitespace": true
, "asi": true
, "laxbreak": true
, "eqeqeq": false
, "eqnull": true
}
}).run().analyze()
29 changes: 19 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"name": "ender-js",
"description": "no-library library",
"version": "0.3.1",
"authors": ["Dustin Diaz <@ded>", "Jacob Thornton <@fat>"],
"keywords": ["ender", "modules", "library", "framework", "packager"],
"main": "./ender.js",
"homepage": "http://ender.no.de",
"engines": {
"node": ">= 0.4.0"
}
"name": "ender-js"
, "description": "no-library library"
, "version": "0.3.4"
, "keywords": ["ender", "modules", "library", "framework", "packager"]
, "main": "./ender.js"
, "homepage": "http://ender.no.de"
, "engines": {
"node": ">= 0.4.0"
}
, "authors": [
"Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
, "Jacob Thornton <jacobthornton@gmail.com> (https://github.com/fat)"
]
, "devDependencies": {
"smoosh": "*"
}
, "scripts": {
"make": "node make.js"
}
}

0 comments on commit 921d503

Please sign in to comment.