-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
var isArray = require('lodash-node/compat/objects/isArray'); | ||
This comment has been minimized.
Sorry, something went wrong.
MajorBreakfast
Contributor
|
||
|
||
function Plugin(name, ext) { | ||
this.name = name; | ||
this.ext = ext; | ||
} | ||
|
||
function Registry(plugins) { | ||
this.registry = {}; | ||
this.availablePlugins = plugins; | ||
} | ||
|
||
module.exports = Registry; | ||
|
||
Registry.prototype.load = function(type) { | ||
return this.registry[type].reduce(function(actual, plugin) { | ||
if(this.availablePlugins.hasOwnProperty(plugin.name)) { | ||
return plugin; | ||
} else { | ||
return actual; | ||
} | ||
}.bind(this), null); | ||
}; | ||
|
||
|
||
Registry.prototype.add = function(type, name, extension) { | ||
var registered = this.registry[type]; | ||
|
||
if(isArray(registered)) { | ||
registered.push(new Plugin(name, extension)); | ||
} else { | ||
this.registry[type] = [new Plugin(name, extension)]; | ||
} | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
var assert = require('../../helpers/assert'); | ||
var PluginRegistry = require('../../../lib/preprocessors/registry'); | ||
|
||
var pkg, registry; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
describe('Plugin Loader', function() { | ||
|
||
beforeEach(function() { | ||
pkg = { | ||
devDependencies: { | ||
'broccoli-sass': 'latest', | ||
'broccoli-coffee': 'latest' | ||
} | ||
}; | ||
registry = new PluginRegistry(pkg.devDependencies); | ||
registry.add('css', 'broccoli-sass'); | ||
registry.add('css', 'broccoli-ruby-sass'); | ||
}); | ||
|
||
it('returns first plugin when only one', function() { | ||
var plugin = registry.load('css'); | ||
assert.equal(plugin.name, 'broccoli-sass'); | ||
}); | ||
|
||
it('returns the correct plugin when there are more than one', function() { | ||
registry.availablePlugins = { 'broccoli-ruby-sass': 'latest' }; | ||
var plugin = registry.load('css'); | ||
assert.equal(plugin.name, 'broccoli-ruby-sass'); | ||
}); | ||
|
||
it('returns plugin of the correct type', function() { | ||
registry.add('js', 'broccoli-coffee'); | ||
var plugin = registry.load('js'); | ||
assert.equal(plugin.name, 'broccoli-coffee'); | ||
}); | ||
|
||
it('returns null when no plugin available for type', function() { | ||
registry.add('blah', 'not-available'); | ||
var plugin = registry.load('blah'); | ||
assert.notOk(plugin, 'loaded a plugin that wasn\'t in dependencies'); | ||
}); | ||
}); |
3 comments
on commit 59ddbdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joefiorini mind submitting a PR next time? It will help the "hive mind" to digest the change and make sure that everyone is aware of the direction ember-cli
is moving to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great, this will be a great API entry point for ember-cli addons :)
why
.call()
?