Skip to content

Instantly share code, notes, and snippets.

View jrburke's full-sized avatar

James Burke jrburke

View GitHub Profile
@jrburke
jrburke / a.js
Created November 23, 2011 05:25
Common module boilerplate that sets export value
// Define a module "a" that depends another module called "b". If
// that other module also uses this type of boilerplate, then
// in the browser, it will create a global .b that is used below.
// If you do not want to support the browser global path, then you
// can remove the `root` use and the passing `this` as the first arg to
// the top function.
(function(root, factory) {
if (typeof exports === 'object') {
@jrburke
jrburke / builder.js
Created December 1, 2011 19:07
Multiple single file builds using one "build script" for requirejs optimizer
//Load the requirejs optimizer
var requirejs = require('./path/to/r.js'),
//Set up basic config, include config that is
//common to all the optimize() calls.
basConfig = {
baseUrl: './some/path',
paths: {
//whatever is neded globally.
}
};
@jrburke
jrburke / build.js
Created December 22, 2011 05:58
Doing multiple almond builds with a nodejs script, example
//Download jquery.js and place it in the build, do not use require-jquery.js
//in the build, since each of the build layers just needs almond and not the
//full require.js file.
//This file is run in nodejs to do the build: node build.js
//Load the requirejs optimizer
var requirejs = require('./r.js');
//Set up basic config, include config that is
//common to all the requirejs.optimize() calls.
var FakeAPI = (function(){
var api = {
add: null,
addWithCallback: null
}
function makeMethod(method) {
return function() {
var context = this;
var args = arguments;
@jrburke
jrburke / amdconfig.md
Created January 18, 2012 00:52
Rough draft of common config understood by loaders

Attempt to list some possible standard AMD loader configuration values.

An AMD loader is not required to implement all of these configuration values, but if it does provide a capability that is satisfied by these configuration values, it should use these configuration values and structures.

baseUrl

String: Indicates the root used for ID-to-path resolutions. Relative paths are relative to the current working directory. In web browsers, the current working directory is the directory containing the web page running the script.

@jrburke
jrburke / gist:1731666
Created February 3, 2012 18:40
kumascript with promises
//based on:
//https://github.com/lmorchard/kumascript/blob/master/lib/kumascript/templates.js
var q = require('q');
var EJSTemplate = ks_utils.Class(BaseTemplate, {
initialize: function (options) {
this._super('initialize', arguments);
this.template = require('ejs').compile(this.options.source);
},
@jrburke
jrburke / gist:3012544
Created June 28, 2012 17:02
override print for r.js optimizer
var requirejs = require('requirejs'),
foo = require('foo');
requirejs.define('node/print', [], function () {
function print(msg) {
//Do whatever you want with the msg here.
//If you use node dependencies, can just require
//them outside of this closure.
foo(msg);
}
@jrburke
jrburke / gist:3020525
Created June 29, 2012 20:43
Module concatenation format

Module concatenation format:

JS module systems, whether commonjs/node, AMD or es harmony modules all allow specifying dependencies inline. Example from node:

var a = require('a'),
    b = require('b');
@jrburke
jrburke / gist:3021061
Created June 29, 2012 22:26
volofile
/*jslint regexp: true */
/*global define, console, process */
var connect = require( "connect" ),
crypto = require('crypto'),
fs = require('fs'),
path = require('path'),
buildDir = 'www-built',
pagesDir = 'www-ghpages';
@jrburke
jrburke / gist:3056350
Created July 5, 2012 20:55
loading built test stuff
if (someConditionIsTrueFromQueryString) {
require(['testmain'], function () {
require(['test'], function (test) {
});
});
} else {
require(['test'], function (test) {