Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 64679f8

Browse files
committed
Added brackets around optional params.
Added tests.
1 parent 8e44cb3 commit 64679f8

File tree

3 files changed

+272
-3
lines changed

3 files changed

+272
-3
lines changed

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ const parser = (content, filename) =>
2424
'description': method.description.full,
2525
'params': method.tags.filter(tag =>
2626
tag.type === 'param' && !tag.name.match(/\./))
27-
.map(tag => formatStringForParam(tag.name))
28-
.join(', '),
27+
.map(tag => {
28+
29+
if (tag.optional) {
30+
31+
return `[${formatStringForParam(tag.name)}]`;
32+
33+
}
34+
35+
return formatStringForParam(tag.name);
36+
37+
})
38+
.join(', ')
39+
.replace(/\], \[/g, ', '),
2940
'tags': {
3041
'example': method.tags.filter(tag => tag.type === 'example')
3142
.map(tag => tag.string),

test/fixtures/facade.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,133 @@
1+
/**
2+
* Creates a new Facade.js object with either a preexisting canvas tag or a unique name, width, and height.
3+
*
4+
* @example var stage = new Facade(document.querySelector('canvas'));
5+
* @example var stage = new Facade('stage', 500, 300);
6+
* @property {Object} canvas Reference to the canvas element.
7+
* @property {Object} context Reference to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D" target="_blank">CanvasRenderingContext2D</a> object.
8+
* @property {Integer} dt Current time in milliseconds since last canvas draw.
9+
* @property {Integer} fps Current frames per second.
10+
* @property {Integer} ftime Time of last canvas draw.
11+
* @param {Object|String} [canvas] Reference to an HTML canvas element or a unique name.
12+
* @param {Integer} [width] Width of the canvas.
13+
* @param {Integer} [height] Height of the canvas.
14+
* @return {Object} New Facade.js object.
15+
* @public
16+
*/
17+
18+
function Facade(canvas, width, height) {
19+
20+
if (!(this instanceof Facade)) {
21+
22+
return new Facade(canvas, width, height);
23+
24+
}
25+
26+
this.dt = null;
27+
this.fps = null;
28+
this.ftime = null;
29+
30+
this._callback = null;
31+
32+
this._requestAnimation = null;
33+
34+
this._width = null;
35+
this._height = null;
36+
37+
if (canvas && typeof canvas === 'object' && canvas.nodeType === 1) {
38+
39+
this.canvas = canvas;
40+
41+
} else {
42+
43+
this.canvas = document.createElement('canvas');
44+
45+
if (typeof canvas === 'string') {
46+
47+
this.canvas.setAttribute('id', canvas);
48+
49+
}
50+
51+
}
52+
53+
if (width) {
54+
55+
this.width(width);
56+
57+
} else if (this.canvas.hasAttribute('width')) {
58+
59+
this._width = parseInt(this.canvas.getAttribute('width'), 10);
60+
61+
} else {
62+
63+
this.width(this.canvas.clientWidth);
64+
65+
}
66+
67+
if (height) {
68+
69+
this.height(height);
70+
71+
} else if (this.canvas.hasAttribute('height')) {
72+
73+
this._height = parseInt(this.canvas.getAttribute('height'), 10);
74+
75+
} else {
76+
77+
this.height(this.canvas.clientHeight);
78+
79+
}
80+
81+
try {
82+
83+
this.context = this.canvas.getContext('2d');
84+
85+
} catch (e) {
86+
87+
console.error('Object passed to Facade.js was not a valid canvas element.');
88+
89+
}
90+
91+
}
92+
93+
/**
94+
* Draws a Facade.js entity (or multiple entities) to the stage.
95+
*
96+
* @example stage.addToStage(circle);
97+
* @example stage.addToStage(circle, { x: 100, y: 100 });
98+
* @param {Object|Array} obj Facade.js entity or an array of entities.
99+
* @param {Object} [options] Temporary options for rendering a Facade.js entity (or multiple entities).
100+
* @return {Object} Facade.js object.
101+
* @public
102+
*/
103+
104+
Facade.prototype.addToStage = function (obj, options) {
105+
106+
var i,
107+
length;
108+
109+
if (obj instanceof Facade.Entity) {
110+
111+
obj.draw(this, options);
112+
113+
} else if (Array.isArray(obj)) {
114+
115+
for (i = 0, length = obj.length; i < length; i += 1) {
116+
117+
this.addToStage(obj[i], options);
118+
119+
}
120+
121+
} else {
122+
123+
console.error('Object passed to Facade.addToStage is not a valid Facade.js entity.');
124+
125+
}
126+
127+
return this;
128+
129+
};
130+
1131
/**
2132
* Create a polygon object. Inherits all methods from <b>Facade.Entity</b>.
3133
*

test/fixtures/facade.json

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,139 @@
11
[
2+
{
3+
"uid": "facade.js-facade",
4+
"isPrivate": false,
5+
"type": "function",
6+
"name": "Facade",
7+
"description": "Creates a new Facade.js object with either a preexisting canvas tag or a unique name, width, and height.",
8+
"params": "[canvas, width, height]",
9+
"tags": {
10+
"example": [
11+
"var stage = new Facade(document.querySelector('canvas'));",
12+
"var stage = new Facade('stage', 500, 300);"
13+
],
14+
"param": [
15+
{
16+
"name": "canvas",
17+
"isOptional": true,
18+
"types": [
19+
"Object",
20+
"String"
21+
],
22+
"description": "Reference to an HTML canvas element or a unique name."
23+
},
24+
{
25+
"name": "width",
26+
"isOptional": true,
27+
"types": [
28+
"Integer"
29+
],
30+
"description": "Width of the canvas."
31+
},
32+
{
33+
"name": "height",
34+
"isOptional": true,
35+
"types": [
36+
"Integer"
37+
],
38+
"description": "Height of the canvas."
39+
}
40+
],
41+
"property": [
42+
{
43+
"name": "canvas",
44+
"types": [
45+
"Object"
46+
],
47+
"description": "Reference to the canvas element."
48+
},
49+
{
50+
"name": "context",
51+
"types": [
52+
"Object"
53+
],
54+
"description": "Reference to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D\" target=\"_blank\">CanvasRenderingContext2D</a> object."
55+
},
56+
{
57+
"name": "dt",
58+
"types": [
59+
"Integer"
60+
],
61+
"description": "Current time in milliseconds since last canvas draw."
62+
},
63+
{
64+
"name": "fps",
65+
"types": [
66+
"Integer"
67+
],
68+
"description": "Current frames per second."
69+
},
70+
{
71+
"name": "ftime",
72+
"types": [
73+
"Integer"
74+
],
75+
"description": "Time of last canvas draw."
76+
}
77+
],
78+
"return": [
79+
{
80+
"types": [
81+
"Object"
82+
],
83+
"description": "New Facade.js object."
84+
}
85+
]
86+
}
87+
},
88+
{
89+
"uid": "facade.js-facade.prototype.addtostage",
90+
"isPrivate": false,
91+
"type": "method",
92+
"name": "Facade.addToStage",
93+
"description": "Draws a Facade.js entity (or multiple entities) to the stage.",
94+
"params": "obj, [options]",
95+
"tags": {
96+
"example": [
97+
"stage.addToStage(circle);",
98+
"stage.addToStage(circle, { x: 100, y: 100 });"
99+
],
100+
"param": [
101+
{
102+
"name": "obj",
103+
"isOptional": false,
104+
"types": [
105+
"Object",
106+
"Array"
107+
],
108+
"description": "Facade.js entity or an array of entities."
109+
},
110+
{
111+
"name": "options",
112+
"isOptional": true,
113+
"types": [
114+
"Object"
115+
],
116+
"description": "Temporary options for rendering a Facade.js entity (or multiple entities)."
117+
}
118+
],
119+
"property": [],
120+
"return": [
121+
{
122+
"types": [
123+
"Object"
124+
],
125+
"description": "Facade.js object."
126+
}
127+
]
128+
}
129+
},
2130
{
3131
"uid": "facade.js-facade.polygon",
4132
"isPrivate": false,
5133
"type": "method",
6134
"name": "Facade.Polygon",
7135
"description": "Create a polygon object. Inherits all methods from <b>Facade.Entity</b>.\n\n```\nvar polygon = new Facade.Polygon({\n x: 0,\n y: 0,\n points: [ [100, 0], [200, 100], [100, 200], [0, 100] ],\n lineWidth: 10,\n strokeStyle: '#333E4B',\n fillStyle: '#1C73A8',\n anchor: 'top/left'\n});\n```",
8-
"params": "options",
136+
"params": "[options]",
9137
"tags": {
10138
"example": [],
11139
"param": [

0 commit comments

Comments
 (0)