Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some minor readme tweaks to sample JS #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
First of all Schemasaurus is an iterator over JSON according to JSON schema. For example:

```javascript
var s = require('schemasaurus')
var s = require('schemasaurus');

var fn = s.compile({
properties: {
Expand All @@ -25,7 +25,7 @@ var fn = s.compile({
"[required]": function (schema, object, ctx) {
console.log(" *required");
}
}
};
});
fn({firstname: "frodo", lastname: "baggins", age: 33});
// Output:
Expand Down Expand Up @@ -315,19 +315,19 @@ console.log(v({name: "Glorfindel", age: "1000", horse: "Asfaloth"}));

It is easy enough - that is what schemasaurus was created for.

Let's create simple form generator.
Let's create a simple form generator.

### Prepare iterator

```javascript
s = require('schemasaurus');
var s = require('schemasaurus');

function FormGenerator () {}
FormGenerator.prototype = {
end: function () {
return "ok!"
}
}
};

var schema = {
properties: {
Expand All @@ -345,7 +345,7 @@ var schema = {
}
}
}
}
};

var gen = s.newIterator(schema, FormGenerator);
console.log(gen({}));
Expand Down Expand Up @@ -385,7 +385,7 @@ FormGenerator.prototype = {
end: function () {
return this.html;
}
}
};
...

console.log(gen({firstname: "frodo", lastname: "baggins", gender: "male"}));
Expand Down Expand Up @@ -490,7 +490,7 @@ First naive implementation would be the following:

but if you start it you'll get the duplicated gender field:
```html
<select name='gender'>
<select name='gender'>
<option value='male' selected>male</option>
<option value='female'>female</option>
</select>
Expand Down Expand Up @@ -518,7 +518,7 @@ console.log(gen());
```html
<input type='string' name='firstname'>
<input type='string' name='lastname'>
<select name='gender'>
<select name='gender'>
<option value='male' >male</option>
<option value='female' >female</option>
</select>
Expand Down Expand Up @@ -606,7 +606,7 @@ FormGenerator.prototype = {
var lines = [];
lines.push("this.html += \"<select name='" + this.path(ctx) + "'>\"\n");
schema.enum.forEach(function (v) {
lines.push("this.html += \"<option value='" + v + "' \" + (_ === " + JSON.stringify(v) + " ? 'selected' : '') + \">" + v + "</options>\"\n")
lines.push("this.html += \"<option value='" + v + "' \" + (_ === " + JSON.stringify(v) + " ? 'selected' : '') + \">" + v + "</options>\"\n");
});
lines.push("this.html += \"</select>\"\n");
lines.push("ctx.stop();");
Expand Down