Skip to content

Commit

Permalink
Merge branch 'examples'
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick committed Aug 8, 2018
2 parents 297f22a + 556b496 commit 4d624e3
Show file tree
Hide file tree
Showing 14 changed files with 723 additions and 949 deletions.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Revision history for docson

## NEXT

* Display examples as part of the description, if present. [GH#60, jvican]
* Add support for consts. [jvican]

## v2.0.1 - 2018-07-23

* Release to npm.
Expand Down
14 changes: 0 additions & 14 deletions Taskfile.yml

This file was deleted.

6 changes: 4 additions & 2 deletions examples/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "number"
"type": "number",
"examples": [ 1234, 5678 ]
},
"name": {
"type": "string"
"type": "string",
"examples": [ "thingy" ]
},
"price": {
"type": "number",
Expand Down
69 changes: 0 additions & 69 deletions integration/basic.js

This file was deleted.

4 changes: 2 additions & 2 deletions integration/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const puppeteer = require('puppeteer');
const path = require('path');

jest.setTimeout(500000);
jest.setTimeout(50000);

const server = new Promise( resolve => {
let app = require( '../src/server' )({ directory: path.join( __dirname, '..' ) });
let server;
server = app.listen( 3000, () => resolve(server) );
}).catch( e => console.log(e) );

const browser = puppeteer.launch({ headless: true });
const browser = puppeteer.launch({ headless: false });

const rootUrl = "http://localhost:3000/public/index.html";

Expand Down
31 changes: 0 additions & 31 deletions integration/widget.js

This file was deleted.

2 changes: 1 addition & 1 deletion integration/widget.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const server = new Promise( resolve => {
server = app.listen( 3000, () => resolve(server) );
}).catch( e => console.log(e) );

const browser = puppeteer.launch({ headless: true });
const browser = puppeteer.launch({ headless: false });

beforeAll( async () => { await server; await browser }, 10000 );
afterAll( async () => {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testURL: "http://localhost/",
}
26 changes: 22 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const highlight = false;

var resolve_ready;
var ready = new Promise((resolve, reject) => {
debug('promise A');
resolve_ready = resolve;
});

Expand Down Expand Up @@ -118,9 +117,25 @@ Handlebars.registerHelper('source', function (schema) {

Handlebars.registerHelper('desc', function (schema) {
var description = schema.description;
var examples = schema.examples;

var text = "";

if (!description && !examples) {
return "";
}

if (description) {
text = description;
}

if (examples && examples.length > 0) {
text += "\n\n*Examples* \n";
examples.forEach(e => {
text += "\n\n```\n" + e + "\n```\n\n";
});
}

if (!description) return "";
var text = description;
if (_marked2.default) {
_marked2.default.setOptions({ gfm: true, breaks: true });
return new Handlebars.SafeString((0, _marked2.default)(text));
Expand All @@ -146,7 +161,7 @@ Handlebars.registerHelper('contains', function (arr, item, options) {
});

Handlebars.registerHelper('primitive', function (schema, options) {
if (schema.type && schema.type != "object" && schema.type != "array" || schema.enum) {
if (schema.type && schema.type != "object" && schema.type != "array" || schema.enum || schema.const) {
return withType(this, options, true);
}
});
Expand Down Expand Up @@ -211,6 +226,9 @@ var withType = function (schema, options, hideAny) {
if (!schema.type && !hideAny) {
schema.__type = "any";
}
if (schema.const) {
schema.__type = schema.const;
}
if (schema.format) {
schema.__type = schema.format;
}
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
},
"bin": "./lib/docson-cli.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "gotask build",
"build-widget": "webpack"
"prepare": "npm run build",
"build": "npm run clean && npm run build-lib && npm run build-widget",
"build-widget": "webpack",
"build-lib": "pnpx babel src -d lib",
"clean": "rm -fr lib"
},
"repository": {
"type": "git",
Expand All @@ -36,12 +38,14 @@
"devDependencies": {
"@babel/preset-env": "^7.0.0-beta.54",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"jest": "^23.2.0",
"jest-environment-jsdom": "^23.4.0",
"puppeteer": "^1.5.0",
"webpack": "^3.11.0"
},
Expand All @@ -58,7 +62,5 @@
"serve-index": "^1.9.1",
"traverse": "^0.6.6",
"urijs": "^1.19.1"
},
"optionalDependencies": {
}
}
Loading

0 comments on commit 4d624e3

Please sign in to comment.