Skip to content
Permalink
Browse files

Updated spaces.

  • Loading branch information...
robbz committed Mar 13, 2013
1 parent fb6dc31 commit a12ddda13f7f9927771890559af3c371a9624ff9
Showing with 199 additions and 200 deletions.
  1. +0 −1 Gruntfile.js
  2. +22 −22 lib/flexigin.js
  3. +69 −69 lib/load.js
  4. +50 −50 lib/resolve.js
  5. +20 −20 test/flexiginTests.js
  6. +38 −38 test/resolveTests.js
@@ -35,7 +35,6 @@ module.exports = function (grunt) {
}
});

//grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');

@@ -1,30 +1,30 @@
(function(window) {
var fx = function(components, options, callback) {
if (typeof components === 'function') {
components = '/';
callback = components;
}
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
components = fx.resolve(components);
fx.load(components, options, callback);
};
var fx = function(components, options, callback) {
if (typeof components === 'function') {
components = '/';
callback = components;
}
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
components = fx.resolve(components);
fx.load(components, options, callback);
};

fx.set = function(key, value) {
fx[key] = value;
};
fx.get = function(key) {
return fx[key];
}
fx.set = function(key, value) {
fx[key] = value;
};
fx.get = function(key) {
return fx[key];
}

window.fx = fx;
window.fx = fx;

if (typeof define !== 'undefined') {
if (typeof define !== 'undefined') {
define(function () {
return fx;
});
}
}
})(window);
@@ -1,75 +1,75 @@
(function(fx, $) {
var load = function(components, options, callback) {
options = options || {};
var load = function(components, options, callback) {
options = options || {};

var query = fx.query();
$.each(components, function(key, component) {
query.add(component, options);
});
if (query.isEmpty()) {
callback();
return;
}
query.run(options, callback);
};
var query = fx.query();
$.each(components, function(key, component) {
query.add(component, options);
});
if (query.isEmpty()) {
callback();
return;
}
query.run(options, callback);
};

fx.loaded = [];
var query = function() {
var query = [];
var loader = this;
var deferreds = getDeferreds();
return {
add: function(component, options) {
if (fx.loaded.indexOf(component) !== -1) {
return;
}
query.push(deferreds[component.type](component.url, options));
loader.loaded.push(component);
},
run: function(options, callback) {
var onLoad = function(data) {
if (typeof ko !== 'undefined' && typeof options.viewModel !== 'undefined') {
var viewModel = options.viewModel();
if (viewModel.hasOwnProperty('init')) {
viewModel.init();
}
ko.applyBindings(viewModel, $(options.container || 'body')[0]);
}
callback(null, data);
};
$.when.apply($, query)
.done(onLoad)
.fail(callback);
},
length: function() {
return query.length;
},
isEmpty: function() {
return query.length === 0;
}
}
};
fx.loaded = [];
var query = function() {
var query = [];
var loader = this;
var deferreds = getDeferreds();
return {
add: function(component, options) {
if (fx.loaded.indexOf(component) !== -1) {
return;
}
query.push(deferreds[component.type](component.url, options));
loader.loaded.push(component);
},
run: function(options, callback) {
var onLoad = function(data) {
if (typeof ko !== 'undefined' && typeof options.viewModel !== 'undefined') {
var viewModel = options.viewModel();
if (viewModel.hasOwnProperty('init')) {
viewModel.init();
}
ko.applyBindings(viewModel, $(options.container || 'body')[0]);
}
callback(null, data);
};
$.when.apply($, query)
.done(onLoad)
.fail(callback);
},
length: function() {
return query.length;
},
isEmpty: function() {
return query.length === 0;
}
}
};

var getDeferreds = function() {
return {
html: function(url, options) {
var onLoad = function(html) {
$(options.container || 'body').append(html);
};
return $.get(url).done(onLoad);
},
css: function(url) {
var onLoad = function(css) {
$('head').append('<style>' + css + '</style>');
};
return $.get(url).done(onLoad);
},
js: function(url) {
return $.getScript(url);
}
};
};
var getDeferreds = function() {
return {
html: function(url, options) {
var onLoad = function(html) {
$(options.container || 'body').append(html);
};
return $.get(url).done(onLoad);
},
css: function(url) {
var onLoad = function(css) {
$('head').append('<style>' + css + '</style>');
};
return $.get(url).done(onLoad);
},
js: function(url) {
return $.getScript(url);
}
};
};

fx.load = load;
fx.query = query;
fx.load = load;
fx.query = query;
})(fx, jQuery);
@@ -1,57 +1,57 @@
(function(fx, $) {
var url = function() {
return {
build: function(component, type) {
component = trimSlash(component);
return (fx.get('route') || '/{component}/{type}/')
.replace('{component}', component)
.replace('{type}', type);
},
getExtension: function(url) {
var parts = url.split('/');
return parts[parts.length - 1];
}
}
};
var url = function() {
return {
build: function(component, type) {
component = trimSlash(component);
return (fx.get('route') || '/{component}/{type}/')
.replace('{component}', component)
.replace('{type}', type);
},
getExtension: function(url) {
var parts = url.split('/');
return parts[parts.length - 1];
}
}
};

var resolve = function(components) {
var url = fx.url();
var extensions = ['js', 'css', 'html'];
var createComponent = function(component, extension) {
return {
url: url.build(component, extension),
type: extension
};
}
var resolve = function(components) {
var url = fx.url();
var extensions = ['js', 'css', 'html'];
var createComponent = function(component, extension) {
return {
url: url.build(component, extension),
type: extension
};
}

var resolved = [];
if (typeof components === 'string') {
components = [components];
}
$.each(components, function(key, component) {
if (typeof component === 'string') {
var extension = url.getExtension(component);
var resolved = [];
if (typeof components === 'string') {
components = [components];
}
$.each(components, function(key, component) {
if (typeof component === 'string') {
var extension = url.getExtension(component);

// If we got an extensionless url, create a component for each extension.
if (extensions.indexOf(extension) === -1) {
$.each(extensions, function(key, extension) {
resolved.push(createComponent(component, extension));
});
} else {
component = component.substr(0, component.lastIndexOf('/'));
resolved.push(createComponent(component, extension));
}
} else {
resolved.push(component);
}
});
return resolved;
};
// If we got an extensionless url, create a component for each extension.
if (extensions.indexOf(extension) === -1) {
$.each(extensions, function(key, extension) {
resolved.push(createComponent(component, extension));
});
} else {
component = component.substr(0, component.lastIndexOf('/'));
resolved.push(createComponent(component, extension));
}
} else {
resolved.push(component);
}
});
return resolved;
};

var trimSlash = function(text) {
return text.replace(/^\/+|\/+$/g, '');
};
var trimSlash = function(text) {
return text.replace(/^\/+|\/+$/g, '');
};

fx.resolve = resolve;
fx.url = url;
fx.resolve = resolve;
fx.url = url;
})(fx, jQuery);
@@ -1,25 +1,25 @@
suite('flexigin', function() {

suite('fx', function() {
test('calls the main function', function(done) {
fx('test/components/user/js', function(err) {
expect(err).to.be(null);
done();
});
});
suite('fx', function() {
test('calls the main function', function(done) {
fx('test/components/user/js', function(err) {
expect(err).to.be(null);
done();
});
});

test('returns a 404 if the url does not exist', function(done) {
fx('test/components/user1/js', function(err) {
expect(err.status).to.be(404);
done();
});
});
});
test('returns a 404 if the url does not exist', function(done) {
fx('test/components/user1/js', function(err) {
expect(err.status).to.be(404);
done();
});
});
});

suite('get', function() {
test('returns the value passed in set', function() {
fx.set('route', '/basepath/');
expect(fx.get('route')).to.be('/basepath/');
});
});
suite('get', function() {
test('returns the value passed in set', function() {
fx.set('route', '/basepath/');
expect(fx.get('route')).to.be('/basepath/');
});
});
});

0 comments on commit a12ddda

Please sign in to comment.
You can’t perform that action at this time.