mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-31 22:36:56 -04:00
strip out components into separate repo
This commit is contained in:
@@ -19,6 +19,7 @@ var ClayItem = require('./clay-item');
|
||||
var utils = require('../lib/utils');
|
||||
var ClayEvents = require('./clay-events');
|
||||
var componentStore = require('./component-registry');
|
||||
var manipulators = require('./manipulators');
|
||||
|
||||
/**
|
||||
* @extends ClayEvents
|
||||
@@ -154,20 +155,8 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
return _settings;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a component to Clay. This must be called prior to .build();
|
||||
* @param {{}} component - the clay component to register
|
||||
* @param {string} component.name - the name of the component
|
||||
* @param {string} component.template - HTML template to use for the component
|
||||
* @param {{}} component.manipulator - methods to attach to the component
|
||||
* @param {function} component.manipulator.set - set manipulator method
|
||||
* @param {function} component.manipulator.get - get manipulator method
|
||||
* @param {{}} component.defaults - template defaults
|
||||
* @param {function} [component.initialize] - method to scaffold the component
|
||||
*/
|
||||
self.registerComponent = function(component) {
|
||||
componentStore[component.name] = component;
|
||||
};
|
||||
// @todo maybe don't do this and force the static method
|
||||
self.registerComponent = ClayConfig.registerComponent;
|
||||
|
||||
/**
|
||||
* Build the config page. This must be run before any of the get methods can be run
|
||||
@@ -189,4 +178,23 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a component to Clay. This must be called prior to .build();
|
||||
* @param {{}} component - the clay component to register
|
||||
* @param {string} component.name - the name of the component
|
||||
* @param {string} component.template - HTML template to use for the component
|
||||
* @param {string|{}} component.manipulator - methods to attach to the component
|
||||
* @param {function} component.manipulator.set - set manipulator method
|
||||
* @param {function} component.manipulator.get - get manipulator method
|
||||
* @param {{}} component.defaults - template defaults
|
||||
* @param {function} [component.initialize] - method to scaffold the component
|
||||
*/
|
||||
ClayConfig.registerComponent = function(component) {
|
||||
var _component = _.copyObj(component);
|
||||
if (typeof _component.manipulator === 'string') {
|
||||
_component.manipulator = manipulators[component.manipulator];
|
||||
}
|
||||
componentStore[_component.name] = _component;
|
||||
};
|
||||
|
||||
module.exports = ClayConfig;
|
||||
|
||||
@@ -14,14 +14,14 @@ var ClayEvents = require('./clay-events');
|
||||
function ClayItem(config) {
|
||||
var self = this;
|
||||
|
||||
var _itemType = componentRegistry[config.type];
|
||||
var _component = componentRegistry[config.type];
|
||||
|
||||
if (!_itemType) {
|
||||
if (!_component) {
|
||||
throw new Error('the component: ' + config.type + ' is not registered. ' +
|
||||
'Make sure to register it with ClayConfig.registerComponent()');
|
||||
}
|
||||
|
||||
var _templateData = _.extend({}, _itemType.defaults, config);
|
||||
var _templateData = _.extend({}, _component.defaults, config);
|
||||
|
||||
/** @type {string|null} */
|
||||
self.id = config.id || null;
|
||||
@@ -33,7 +33,7 @@ function ClayItem(config) {
|
||||
self.config = config;
|
||||
|
||||
/** @type {M} */
|
||||
self.$element = HTML(_.formatHtml(_itemType.template, _templateData));
|
||||
self.$element = HTML(_.formatHtml(_component.template, _templateData));
|
||||
|
||||
/** @type {M} */
|
||||
self.$manipulatorTarget = self.$element.select('[data-manipulator-target]');
|
||||
@@ -48,8 +48,8 @@ function ClayItem(config) {
|
||||
* @returns {ClayItem}
|
||||
*/
|
||||
self.initialize = function() {
|
||||
if (typeof _itemType.initialize === 'function') {
|
||||
_itemType.initialize.apply(self, arguments);
|
||||
if (typeof _component.initialize === 'function') {
|
||||
_component.initialize.apply(self, arguments);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
@@ -58,7 +58,7 @@ function ClayItem(config) {
|
||||
ClayEvents.call(self, self.$manipulatorTarget);
|
||||
|
||||
// attach the manipulator methods to the clayItem
|
||||
_.eachObj(_itemType.manipulator, function(methodName, method) {
|
||||
_.eachObj(_component.manipulator, function(methodName, method) {
|
||||
self[methodName] = method.bind(self);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user