Comparing version 0.1.56 to 0.1.57
@@ -30,2 +30,3 @@ /** | ||
registerPlugin: plugins.registerPlugin, | ||
registerComponents: runtime.registerComponents, | ||
parse: parser.parse, | ||
@@ -32,0 +33,0 @@ render: runtime.render, |
@@ -214,2 +214,18 @@ /** | ||
/** | ||
* Given an array of element names, register the custom | ||
* elements so that a user can make them accessible | ||
* @param elemNames | ||
*/ | ||
function registerComponents(elemNames) { | ||
if (!elemNames) { return; } | ||
var elemNameDashCase, elemNameCamelCase; | ||
for (var i = 0; i < elemNames.length; i++) { | ||
elemNameDashCase = elemNames[i]; | ||
elemNameCamelCase = utils.dashToCamelCase(elemNameDashCase); | ||
elems[elemNameCamelCase] = makeElem(elemNameDashCase); | ||
} | ||
} | ||
/** | ||
* Create functions for all standard HTML element | ||
@@ -233,3 +249,4 @@ */ | ||
makeElem: makeElem, | ||
registerComponents: registerComponents, | ||
init: init | ||
}; |
@@ -71,2 +71,21 @@ /** | ||
/** | ||
* Convert a string with dashes to camel case | ||
* @param dashCase | ||
*/ | ||
function dashToCamelCase(dashCase) { | ||
if (!dashCase) { return dashCase; } | ||
var parts = dashCase.split('-'); | ||
var camelCase = parts[0]; | ||
var part; | ||
for (var i = 1; i < parts.length; i++) { | ||
part = parts[i]; | ||
camelCase += part.substring(0, 1).toUpperCase() + part.substring(1); | ||
} | ||
return camelCase; | ||
} | ||
/** | ||
* Equivalent to _.extend() function | ||
@@ -153,3 +172,4 @@ * @returns {*|{}} | ||
isEmptyObject: isEmptyObject, | ||
dashToCamelCase: dashToCamelCase, | ||
extend: extend | ||
}; |
{ | ||
"name": "jyt", | ||
"version": "0.1.56", | ||
"version": "0.1.57", | ||
"description": "JavaScript Your Templates", | ||
@@ -24,6 +24,6 @@ "main": "lib/jyt.js", | ||
"devDependencies": { | ||
"batter": "0.0.21", | ||
"batter": "0.0.22", | ||
"gulp": "^3.8.11", | ||
"taste": "^0.1.52" | ||
"taste": "^0.1.53" | ||
} | ||
} |
@@ -65,2 +65,18 @@ /** | ||
}); | ||
describe('registerComponents()', function () { | ||
it('should do nothing if nothing passed in', function () { | ||
var expected = target.elems.length || 0; | ||
target.registerComponents(); | ||
var actual = target.elems.length || 0; | ||
actual.should.equals(expected); | ||
}); | ||
it('should register a set of components', function () { | ||
var components = ['onetwo', 'one-two-three']; | ||
target.registerComponents(components); | ||
taste.should.exist(target.elems.onetwo, 'onetwo does not exist'); | ||
taste.should.exist(target.elems.oneTwoThree, 'oneTwoThree does not exist'); | ||
}); | ||
}); | ||
}); |
@@ -66,2 +66,20 @@ /** | ||
describe('dashToCamelCase()', function () { | ||
it('should return empty value untouched', function () { | ||
taste.should.not.exist(target.dashToCamelCase()); | ||
}); | ||
it('should return string untouched if no dashes', function () { | ||
var str = 'blahbla234'; | ||
target.dashToCamelCase(str).should.equal(str); | ||
}); | ||
it('should replace all dashes and do camel casing', function () { | ||
var str = 'one-two-three-four'; | ||
var expected = 'oneTwoThreeFour'; | ||
var actual = target.dashToCamelCase(str); | ||
actual.should.equal(expected); | ||
}); | ||
}); | ||
describe('extend()', function () { | ||
@@ -68,0 +86,0 @@ it('should extend an objet with one other', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31169
829