-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Add automated theme.json reference documentation (#37569)
* Initial script to generate settings and style for theme.json * Add to table of contents and link to how to guide - Adds a brief paragraph at top of reference guide linking to how to guide for examples - Adds reference guide to table of contents / manifest * Add markdownDescription for appearanceTools To enrich the automated docs this adds a markdownDescription field for appearanceTools to explain what tools are enabled. You can see the markdownDescription field used in the tsconfig schema here: http:https://json.schemastore.org/tsconfig * Add support for markdownDescription in generated docs * Update generated docs. * Dont use markdownDescription yet, move rich description to description field. * Remove markdownDescription field * Change doc scripts trigger for pre-commit Update lint-staged to command to run script to generate theme.json reference prior to checking for changed files. For details fixing similar issue see PR #37613
- Loading branch information
Showing
6 changed files
with
349 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/** | ||
* Generates core block documentation using block.json files. | ||
* Reads from : packages/block-library/src | ||
* Publishes to: docs/reference-guides/core-blocks.ms | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
const path = require( 'path' ); | ||
const fs = require( 'fs' ); | ||
const { keys } = require( 'lodash' ); | ||
/** | ||
* Path to root project directory. | ||
* | ||
* @type {string} | ||
*/ | ||
const ROOT_DIR = path.resolve( __dirname, '../..' ); | ||
|
||
/** | ||
* Path to theme json schema file. | ||
* | ||
* @type {string} | ||
*/ | ||
const THEME_JSON_SCHEMA_FILE = path.resolve( | ||
ROOT_DIR, | ||
path.join( 'schemas', 'json', 'theme.json' ) | ||
); | ||
|
||
/** | ||
* Path to docs file. | ||
* | ||
* @type {string} | ||
*/ | ||
const THEME_JSON_REF_DOC = path.resolve( | ||
ROOT_DIR, | ||
'docs/reference-guides/theme-json-reference.md' | ||
); | ||
|
||
/** | ||
* Start token for matching string in doc file. | ||
* | ||
* @type {string} | ||
*/ | ||
const START_TOKEN = '<!-- START TOKEN Autogenerated - DO NOT EDIT -->'; | ||
|
||
/** | ||
* Start token for matching string in doc file. | ||
* | ||
* @type {string} | ||
*/ | ||
const END_TOKEN = '<!-- END TOKEN Autogenerated - DO NOT EDIT -->'; | ||
|
||
/** | ||
* Regular expression using tokens for matching in doc file. | ||
* Note: `.` does not match new lines, so [^] is used. | ||
* | ||
* @type {RegExp} | ||
*/ | ||
const TOKEN_PATTERN = new RegExp( START_TOKEN + '[^]*' + END_TOKEN ); | ||
|
||
const themejson = require( THEME_JSON_SCHEMA_FILE ); | ||
|
||
/** | ||
* Convert settings properties to markup. | ||
* | ||
* @param {Object} struct | ||
* @return {string} markup | ||
*/ | ||
const getSettingsPropertiesMarkup = ( struct ) => { | ||
if ( ! ( 'properties' in struct ) ) { | ||
return ''; | ||
} | ||
const props = struct.properties; | ||
const ks = keys( props ); | ||
if ( ks.length < 1 ) { | ||
return ''; | ||
} | ||
|
||
let markup = '| Property | Type | Default | Props |\n'; | ||
markup += '| --- | --- | --- |--- |\n'; | ||
ks.forEach( ( key ) => { | ||
const def = 'default' in props[ key ] ? props[ key ].default : ''; | ||
const ps = | ||
props[ key ].type === 'array' | ||
? keys( props[ key ].items.properties ).sort().join( ', ' ) | ||
: ''; | ||
markup += `| ${ key } | ${ props[ key ].type } | ${ def } | ${ ps } |\n`; | ||
} ); | ||
|
||
return markup; | ||
}; | ||
|
||
/** | ||
* Convert style properties to markup. | ||
* | ||
* @param {Object} struct | ||
* @return {string} markup | ||
*/ | ||
const getStylePropertiesMarkup = ( struct ) => { | ||
if ( ! ( 'properties' in struct ) ) { | ||
return ''; | ||
} | ||
const props = struct.properties; | ||
const ks = keys( props ); | ||
if ( ks.length < 1 ) { | ||
return ''; | ||
} | ||
|
||
let markup = '| Property | Type | Props |\n'; | ||
markup += '| --- | --- |--- |\n'; | ||
ks.forEach( ( key ) => { | ||
const ps = | ||
props[ key ].type === 'object' | ||
? keys( props[ key ].properties ).sort().join( ', ' ) | ||
: ''; | ||
markup += `| ${ key } | ${ props[ key ].type } | ${ ps } |\n`; | ||
} ); | ||
|
||
return markup; | ||
}; | ||
|
||
/** | ||
* Parses a section for description and properties and | ||
* returns a marked up version. | ||
* | ||
* @param {string} title | ||
* @param {Object} data | ||
* @param {string} type settings|style | ||
* @return {string} markup | ||
*/ | ||
const getSectionMarkup = ( title, data, type ) => { | ||
const markupFn = | ||
type === 'settings' | ||
? getSettingsPropertiesMarkup | ||
: getStylePropertiesMarkup; | ||
|
||
return ` | ||
### ${ title } | ||
${ data.description } | ||
${ markupFn( data ) } | ||
--- | ||
`; | ||
}; | ||
|
||
let autogen = ''; | ||
|
||
// Settings | ||
const settings = themejson.definitions.settingsProperties.properties; | ||
const settingSections = keys( settings ); | ||
autogen += '## Settings' + '\n\n'; | ||
settingSections.forEach( ( section ) => { | ||
autogen += getSectionMarkup( section, settings[ section ], 'settings' ); | ||
} ); | ||
|
||
// Styles | ||
const styles = themejson.definitions.stylesProperties.properties; | ||
const styleSections = keys( styles ); | ||
autogen += '## Styles' + '\n\n'; | ||
styleSections.forEach( ( section ) => { | ||
autogen += getSectionMarkup( section, styles[ section ], 'styles' ); | ||
} ); | ||
|
||
// Read existing file to wrap auto generated content. | ||
let docsContent = fs.readFileSync( THEME_JSON_REF_DOC, { | ||
encoding: 'utf8', | ||
flag: 'r', | ||
} ); | ||
|
||
// Replace auto generated part with new generated docs. | ||
autogen = START_TOKEN + '\n' + autogen + '\n' + END_TOKEN; | ||
docsContent = docsContent.replace( TOKEN_PATTERN, autogen ); | ||
|
||
// Write back out. | ||
fs.writeFileSync( THEME_JSON_REF_DOC, docsContent, { encoding: 'utf8' } ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Theme.json Reference | ||
|
||
This reference guide lists the settings and style properties defined in the theme.json schema. See the [theme.json how to guide](/docs/how-to-guides/themes/theme-json.md) for examples and guide on how to use the theme.json file in your theme. | ||
|
||
<!-- START TOKEN Autogenerated - DO NOT EDIT --> | ||
## Settings | ||
|
||
|
||
### appearanceTools | ||
|
||
Setting that enables the following UI tools: | ||
|
||
- border: color, radius, style, width | ||
- color: link | ||
- spacing: blockGap, margin, padding | ||
- typography: lineHeight | ||
|
||
|
||
--- | ||
|
||
### border | ||
|
||
Settings related to borders. | ||
|
||
| Property | Type | Default | Props | | ||
| --- | --- | --- |--- | | ||
| color | boolean | false | | | ||
| radius | boolean | false | | | ||
| style | boolean | false | | | ||
| width | boolean | false | | | ||
|
||
--- | ||
|
||
### color | ||
|
||
Settings related to colors. | ||
|
||
| Property | Type | Default | Props | | ||
| --- | --- | --- |--- | | ||
| background | boolean | true | | | ||
| custom | boolean | true | | | ||
| customDuotone | boolean | true | | | ||
| customGradient | boolean | true | | | ||
| defaultGradients | boolean | true | | | ||
| defaultPalette | boolean | true | | | ||
| duotone | array | | colors, name, slug | | ||
| gradients | array | | gradient, name, slug | | ||
| link | boolean | false | | | ||
| palette | array | | color, name, slug | | ||
| text | boolean | true | | | ||
|
||
--- | ||
|
||
### layout | ||
|
||
Settings related to layout. | ||
|
||
| Property | Type | Default | Props | | ||
| --- | --- | --- |--- | | ||
| contentSize | string | | | | ||
| wideSize | string | | | | ||
|
||
--- | ||
|
||
### spacing | ||
|
||
Settings related to spacing. | ||
|
||
| Property | Type | Default | Props | | ||
| --- | --- | --- |--- | | ||
| blockGap | undefined | null | | | ||
| margin | boolean | false | | | ||
| padding | boolean | false | | | ||
| units | array | px,em,rem,vh,vw,% | | | ||
|
||
--- | ||
|
||
### typography | ||
|
||
Settings related to typography. | ||
|
||
| Property | Type | Default | Props | | ||
| --- | --- | --- |--- | | ||
| customFontSize | boolean | true | | | ||
| fontStyle | boolean | true | | | ||
| fontWeight | boolean | true | | | ||
| letterSpacing | boolean | true | | | ||
| lineHeight | boolean | false | | | ||
| textDecoration | boolean | true | | | ||
| textTransform | boolean | true | | | ||
| dropCap | boolean | true | | | ||
| fontSizes | array | | name, size, slug | | ||
| fontFamilies | array | | fontFamily, name, slug | | ||
|
||
--- | ||
|
||
### custom | ||
|
||
Generate custom CSS custom properties of the form `--wp--custom--{key}--{nested-key}: {value};`. `camelCased` keys are transformed to `kebab-case` as to follow the CSS property naming schema. Keys at different depth levels are separated by `--`, so keys should not include `--` in the name. | ||
|
||
|
||
--- | ||
## Styles | ||
|
||
|
||
### border | ||
|
||
Border styles. | ||
|
||
| Property | Type | Props | | ||
| --- | --- |--- | | ||
| color | string | | | ||
| radius | string | | | ||
| style | string | | | ||
| width | string | | | ||
|
||
--- | ||
|
||
### color | ||
|
||
Color styles. | ||
|
||
| Property | Type | Props | | ||
| --- | --- |--- | | ||
| background | string | | | ||
| gradient | string | | | ||
| text | string | | | ||
|
||
--- | ||
|
||
### spacing | ||
|
||
Spacing styles. | ||
|
||
| Property | Type | Props | | ||
| --- | --- |--- | | ||
| blockGap | string | | | ||
| margin | object | bottom, left, right, top | | ||
| padding | object | bottom, left, right, top | | ||
|
||
--- | ||
|
||
### typography | ||
|
||
Typography styles. | ||
|
||
| Property | Type | Props | | ||
| --- | --- |--- | | ||
| fontFamily | string | | | ||
| fontSize | string | | | ||
| fontStyle | string | | | ||
| fontWeight | string | | | ||
| letterSpacing | string | | | ||
| lineHeight | string | | | ||
| textDecoration | string | | | ||
| textTransform | string | | | ||
|
||
--- | ||
|
||
<!-- END TOKEN Autogenerated - DO NOT EDIT --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters