Skip to content

Commit

Permalink
Add dist/ to repository
Browse files Browse the repository at this point in the history
  • Loading branch information
passy committed May 10, 2013
1 parent 9e0a58a commit fac002b
Show file tree
Hide file tree
Showing 17 changed files with 1,785 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
dist
.tmp
components/
coverage/
22 changes: 22 additions & 0 deletions dist/amd/hyperagent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define(
["hyperagent/resource","hyperagent/properties","hyperagent/curie","hyperagent/config","exports"],
function(__dependency1__, __dependency2__, __dependency3__, config, __exports__) {
"use strict";
var Resource = __dependency1__.Resource;
var LazyResource = __dependency1__.LazyResource;
var LinkResource = __dependency1__.LinkResource;
var Properties = __dependency2__.Properties;
var CurieStore = __dependency3__.CurieStore;

function configure(name, value) {
config[name] = value;
}


__exports__.Resource = Resource;
__exports__.Properties = Properties;
__exports__.LazyResource = LazyResource;
__exports__.LinkResource = LinkResource;
__exports__.CurieStore = CurieStore;
__exports__.configure = configure;
});
17 changes: 17 additions & 0 deletions dist/amd/hyperagent/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
define(
["hyperagent/miniscore"],
function(_) {
"use strict";

var config = {};

// Provide defaults in case we're in a browser.
if (typeof window !== 'undefined') {
config.ajax = window.$ && window.$.ajax.bind(window.$);
config.defer = window.Q && window.Q.defer;
config._ = _;
}


return config;
});
71 changes: 71 additions & 0 deletions dist/amd/hyperagent/curie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
define(
["exports"],
function(__exports__) {
"use strict";
/**
* A simple data storage to register and expand CURIES:
* http://www.w3.org/TR/curie/
*/
function CurieStore() {
this._store = {};
}

CurieStore.prototype.register = function register(key, value) {
this._store[key] = URITemplate(value);
};

CurieStore._split = function (value) {
var index = value.indexOf(':');
var curie = value.substring(0, index);
var ref = value.substring(index + 1);

if (value === -1 || value === (value.length - 1)) {
return null;
}

return [curie, ref];
};

/**
* Boolean if the store is empty.
*/
CurieStore.prototype.empty = function empty() {
return Object.keys(this._store).length === 0;
};

/**
* Expands a CURIE value or returns the value back if it cannot be
* expanded.
*/
CurieStore.prototype.expand = function expand(value) {
var template;
var curie = CurieStore._split(value);

if (!curie) {
return value;
}

template = this._store[curie[0]];
if (template === undefined) {
return value;
}

return template.expand({ rel: curie[1] });
};

/**
* A boolean indicator whether a value can (probably) be expanded.
*/
CurieStore.prototype.canExpand = function canExpand(value) {
var curie = CurieStore._split(value);

if (!curie) {
return false;
}

return this._store[curie[0]] !== undefined;
};


__exports__.CurieStore = CurieStore;
});
23 changes: 23 additions & 0 deletions dist/amd/hyperagent/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define(
["hyperagent/config","exports"],
function(c, __exports__) {
"use strict";

function loadAjax(options) {
var deferred = c.defer();
c.ajax(c._.extend(options, {
headers: {
'Accept': 'application/hal+json, application/json, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest'
},
success: deferred.resolve,
error: deferred.reject,
dataType: 'html' // We don't want auto-converting
}));

return deferred.promise;
}


__exports__.loadAjax = loadAjax;
});
124 changes: 124 additions & 0 deletions dist/amd/hyperagent/miniscore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
define(
[],
function() {
"use strict";
/*jshint strict:false */
/**
* A minimal collection of underscore functions used in the project without
* pre-ES5 compatibility.
*/

var _ = {};
var breaker = {};

_.each = _.forEach = function (obj, iterator, context) {
if (obj === null || obj === undefined) {
return;
}

if (obj.forEach === Array.prototype.forEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) {
return;
}
}
} else {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (iterator.call(context, obj[key], key, obj) === breaker) {
return;
}
}
}
}
};

_.identity = function (val) {
return val;
};

_.any = function (obj, iterator, context) {
var result = false;
if (!iterator) {
iterator = _.identity;
}

if (obj === null || obj === undefined) {
return result;
}
if (obj.some === Array.prototype.some) {
return obj.some(iterator, context);
}

_.each(obj, function (value, index, list) {
if (result || (result = iterator.call(context, value, index, list))) {
return breaker;
}
});
return !!result;
};

_.contains = function (obj, target) {
if (obj === null || obj === undefined) {
return false;
}

if (obj.indexOf === Array.prototype.indexOf) {
return obj.indexOf(target) !== -1;
}

return _.any(obj, function (value) {
return value === target;
});
};

_.pick = function (obj) {
var copy = {};
var keys = Array.prototype.concat.apply(Array.prototype,
Array.prototype.slice.call(arguments, 1));

_.each(keys, function (key) {
if (key in obj) {
copy[key] = obj[key];
}
});
return copy;
};

_.extend = function (obj) {
_.each(Array.prototype.slice.call(arguments, 1), function (source) {
if (source) {
for (var prop in source) {
obj[prop] = source[prop];
}
}
});
return obj;
};

_.defaults = function (obj) {
_.each(Array.prototype.slice.call(arguments, 1), function (source) {
if (source) {
for (var prop in source) {
if (obj[prop] === null || obj[prop] === undefined) {
obj[prop] = source[prop];
}
}
}
});
return obj;
};

_.clone = function (obj) {
if (obj !== Object(obj)) {
return obj;
}

return Array.isArray(obj) ? obj.slice() : _.extend({}, obj);
};


return _;
});
42 changes: 42 additions & 0 deletions dist/amd/hyperagent/properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
define(
["hyperagent/config","exports"],
function(c, __exports__) {
"use strict";

function Properties(response, options) {
// XXX: This function is too large. Let's figure out if we could instead build
// one large object for defineProperties first and call on that in the end
// and if that would make the code cleaner.
options = options || {};
if (Object(response) !== response) {
throw new Error('The Properties argument must be an object.');
}
// Overwrite the response object with the original properties if provided.
c._.extend(response, options.original || {});

var skipped = ['_links', '_embedded'];
Object.keys(response).forEach(function (key) {
if (!c._.contains(skipped, key)) {
this[key] = response[key];
}
}.bind(this));

// Set up curies
var curies = options.curies;
if (!curies) {
return;
}

Object.keys(this).forEach(function (key) {
if (curies.canExpand(key)) {
Object.defineProperty(this, curies.expand(key), {
enumerable: true, /// XXX
value: this[key]
});
}
}.bind(this));
}


__exports__.Properties = Properties;
});
Loading

0 comments on commit fac002b

Please sign in to comment.