Skip to content

Commit 0a549f8

Browse files
feat: Add JSdoc for pfelement (#89) (#1520)
* feat: Add JSdoc for pfelement * feat: Update changelog * feat: Preserve example page * feat: Remove compiled assets from commit * feat: Remove commented out config and link to documentation * feat: Update package; remove jsdoc for gulp-jsdoc3 * Update gulpfile.js * Update gulpfile.factory.js * Update gulpfile.factory.js Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 20db453 commit 0a549f8

File tree

13 files changed

+1320
-200
lines changed

13 files changed

+1320
-200
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ test/.wct-kludge
5353

5454
# Sassdoc compiled assets ignored
5555
elements/pfe-sass/demo/*
56+
elements/pfelement/demo/*
57+
!elements/pfelement/demo/example.html

CHANGELOG-1.x.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# 1.5.2 (2021)
1+
# 1.6.0 (2021)
22

3-
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: pfe-primary-detail IE11 rendering fix
3+
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: JSDoc preview added for PFElement
4+
- [65983e6](https://github.com/patternfly/patternfly-elements/commit/65983e60d5394116d3dce6870b77f72772fa09c0) fix: pfe-primary-detail IE11 rendering fix
45

56
# 1.5.1 (2021-04-15)
67

elements/pfe-sass/gulpfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const paths = {
1515
temp: "./_temp"
1616
};
1717

18-
const clean = require("gulp-clean");
18+
const del = require("del");
1919
const sassdoc = require("sassdoc");
2020

2121
// Delete the demo assets
22-
task("clean", () => src(["demo/*.html", "demo/assets"], {
22+
task("clean", () => del(["demo/*.html", "demo/assets"], {
2323
cwd: paths.compiled,
2424
read: false,
2525
allowEmpty: true
26-
}).pipe(clean()));
26+
}));
2727

2828
task("build:sassdoc", () => src(["{extends,functions,maps,mixins,variables}/_*.scss", "pfe-sass.scss"], {
2929
cwd: paths.compiled,

elements/pfelement/gulpfile.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
11
const gulpFactory = require("../../scripts/gulpfile.factory.js");
22
const pfelementPackage = require("./package.json");
33

4-
gulpFactory(pfelementPackage);
4+
const { task, src, series } = require("gulp");
5+
const jsdoc = require("gulp-jsdoc3");
6+
const del = require("del");
7+
8+
task("clean:jsdoc", () =>
9+
del(["demo/**", "!demo/example.html"], {
10+
read: false,
11+
allowEmpty: true
12+
})
13+
);
14+
15+
task("build:jsdoc", cb => {
16+
src(["README.md", "dist/pfelement.js"], {
17+
read: false,
18+
allowEmpty: true
19+
}).pipe(
20+
jsdoc(
21+
{
22+
opts: {
23+
destination: "demo/",
24+
template: "../../node_modules/foodoc/template"
25+
},
26+
// https://github.com/steveush/foodoc#configuring-the-template
27+
templates: {
28+
systemName: "PatternFly Elements",
29+
systemSummary: "A set of community-created web components based on PatternFly design.",
30+
systemLogo: "../../brand/logo/svg/pfe-icon-white-shaded.svg",
31+
favicon: "../../brand/logo/svg/pfe-icon-blue-shaded.svg",
32+
systemColor: "rgb(0, 64, 128)",
33+
copyright: "©2021 Red Hat, Inc.",
34+
includeDate: true,
35+
dateFormat: "YYYY MMM DD",
36+
showAccessFilter: false,
37+
collapseSymbols: false,
38+
stylesheets: ["../pfe-styles/dist/pfe-base.min.css"]
39+
}
40+
},
41+
cb
42+
)
43+
);
44+
});
45+
46+
task("jsdoc", series("clean:jsdoc", "build:jsdoc"));
47+
48+
gulpFactory(Object.assign(pfelementPackage, { postbundle: ["jsdoc"] }));

elements/pfelement/src/attrDefValidators.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Verify that a property definition's `type` field contains one of the allowed
3-
* types.
4-
*
5-
* Allowed types are String, Number, and Boolean. If `type` is falsy, it
6-
* defaults to String.
3+
* types. If the definition type resolves to falsy, assumes String type.
4+
* @param {constructor} definition
5+
* @default String
6+
* @return {Boolean} True if the definition type is one of String, Number, or Boolean
77
*/
88
export function isAllowedType(definition) {
99
return [String, Number, Boolean].includes(definition.type || String);
@@ -15,6 +15,8 @@ export function isAllowedType(definition) {
1515
* A `default` value is valid if it's of the same type as the `type`
1616
* definition. Or, if there is no `type` definition, then it must be a String
1717
* (the default value for `type`).
18+
* @param {type} definition
19+
* @return {Boolean} True if the default value matches the type of the definition object.
1820
*/
1921
export function isValidDefaultType(definition) {
2022
return definition.hasOwnProperty("default") && definition.default.constructor === definition.type;

elements/pfelement/src/pfelement.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ import { isAllowedType, isValidDefaultType } from "./attrDefValidators.js";
33
// Import polyfills: includes
44
import "./polyfills--pfelement.js";
55

6+
// /**
7+
// * Global prefix used for all components in the project.
8+
// * @constant {String}
9+
// * */
610
const prefix = "pfe";
711

12+
/**
13+
* @class PFElement
14+
* @extends HTMLElement
15+
* @version {{version}}
16+
* @classdesc Serves as the baseline for all PatternFly Element components.
17+
*/
818
class PFElement extends HTMLElement {
919
/**
1020
* A boolean value that indicates if the logging should be printed to the console; used for debugging.
11-
*
12-
* @example In a JS file or script tag: `PFElement._debugLog = true;`
21+
* For use in a JS file or script tag; can also be added in the constructor of a component during development.
22+
* @example PFElement._debugLog = true;
23+
* @tags debug
1324
*/
1425
static debugLog(preference = null) {
1526
if (preference !== null) {
@@ -20,8 +31,8 @@ class PFElement extends HTMLElement {
2031

2132
/**
2233
* A boolean value that indicates if the performance should be tracked.
23-
*
24-
* @example In a JS file or script tag: `PFElement._trackPerformance = true;`
34+
* For use in a JS file or script tag; can also be added in the constructor of a component during development.
35+
* @example PFElement._trackPerformance = true;
2536
*/
2637
static trackPerformance(preference = null) {
2738
if (preference !== null) {
@@ -33,7 +44,7 @@ class PFElement extends HTMLElement {
3344
/**
3445
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
3546
*
36-
* @example `PFElement.log("Hello")`
47+
* @example PFElement.log("Hello");
3748
*/
3849
static log(...msgs) {
3950
if (PFElement.debugLog()) {
@@ -44,7 +55,7 @@ class PFElement extends HTMLElement {
4455
/**
4556
* Local logging that outputs the tag name as a prefix automatically
4657
*
47-
* @example In a component's function: `this.log("Hello")`
58+
* @example this.log("Hello");
4859
*/
4960
log(...msgs) {
5061
PFElement.log(`[${this.tag}${this.id ? `#${this.id}` : ""}]: ${msgs.join(", ")}`);
@@ -53,34 +64,34 @@ class PFElement extends HTMLElement {
5364
/**
5465
* A console warning wrapper which formats your output with useful debugging information.
5566
*
56-
* @example `PFElement.warn("Hello")`
67+
* @example PFElement.warn("Hello");
5768
*/
5869
static warn(...msgs) {
5970
console.warn(...msgs);
6071
}
6172

6273
/**
6374
* Local warning wrapper that outputs the tag name as a prefix automatically.
64-
*
65-
* @example In a component's function: `this.warn("Hello")`
75+
* For use inside a component's function.
76+
* @example this.warn("Hello");
6677
*/
6778
warn(...msgs) {
6879
PFElement.warn(`[${this.tag}${this.id ? `#${this.id}` : ``}]: ${msgs.join(", ")}`);
6980
}
7081

7182
/**
7283
* A console error wrapper which formats your output with useful debugging information.
73-
*
74-
* @example `PFElement.error("Hello")`
84+
* For use inside a component's function.
85+
* @example PFElement.error("Hello");
7586
*/
7687
static error(...msgs) {
7788
throw new Error([...msgs].join(" "));
7889
}
7990

8091
/**
8192
* Local error wrapper that outputs the tag name as a prefix automatically.
82-
*
83-
* @example In a component's function: `this.error("Hello")`
93+
* For use inside a component's function.
94+
* @example this.error("Hello");
8495
*/
8596
error(...msgs) {
8697
PFElement.error(`[${this.tag}${this.id ? `#${this.id}` : ``}]:`, ...msgs);
@@ -107,8 +118,8 @@ class PFElement extends HTMLElement {
107118

108119
/**
109120
* A local alias to the static version.
110-
*
111-
* @example: In the console: `PfeAccordion.version`
121+
* For use in the console to validate version being loaded.
122+
* @example PfeAccordion.version
112123
*/
113124
get version() {
114125
return this._pfeClass.version;
@@ -175,7 +186,7 @@ class PFElement extends HTMLElement {
175186
* A quick way to fetch a random ID value.
176187
* _Note:_ All values are prefixes with `pfe` automatically to ensure an ID-safe value is returned.
177188
*
178-
* @example: In a component's JS: `this.id = this.randomID;`
189+
* @example this.id = this.randomID;
179190
*/
180191
get randomId() {
181192
return (
@@ -205,7 +216,7 @@ class PFElement extends HTMLElement {
205216
/**
206217
* Returns a boolean statement of whether or not this component contains any light DOM.
207218
* @returns {boolean}
208-
* @examples `if(this.hasLightDOM()) this._init();`
219+
* @example if(this.hasLightDOM()) this._init();
209220
*/
210221
hasLightDOM() {
211222
return this.children.length || this.textContent.trim().length;
@@ -214,7 +225,7 @@ class PFElement extends HTMLElement {
214225
/**
215226
* Returns a boolean statement of whether or not that slot exists in the light DOM.
216227
*
217-
* @example: `this.hasSlot("header")`
228+
* @example this.hasSlot("header");
218229
*/
219230
hasSlot(name) {
220231
if (!name) {
@@ -1016,4 +1027,5 @@ class PFElement extends HTMLElement {
10161027

10171028
autoReveal(PFElement.log);
10181029

1030+
/** @module PFElement */
10191031
export default PFElement;

elements/pfelement/src/polyfills--pfelement.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @POLYFILL Array.includes
2-
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
2+
/** @see https://tc39.github.io/ecma262/#sec-array.prototype.includes */
33
if (!Array.prototype.includes) {
44
Object.defineProperty(Array.prototype, "includes", {
55
value: function(valueToFind, fromIndex) {
@@ -51,7 +51,7 @@ if (!Array.prototype.includes) {
5151
}
5252

5353
// @POLYFILL Object.entries
54-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
54+
/** @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries */
5555
if (!Object.entries) {
5656
Object.entries = function(obj) {
5757
var ownProps = Object.keys(obj),
@@ -64,7 +64,7 @@ if (!Object.entries) {
6464
}
6565

6666
// @POLYFILL String.startsWith
67-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#polyfill
67+
/** @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#polyfill */
6868
if (!String.prototype.startsWith) {
6969
Object.defineProperty(String.prototype, "startsWith", {
7070
value: function(search, rawPos) {

elements/pfelement/src/reveal.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
let logger = () => null;
22

3+
/**
4+
* Reveal web components when loading is complete by removing the unresolved attribute
5+
* from the body tag; log the event.
6+
* @throws debugging log indicating the reveal event
7+
*/
38
export function reveal() {
49
logger(`[reveal] elements ready, revealing the body`);
510
window.document.body.removeAttribute("unresolved");
611
}
712

13+
/**
14+
* Auto-reveal functionality prevents a flash of unstyled content before components
15+
* have finished loading.
16+
* @param {function} logFunction
17+
* @see https://github.com/github/webcomponentsjs#webcomponents-loaderjs
18+
*/
819
export function autoReveal(logFunction) {
920
logger = logFunction;
1021
// If Web Components are already ready, run the handler right away. If they
@@ -22,6 +33,10 @@ export function autoReveal(logFunction) {
2233
}
2334
}
2435

36+
/**
37+
* Reveal web components when loading is complete and log event.
38+
* @throws debugging log indicating the web components are ready
39+
*/
2540
function handleWebComponentsReady() {
2641
logger("[reveal] web components ready");
2742
reveal();

generators/element/templates/scripts/gulpfile.factory.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = function factory({
3939
const fs = require("fs");
4040
const path = require("path");
4141
const replace = require("gulp-replace");
42-
const clean = require("gulp-clean");
42+
const del = require("del");
4343
const gulpif = require("gulp-if");
4444
const gulpmatch = require("gulp-match");
4545

@@ -64,14 +64,14 @@ module.exports = function factory({
6464
const decomment = require("decomment");
6565

6666
// Delete the temp directory
67-
task("clean", () => src([
68-
paths.temp,
69-
paths.compiled
70-
], {
71-
cwd: paths.root,
72-
read: false,
73-
allowEmpty: true
74-
}).pipe(clean()));
67+
task("clean", () => del([
68+
paths.temp,
69+
paths.compiled
70+
], {
71+
cwd: paths.root,
72+
read: false,
73+
allowEmpty: true
74+
}));
7575

7676
// Compile the sass into css, compress, autoprefix
7777
task("compile:styles", () => src("*.{scss,css}", {
@@ -294,14 +294,14 @@ ${fs
294294
task("bundle", () => shell.task("../../node_modules/.bin/rollup -c"));
295295

296296
// Delete the temp directory
297-
task("clean:post", () => src([
298-
"*.min.css",
299-
"*.umd.js"
300-
], {
301-
cwd: paths.temp,
302-
read: false,
303-
allowEmpty: true
304-
}).pipe(clean()));
297+
task("clean:post", () => del([
298+
"*.min.css",
299+
"*.umd.js"
300+
], {
301+
cwd: paths.temp,
302+
read: false,
303+
allowEmpty: true
304+
}));
305305

306306
task(
307307
"build",

0 commit comments

Comments
 (0)