Skip to content

Commit f761680

Browse files
authored
Merge branch 'dev-2.0' into textToModel-docs
2 parents 337e47e + 161f41d commit f761680

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4834
-21545
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ docs/reference/*
1010
examples/3d/
1111
.idea
1212
dist/
13+
*.d.ts
1314
p5.zip
1415
bower-repo/
1516
p5-website/

contributor_docs/contributor_guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ When opening a discussion issue, you can use the "Labels" panel on the side pane
194194

195195
## Prerequisites
196196

197-
To proceed you should be minimally familiar with working with the command line, git, node.js (at least v18 and up), and have a local development environment setup.
197+
To proceed you should be minimally familiar with working with the command line, git, node.js (at least v20 and up), and have a local development environment setup.
198198

199199

200200
## Introduction

contributor_docs/jsdoc.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# JSDoc Best Practices
2+
3+
Documentation on the website is built from the comments in the p5.js repo. Here are a few things to keep in mind in order for the documentation to be parsed correctly!
4+
5+
## For everything
6+
7+
- At the top of a file, add a comment with the `@module` tag, and optionally also the `@submodule`. These reference the category and subcategory names that the contents of the file should appear under in the reference:
8+
9+
e.g. for just a category:
10+
```js
11+
/**
12+
* @module Rendering
13+
*/
14+
```
15+
16+
e.g. for both:
17+
```js
18+
/**
19+
* @module Data
20+
* @submodule LocalStorage
21+
*/
22+
```
23+
24+
## For classes
25+
26+
27+
- Create classes *outside* of the addon function, and assign them to `p5` *inside.* The class name should be the same always:
28+
29+
```js
30+
class MyClass {
31+
// ...
32+
}
33+
34+
export default function myAddon(p5, fn) {
35+
p5.MyClass = MyClass;
36+
}
37+
```
38+
39+
- Document class methods directly above the members in classes, *without* a `@method` tag:
40+
41+
```js
42+
class MyClass {
43+
/**
44+
* Description goes here
45+
*/
46+
myMethod() {
47+
return 4;
48+
}
49+
}
50+
```
51+
52+
- Documentation for the class itself should go at the spot where the class is added to `p5` and not right next to the class definition. This needs to include the `@class` tag, including a `p5.` prefix on the class name. Also include the parameters for the constructor in this description, if they exist.
53+
54+
```js
55+
class MyClass {
56+
constructor(n) {
57+
this.n = n;
58+
}
59+
}
60+
61+
export default function myAddon(p5, fn) {
62+
/**
63+
* Description of the class goes here!
64+
*
65+
* @class p5.MyClass
66+
* @param {Number} n A number to pass in
67+
*/
68+
p5.MyClass = MyClass;
69+
}
70+
```
71+
72+
- Documentation for class properties should appear after the class is added to `p5`, not within the class itself. It needs to have the `@for` tag referencing its class, and the `@property` tag naming the property itself:
73+
74+
```js
75+
class MyClass {
76+
myProperty;
77+
constructor() {
78+
myProperty = 2;
79+
}
80+
}
81+
82+
export default function myAddon(p5, fn) {
83+
/**
84+
* Description of the class goes here!
85+
*
86+
* @class p5.MyClass
87+
*/
88+
p5.MyClass = MyClass;
89+
90+
/**
91+
* Description of the property goes here!
92+
*
93+
* @property {Number} myProperty
94+
* @for p5.MyClass
95+
*/
96+
}
97+
```
98+
99+
## For global functions
100+
101+
- Add a comment with the `@method` tag listing its name:
102+
103+
```js
104+
export default function myAddon(p5, fn) {
105+
/**
106+
* Description goes here!
107+
*
108+
* @method myFunction
109+
*/
110+
p5.myFunction = function() {
111+
return 8;
112+
};
113+
}
114+
```
115+
116+
- For dynamically generated methods, do the same as usual, but add `@for p5`.
117+
118+
```js
119+
function myAddon(p5, fn) {
120+
for (const key of ['nameA', 'nameB']) {
121+
fn[key] = function() {
122+
return `Hello from ${key}!`;
123+
};
124+
}
125+
126+
/**
127+
* @method nameA
128+
* @for p5
129+
*/
130+
131+
/**
132+
* @method nameB
133+
* @for p5
134+
*/
135+
}
136+
```
137+
138+
- Mark things that you don't want showing up as `@private`. This is done automatically for methods whose names start with `_`.
139+
140+
```js
141+
class MyClass {
142+
/**
143+
* @private
144+
*/
145+
privateMethodA() {
146+
// ...
147+
}
148+
149+
_privateMethodB() {
150+
// ...
151+
}
152+
}
153+
```

0 commit comments

Comments
 (0)