|
|
@@ -3,35 +3,40 @@ var config = require('./config'),
|
|
|
directives = require('./directives'),
|
|
|
filters = require('./filters')
|
|
|
|
|
|
-var seeds = {}
|
|
|
-
|
|
|
function buildSelector () {
|
|
|
- config.selector = Object.keys(module.exports).forEach(function (directive) {
|
|
|
-
|
|
|
- })
|
|
|
+ config.selector = Object.keys(directives).map(function (directive) {
|
|
|
+ return '[' + config.prefix + '-' + directive + ']'
|
|
|
+ }).join()
|
|
|
}
|
|
|
|
|
|
-module.exports = {
|
|
|
- seeds: seeds,
|
|
|
- seed: function (id, opts) {
|
|
|
- seeds[id] = opts
|
|
|
- },
|
|
|
- directive: function (name, fn) {
|
|
|
- Directives[name] = fn
|
|
|
- },
|
|
|
- filter: function (name, fn) {
|
|
|
- Filters[name] = fn
|
|
|
- },
|
|
|
- config: function (opts) {
|
|
|
- for (var prop in opts) {
|
|
|
- if (prop !== 'selector') {
|
|
|
- config[prop] = opts[prop]
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- plant: function () {
|
|
|
- for (var id in seeds) {
|
|
|
- seeds[id] = new Seed(id, seeds[id])
|
|
|
+Seed.config = config
|
|
|
+buildSelector()
|
|
|
+
|
|
|
+Seed.extend = function (opts) {
|
|
|
+ var Spore = function () {
|
|
|
+ Seed.apply(this, arguments)
|
|
|
+ for (var prop in this.extensions) {
|
|
|
+ var ext = this.extensions[prop]
|
|
|
+ this.scope[prop] = (typeof ext === 'function')
|
|
|
+ ? ext.bind(this)
|
|
|
+ : ext
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+ Spore.prototype = Object.create(Seed.prototype)
|
|
|
+ Spore.prototype.extensions = {}
|
|
|
+ for (var prop in opts) {
|
|
|
+ Spore.prototype.extensions[prop] = opts[prop]
|
|
|
+ }
|
|
|
+ return Spore
|
|
|
+}
|
|
|
+
|
|
|
+Seed.directive = function (name, fn) {
|
|
|
+ directives[name] = fn
|
|
|
+ buildSelector()
|
|
|
+}
|
|
|
+
|
|
|
+Seed.filter = function (name, fn) {
|
|
|
+ filters[name] = fn
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = Seed
|