Comparing version 0.0.2 to 0.0.3
@@ -24,2 +24,3 @@ 'use strict'; | ||
IsoForm.prototype.build = build; | ||
IsoForm.prototype.compile = compile; | ||
@@ -41,2 +42,3 @@ function addItemType(name, template) { | ||
this._registry.put(name, { template: template }); | ||
this._isRegistryDirty = true; | ||
} | ||
@@ -75,2 +77,3 @@ | ||
this._registry.put(name, { template: template, closeTemplate: closeTemplate }); | ||
this._isRegistryDirty = true; | ||
} | ||
@@ -85,8 +88,15 @@ | ||
function build(formSchema) { | ||
var buildFunc = this.ajv.compile(this.schema); | ||
this.validSchema = buildFunc.call(this, formSchema); | ||
function compile() { | ||
this._buildFunc = this.ajv.compile(this.schema); | ||
this._isRegistryDirty = false; | ||
return this; | ||
} | ||
function build(formSchema) { | ||
var form = { html: '' }; | ||
if (!this._buildFunc || this._isRegistryDirty) this.compile(); | ||
form.isValidSchema = this._buildFunc.call(form, formSchema); | ||
return form; | ||
} | ||
function objWithType(type) { | ||
@@ -93,0 +103,0 @@ return { |
{ | ||
"name": "iso-form", | ||
"version": "0.0.2", | ||
"description": "TBC", | ||
"version": "0.0.3", | ||
"description": "An isometric, schema based form generator that can be used in the client, on the server, or even to pre-compile forms in the build phase. This is the core library that is used to register form types.", | ||
"main": "lib/iso-form.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -16,3 +16,3 @@ # iso-form | ||
isoForm.build({ | ||
var form = isoForm.build({ | ||
type:'group', | ||
@@ -24,3 +24,4 @@ items: [ | ||
// isoForm.html == '<div><input id="test"></div>'; | ||
// form.isValidSchema == true; | ||
// form.html == '<div><input id="test"></div>'; | ||
@@ -27,0 +28,0 @@ ``` |
@@ -32,5 +32,5 @@ 'use strict'; | ||
it('should create build function', function () { | ||
isoForm.build({ type:'test' }); | ||
isoForm.validSchema.should.equal(true); | ||
isoForm.html.should.equal('TEST'); | ||
var form = isoForm.build({ type:'test' }); | ||
form.isValidSchema.should.equal(true); | ||
form.html.should.equal('TEST'); | ||
}); | ||
@@ -40,11 +40,11 @@ | ||
isoForm.addItemType('stringtest', 'A STRING TEMPLATE'); | ||
isoForm.build({ type:'stringtest' }); | ||
isoForm.validSchema.should.equal(true); | ||
isoForm.html.should.equal('A STRING TEMPLATE'); | ||
var form = isoForm.build({ type:'stringtest' }); | ||
form.isValidSchema.should.equal(true); | ||
form.html.should.equal('A STRING TEMPLATE'); | ||
}); | ||
it('should support starting with an array', function () { | ||
isoForm.build([{ type:'test' }, { type:'test' }]); | ||
isoForm.validSchema.should.equal(true); | ||
isoForm.html.should.equal('TESTTEST'); | ||
var form = isoForm.build([{ type:'test' }, { type:'test' }]); | ||
form.isValidSchema.should.equal(true); | ||
form.html.should.equal('TESTTEST'); | ||
}); | ||
@@ -54,3 +54,3 @@ | ||
isoForm.addGroupType('group', groupTemplate, closeGroupTemplate); | ||
isoForm.build({ | ||
var form = isoForm.build({ | ||
type:'group', | ||
@@ -61,4 +61,4 @@ items: [ | ||
}); | ||
isoForm.validSchema.should.equal(true); | ||
isoForm.html.should.equal('GROUP START TEST GROUP END'); | ||
form.isValidSchema.should.equal(true); | ||
form.html.should.equal('GROUP START TEST GROUP END'); | ||
}); | ||
@@ -69,3 +69,3 @@ | ||
isoForm.addItemType('testoptions', templateWithOptions); | ||
isoForm.build({ | ||
var form = isoForm.build({ | ||
type:'group', | ||
@@ -76,4 +76,4 @@ items: [ | ||
}); | ||
isoForm.validSchema.should.equal(true); | ||
isoForm.html.should.equal('GROUP START TESTwoo GROUP END'); | ||
form.isValidSchema.should.equal(true); | ||
form.html.should.equal('GROUP START TESTwoo GROUP END'); | ||
}); | ||
@@ -80,0 +80,0 @@ |
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
9947
196
29