Skip to content

Commit

Permalink
Merge pull request #186 from preciousforever/improvement-custom_types…
Browse files Browse the repository at this point in the history
…-example

Improve custom types example
  • Loading branch information
dervus committed Apr 29, 2015
2 parents 9cc570a + 0b9042f commit ad21884
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions examples/custom_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ var SpaceYamlType = new yaml.Type('!space', {

var SPACE_SCHEMA = yaml.Schema.create([ SpaceYamlType, PointYamlType ]);


// And read a document using that schema.

fs.readFile(path.join(__dirname, 'custom_types.yml'), 'utf8', function (error, data) {
var loaded;

if (!error) {
loaded = yaml.load(data, { schema: SPACE_SCHEMA });
console.log(util.inspect(loaded, false, 20, true));
} else {
console.error(error.stack || error.message || String(error));
}
});

// do not execute the following if file is required (http://stackoverflow.com/a/6398335)
if (require.main === module) {

// And read a document using that schema.
fs.readFile(path.join(__dirname, 'custom_types.yml'), 'utf8', function (error, data) {
var loaded;

if (!error) {
loaded = yaml.load(data, { schema: SPACE_SCHEMA });
console.log(util.inspect(loaded, false, 20, true));
} else {
console.error(error.stack || error.message || String(error));
}
});
}

// There are some exports to play with this example interactively.

module.exports.Point = Point;
module.exports.Space = Space;
module.exports.PointYamlType = PointYamlType;
Expand Down

0 comments on commit ad21884

Please sign in to comment.