<?xml version="1.0" ?>
<?xml-stylesheet type='text/xsl' href='interface.xsl'?>
<interface uri="http://gfxmonk.net/dist/0install/obligate.js.xml" xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
	<name>obligate.js</name>
	<summary>javascript module implementation with Zero Install integration</summary>
	<publish mode="default" xmlns="http://gfxmonk.net/dist/0install"/>
	<description>
#Obligate.js
_It's a synonym of `require`, did you know?_

**Obligate is a simple javascript helper that allows you to write modular javascript and serve it up to the browser effortlessly**

Organising and including all your javascript for a web pages is super lame. *especially* if you want to write javascript code that works both in a browser and in a server-side environment like node.js (wasn't that kind of the point of using javascript everywhere?)

Here's what you're going to do. You're going to write javascript just as you would (or do) for a [commonJS][] module system:

1. add your module's top-level variables as members of the global `exports` object.
2. use `var mod = require(&quot;my/awesome/module&quot;)` when you need to use another module

Then, you run `obligate combine [root-js-folder]` to create `obligate-modules.js` which now contains the code for *all* modules.

In your client-side code, include `obligate-modules.js`. Then, just run `Obligate.install()` to install obligate's `require` function globally. If you don't want to install it globally, you can instead call `Obligate.require()` as needed.

Tada! Your code works in both node and the browser without doing anything special. Except of course you can't use any of node's builtin modules in the browser. I'm not [_crazy_][browserify], you know.

#The _obligatory_ integration
_of an already awkward metaphor_

If you use [Zero Install][0install] (you _should_!), you get all your dependencies included for free. Just:

1. run `obligate gather [your-feed-file]` and it'll create a `0cache` directory that combines everything from all of your dependencies (and your own app) that would end up on `$NODE_PATH` at runtime (this is configurable if you don't use `$NODE_PATH`)
2. run `obligate combine 0cache` as above.

#What the FAQ?

### Why don't you use [some other javascript dependency mananger], it's great!

I already have an excellent dependency manager ([Zero Install][0install]) that works for any language, while most people who code in the same languages as I do use something like the set of `apt-get`, `npm`, `pip`, `setuptools`, `gem`, `cabal`, `ivy` and a whole bunch of manual steps because these tools can't handle anything out of their own language's domain. You really think we need _more_ dependency managers that can only do one thing?

### [node-browserify][browserify] already supports `require()` for browsers

I know, that's what prompted me to do this! It looks pretty big and complicated though, and it uses `npm` (see above question for reasons that's bad). Obligate is tiny (less that 100 lines of javascript), and has simple (optional) integration with Zero Install. But you should try out browserify if you like its features (it includes implementations of many builtin node libraries).

### What's missing?

Relative requires don't work yet, and `index.js` isn't dealt with correctly. Patches welcome, the code is pretty simple.

### (experimental) apollo support

Obligate has tentative support for stratified javascript on [oni apollo](http://onilabs.com/). It's mostly the same as for vanilla javascript, except that:

 - it adds an `obligate:` hub - instead of `require(&quot;foo&quot;)`, you should do `require(&quot;obligate:foo&quot;)`
 - you should pass `--apollo` into `obligate combine` to tell it to spit out an apollo-compatible `obligate-modules.js` file.

Note that to have the `obligate:` hub available in node-based command-line scripts, you'll need to add `obligate-modules.js` to your `$APOLLO_INIT` path (or require it explicitly).

If you just want to alias the `obligate:` hub to `nodejs:` on the console (i.e all your dependencies are available via `$NODE_PATH`), you can add `lib/nodejs-alias.sjs` to your `$APOLLO_INIT` path instead of generating an `obligate-modules/js` file.


[tartare-0bundle]: http://gfxmonk.net/dist/0install/tartare-0bundle.xml
[browserify]:      https://github.com/substack/node-browserify
[commonJS]:        http://www.commonjs.org/specs/modules/1.0/
[0install]:        http://0install.net/
	</description>
	<homepage>http://github.com/gfxmonk/obligate.js</homepage>
	<rich-description xmlns="http://gfxmonk.net/dist/0install">
		<div xmlns="http://www.w3.org/1999/xhtml">
			<h1 id="obligate.js">Obligate.js</h1>
			<p>
				<em>It's a synonym of <code>require</code>, did you know?</em>
			</p>
			<p>
				<strong>Obligate is a simple javascript helper that allows you to write modular javascript and serve it up to the browser effortlessly</strong>
			</p>
			<p>Organising and including all your javascript for a web pages is super lame. <em>especially</em> if you want to write javascript code that works both in a browser and in a server-side environment like node.js (wasn't that kind of the point of using javascript everywhere?)</p>
			<p>Here's what you're going to do. You're going to write javascript just as you would (or do) for a <a href="http://www.commonjs.org/specs/modules/1.0/">commonJS</a> module system:</p>
			<ol style="list-style-type: decimal">
				<li>add your module's top-level variables as members of the global <code>exports</code> object.</li>
				<li>use <code>var mod = require(&quot;my/awesome/module&quot;)</code> when you need to use another module</li>
			</ol>
			<p>Then, you run <code>obligate combine [root-js-folder]</code> to create <code>obligate-modules.js</code> which now contains the code for <em>all</em> modules.</p>
			<p>In your client-side code, include <code>obligate-modules.js</code>. Then, just run <code>Obligate.install()</code> to install obligate's <code>require</code> function globally. If you don't want to install it globally, you can instead call <code>Obligate.require()</code> as needed.</p>
			<p>Tada! Your code works in both node and the browser without doing anything special. Except of course you can't use any of node's builtin modules in the browser. I'm not <a href="https://github.com/substack/node-browserify"><em>crazy</em></a>, you know.</p>
			<h1 id="the-obligatory-integration">The <em>obligatory</em> integration</h1>
			<p>
				<em>of an already awkward metaphor</em>
			</p>
			<p>If you use <a href="http://0install.net/">Zero Install</a> (you <em>should</em>!), you get all your dependencies included for free. Just:</p>
			<ol style="list-style-type: decimal">
				<li>run <code>obligate gather [your-feed-file]</code> and it'll create a <code>0cache</code> directory that combines everything from all of your dependencies (and your own app) that would end up on <code>$NODE_PATH</code> at runtime (this is configurable if you don't use <code>$NODE_PATH</code>)</li>
				<li>run <code>obligate combine 0cache</code> as above.</li>
			</ol>
			<h1 id="what-the-faq">What the FAQ?</h1>
			<h3 id="why-dont-you-use-some-other-javascript-dependency-mananger-its-great">Why don't you use [some other javascript dependency mananger], it's great!</h3>
			<p>I already have an excellent dependency manager (<a href="http://0install.net/">Zero Install</a>) that works for any language, while most people who code in the same languages as I do use something like the set of <code>apt-get</code>, <code>npm</code>, <code>pip</code>, <code>setuptools</code>, <code>gem</code>, <code>cabal</code>, <code>ivy</code> and a whole bunch of manual steps because these tools can't handle anything out of their own language's domain. You really think we need <em>more</em> dependency managers that can only do one thing?</p>
			<h3 id="node-browserify-already-supports-require-for-browsers"><a href="https://github.com/substack/node-browserify">node-browserify</a> already supports <code>require()</code> for browsers</h3>
			<p>I know, that's what prompted me to do this! It looks pretty big and complicated though, and it uses <code>npm</code> (see above question for reasons that's bad). Obligate is tiny (less that 100 lines of javascript), and has simple (optional) integration with Zero Install. But you should try out browserify if you like its features (it includes implementations of many builtin node libraries).</p>
			<h3 id="whats-missing">What's missing?</h3>
			<p>Relative requires don't work yet, and <code>index.js</code> isn't dealt with correctly. Patches welcome, the code is pretty simple.</p>
			<h3 id="experimental-apollo-support">(experimental) apollo support</h3>
			<p>Obligate has tentative support for stratified javascript on <a href="http://onilabs.com/">oni apollo</a>. It's mostly the same as for vanilla javascript, except that:</p>
			<ul>
				<li>it adds an <code>obligate:</code> hub - instead of <code>require(&quot;foo&quot;)</code>, you should do <code>require(&quot;obligate:foo&quot;)</code></li>
				<li>you should pass <code>--apollo</code> into <code>obligate combine</code> to tell it to spit out an apollo-compatible <code>obligate-modules.js</code> file.</li>
			</ul>
			<p>Note that to have the <code>obligate:</code> hub available in node-based command-line scripts, you'll need to add <code>obligate-modules.js</code> to your <code>$APOLLO_INIT</code> path (or require it explicitly).</p>
			<p>If you just want to alias the <code>obligate:</code> hub to <code>nodejs:</code> on the console (i.e all your dependencies are available via <code>$NODE_PATH</code>), you can add <code>lib/nodejs-alias.sjs</code> to your <code>$APOLLO_INIT</code> path instead of generating an <code>obligate-modules/js</code> file.</p>
		</div>
	</rich-description>
	<group main="obligate">
		<command name="run" path="obligate"/>
		<requires interface="http://repo.roscidus.com/python/python"/>
		<requires interface="http://0install.net/2007/interfaces/ZeroInstall.xml">
			<environment insert="" mode="prepend" name="PATH"/>
			<environment insert="" mode="prepend" name="PYTHONPATH"/>
		</requires>
		<environment insert="lib" mode="prepend" name="OBLIGATE_LIB"/>
		<environment insert="" mode="prepend" name="PATH"/>
		<implementation id="sha1new=1a4446b14b453046313fb7599d7f67327328d653" released="2011-09-11" version="0.1">
			<manifest-digest sha256="1e131b36c35a240fe0249608659d3bd80771b7d668717dedd8ef1ae1ec26d0c5"/>
			<archive href="http://gfxmonk.net/dist/0install/obligate.js/obligate.js-0.1.tgz" size="3712"/>
		</implementation>
		<implementation id="sha1new=cbd04646de184e70fa2e297e53deec2af04b6aaa" released="2011-09-27" version="0.2">
    <manifest-digest sha256="8c209194f024e9288ed89ebc87f7e911709545ec4fbbd4122955c203c072b70a"/>
    <archive href="http://gfxmonk.net/dist/0install/obligate.js/obligate.js-0.2.tgz" size="3636"/>
  </implementation>
	</group>
</interface>
<!-- Base64 Signature
iEYEABECAAYFAk6BhbEACgkQ/lhgK1iJTtJuvwCcCV10eGpljBgzrwCgnh9rCjezLI4AniYRY40O
wRUkhM0HK9fh/9kp90Xc

-->
