mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-06 00:57:21 -04:00
JSDoc all the things
This commit is contained in:
@@ -9,6 +9,19 @@
|
|||||||
},
|
},
|
||||||
"rules" : {
|
"rules" : {
|
||||||
"new-cap": [0],
|
"new-cap": [0],
|
||||||
"max-params": [1]
|
"max-params": [1],
|
||||||
|
"require-jsdoc": [2, {
|
||||||
|
"require": {
|
||||||
|
"FunctionDeclaration": true,
|
||||||
|
"MethodDefinition": true,
|
||||||
|
"ClassDeclaration": false
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"valid-jsdoc": [2, {
|
||||||
|
"requireParamDescription": false,
|
||||||
|
"requireReturnDescription": false,
|
||||||
|
"requireReturnType": true
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
var configPageHtml = require('./tmp/config-page.html');
|
var configPageHtml = require('./tmp/config-page.html');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
function encodeDataUri(input) {
|
function encodeDataUri(input) {
|
||||||
if (window.btoa) {
|
if (window.btoa) {
|
||||||
return 'data:text/html;base64,' + encodeURIComponent(window.btoa(input));
|
return 'data:text/html;base64,' + encodeURIComponent(window.btoa(input));
|
||||||
@@ -65,6 +69,7 @@ function Clay(config, customFn) {
|
|||||||
/**
|
/**
|
||||||
* Generate the Data URI used by the config Page with settings injected
|
* Generate the Data URI used by the config Page with settings injected
|
||||||
* @param {string} returnTo - used while developing on desktop.
|
* @param {string} returnTo - used while developing on desktop.
|
||||||
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
Clay.prototype.generateUrl = function(returnTo) {
|
Clay.prototype.generateUrl = function(returnTo) {
|
||||||
var settings;
|
var settings;
|
||||||
@@ -91,6 +96,11 @@ Clay.prototype.generateUrl = function(returnTo) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the response from the webviewclosed event data
|
||||||
|
* @param {string} response
|
||||||
|
* @returns {{}}
|
||||||
|
*/
|
||||||
Clay.prototype.getSettings = function(response) {
|
Clay.prototype.getSettings = function(response) {
|
||||||
// Decode and parse config data as JSON
|
// Decode and parse config data as JSON
|
||||||
var settings = JSON.parse(decodeURIComponent(response));
|
var settings = JSON.parse(decodeURIComponent(response));
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ var clayConfig = new ClayConfig(settings, config, $mainForm);
|
|||||||
clayConfig.on(clayConfig.EVENTS.BEFORE_BUILD, function() {
|
clayConfig.on(clayConfig.EVENTS.BEFORE_BUILD, function() {
|
||||||
|
|
||||||
// register components here
|
// register components here
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/heading'));
|
this.registerComponent(require('pebble-clay-components').heading);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/text'));
|
this.registerComponent(require('pebble-clay-components').text);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/footer'));
|
this.registerComponent(require('pebble-clay-components').footer);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/input'));
|
this.registerComponent(require('pebble-clay-components').input);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/color'));
|
this.registerComponent(require('pebble-clay-components').color);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/select'));
|
this.registerComponent(require('pebble-clay-components').select);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/toggle'));
|
this.registerComponent(require('pebble-clay-components').toggle);
|
||||||
this.registerComponent(require('pebble-clay-components/dist/components/submit'));
|
this.registerComponent(require('pebble-clay-components').submit);
|
||||||
});
|
});
|
||||||
|
|
||||||
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
|
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ var manipulators = require('./manipulators');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ClayEvents
|
* @extends ClayEvents
|
||||||
* @param settings
|
* @param {{}} settings - setting that were set from a previous session
|
||||||
* @param config
|
* @param {[]|{}} config
|
||||||
* @param $rootContainer
|
* @param {M} $rootContainer
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function ClayConfig(settings, config, $rootContainer) {
|
function ClayConfig(settings, config, $rootContainer) {
|
||||||
@@ -39,10 +39,11 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add item(s) to the config
|
* Add item(s) to the config
|
||||||
* @param {Clay~ConfigItem|array} items
|
* @param {Clay~ConfigItem|array} item
|
||||||
* @param {M} [$container]
|
* @param {M} $container
|
||||||
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
var _addItems = function(item, $container) {
|
function _addItems(item, $container) {
|
||||||
if (Array.isArray(item)) {
|
if (Array.isArray(item)) {
|
||||||
item.forEach(function(item) {
|
item.forEach(function(item) {
|
||||||
_addItems(item, $container);
|
_addItems(item, $container);
|
||||||
@@ -73,14 +74,15 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
|
|
||||||
$container.add(clayItem.$element);
|
$container.add(clayItem.$element);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Throws if the config has not been built yet.
|
||||||
* @param {string} fnName
|
* @param {string} fnName
|
||||||
|
* @returns {boolean}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var _checkBuilt = function(fnName) {
|
function _checkBuilt(fnName) {
|
||||||
if (!_isBuilt) {
|
if (!_isBuilt) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'ClayConfig not built. build() must be run before ' +
|
'ClayConfig not built. build() must be run before ' +
|
||||||
@@ -88,7 +90,7 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
self.EVENTS = {
|
self.EVENTS = {
|
||||||
/**
|
/**
|
||||||
@@ -134,8 +136,8 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} key
|
* @param {string} type
|
||||||
* @returns {[ClayItem]}
|
* @returns {Array.<ClayItem>}
|
||||||
*/
|
*/
|
||||||
self.getItemsByType = function(type) {
|
self.getItemsByType = function(type) {
|
||||||
_checkBuilt('getItemsByType');
|
_checkBuilt('getItemsByType');
|
||||||
@@ -188,6 +190,7 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
* @param {function} component.manipulator.get - get manipulator method
|
* @param {function} component.manipulator.get - get manipulator method
|
||||||
* @param {{}} component.defaults - template defaults
|
* @param {{}} component.defaults - template defaults
|
||||||
* @param {function} [component.initialize] - method to scaffold the component
|
* @param {function} [component.initialize] - method to scaffold the component
|
||||||
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
ClayConfig.registerComponent = function(component) {
|
ClayConfig.registerComponent = function(component) {
|
||||||
var _component = _.copyObj(component);
|
var _component = _.copyObj(component);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var $ = require('../vendor/minified/minified').$;
|
var $ = require('../vendor/minified/minified').$;
|
||||||
var _ = require('../vendor/minified/minified')._;
|
var _ = require('../vendor/minified/minified')._;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches event methods to the context.
|
* Attaches event methods to the context.
|
||||||
* Call with ClayEvents.call(yourObject, $eventTarget)
|
* Call with ClayEvents.call(yourObject, $eventTarget)
|
||||||
@@ -19,13 +20,19 @@ function ClayEvents($eventTarget) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var _transformEventNames = function(events) {
|
function _transformEventNames(events) {
|
||||||
return events.split(' ').map(function(event) {
|
return events.split(' ').map(function(event) {
|
||||||
return '|' + event.replace(/^\|/, '');
|
return '|' + event.replace(/^\|/, '');
|
||||||
}).join(' ');
|
}).join(' ');
|
||||||
};
|
}
|
||||||
|
|
||||||
var _registerEventProxy = function(handler, proxy) {
|
/**
|
||||||
|
* @param {function} handler
|
||||||
|
* @param {function} proxy
|
||||||
|
* @returns {function}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function _registerEventProxy(handler, proxy) {
|
||||||
var eventProxy = _.find(_eventProxies, function(item) {
|
var eventProxy = _.find(_eventProxies, function(item) {
|
||||||
return item.handler === handler ? item : null;
|
return item.handler === handler ? item : null;
|
||||||
});
|
});
|
||||||
@@ -35,13 +42,18 @@ function ClayEvents($eventTarget) {
|
|||||||
_eventProxies.push(eventProxy);
|
_eventProxies.push(eventProxy);
|
||||||
}
|
}
|
||||||
return eventProxy.proxy;
|
return eventProxy.proxy;
|
||||||
};
|
}
|
||||||
|
|
||||||
var _getEventProxy = function(handler) {
|
/**
|
||||||
|
* @param {function} handler
|
||||||
|
* @returns {function}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function _getEventProxy(handler) {
|
||||||
return _.find(_eventProxies, function(item) {
|
return _.find(_eventProxies, function(item) {
|
||||||
return item.handler === handler ? item.proxy : null;
|
return item.handler === handler ? item.proxy : null;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach an event listener to the item.
|
* Attach an event listener to the item.
|
||||||
@@ -60,8 +72,8 @@ function ClayEvents($eventTarget) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the given event handler.
|
* Remove the given event handler. NOTE: This will remove the handler from all
|
||||||
* @see {@link http://minifiedjs.com/api/off.html|$.off()}
|
* registered events
|
||||||
* @param {function} handler
|
* @param {function} handler
|
||||||
* @returns {ClayEvents}
|
* @returns {ClayEvents}
|
||||||
*/
|
*/
|
||||||
@@ -74,11 +86,10 @@ function ClayEvents($eventTarget) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger an event. This proxies minified.js' trigger.
|
* Trigger an event.
|
||||||
* @param {string} name - a single event name to trigger
|
* @param {string} name - a single event name to trigger
|
||||||
* @param {object} [eventObj] - an object to pass to the event handler,
|
* @param {object} [eventObj] - an object to pass to the event handler,
|
||||||
* provided the handler does not have custom arguments.
|
* provided the handler does not have custom arguments.
|
||||||
* @see {@link http://minifiedjs.com/api/trigger.html|.trigger()}
|
|
||||||
* @returns {ClayEvents}
|
* @returns {ClayEvents}
|
||||||
*/
|
*/
|
||||||
self.trigger = function(name, eventObj) {
|
self.trigger = function(name, eventObj) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var ClayEvents = require('./clay-events');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ClayEvents
|
* @extends ClayEvents
|
||||||
* @param config
|
* @param {Clay~ConfigItem} config
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function ClayItem(config) {
|
function ClayItem(config) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
* @param {boolean} [descriptor.writable]
|
* @param {boolean} [descriptor.writable]
|
||||||
* @param {function} [descriptor.get]
|
* @param {function} [descriptor.get]
|
||||||
* @param {function} [descriptor.set]
|
* @param {function} [descriptor.set]
|
||||||
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
module.exports.updateProperties = function(obj, descriptor) {
|
module.exports.updateProperties = function(obj, descriptor) {
|
||||||
Object.getOwnPropertyNames(obj).forEach(function(prop) {
|
Object.getOwnPropertyNames(obj).forEach(function(prop) {
|
||||||
|
|||||||
+5
-7
@@ -7,14 +7,12 @@ var ClayItem = require('../src/scripts/lib/clay-item');
|
|||||||
var ClayConfig = require('../src/scripts/lib/clay-config');
|
var ClayConfig = require('../src/scripts/lib/clay-config');
|
||||||
var idCounter = 0;
|
var idCounter = 0;
|
||||||
|
|
||||||
var componentRegistry = require('../src/scripts/lib/component-registry');
|
|
||||||
|
|
||||||
// add some components to the registry to test
|
// add some components to the registry to test
|
||||||
ClayConfig.registerComponent(require('pebble-clay-components/dist/components/text'));
|
ClayConfig.registerComponent(require('pebble-clay-components').text);
|
||||||
ClayConfig.registerComponent(require('pebble-clay-components/dist/components/input'));
|
ClayConfig.registerComponent(require('pebble-clay-components').input);
|
||||||
ClayConfig.registerComponent(require('pebble-clay-components/dist/components/toggle'));
|
ClayConfig.registerComponent(require('pebble-clay-components').toggle);
|
||||||
ClayConfig.registerComponent(require('pebble-clay-components/dist/components/footer'));
|
ClayConfig.registerComponent(require('pebble-clay-components').footer);
|
||||||
ClayConfig.registerComponent(require('pebble-clay-components/dist/components/select'));
|
ClayConfig.registerComponent(require('pebble-clay-components').select);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string|{}} config
|
* @param {string|{}} config
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
var assert = require('chai').assert;
|
var assert = require('chai').assert;
|
||||||
var _ = require('../../../src/scripts/vendor/minified/minified')._;
|
var _ = require('../../../src/scripts/vendor/minified/minified')._;
|
||||||
var textComponent = require('pebble-clay-components/dist/components/text');
|
var textComponent = require('pebble-clay-components').text;
|
||||||
var componentRegistry = require('../../../src/scripts/lib/component-registry');
|
var componentRegistry = require('../../../src/scripts/lib/component-registry');
|
||||||
var checkReadOnly = require('../../test-utils').checkReadOnly;
|
var checkReadOnly = require('../../test-utils').checkReadOnly;
|
||||||
var fixtures = require('../../fixture');
|
var fixtures = require('../../fixture');
|
||||||
|
|||||||
@@ -12,10 +12,14 @@ var ctx;
|
|||||||
|
|
||||||
var eventCounter = 0;
|
var eventCounter = 0;
|
||||||
|
|
||||||
var createEventName = function() {
|
/**
|
||||||
|
* Create a unique event name
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function createEventName() {
|
||||||
eventCounter++;
|
eventCounter++;
|
||||||
return 'test-event-' + eventCounter;
|
return 'test-event-' + eventCounter;
|
||||||
};
|
}
|
||||||
|
|
||||||
describe('ClayEvents', function() {
|
describe('ClayEvents', function() {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var assert = require('chai').assert;
|
|||||||
/**
|
/**
|
||||||
* @param {Object} object
|
* @param {Object} object
|
||||||
* @param {Array} properties
|
* @param {Array} properties
|
||||||
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
module.exports.checkReadOnly = function(object, properties) {
|
module.exports.checkReadOnly = function(object, properties) {
|
||||||
properties.forEach(function(property) {
|
properties.forEach(function(property) {
|
||||||
|
|||||||
Reference in New Issue
Block a user