From abb9a3695f97f2e4b18f35990a38496a76dcced8 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 15:03:28 -0500 Subject: [PATCH 01/22] composer install wp-cli --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e402485f..ee30b568 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", "php-stubs/acf-pro-stubs": "6.0.6", "phpcompatibility/phpcompatibility-wp": "^2.1.4", - "wp-cli/wp-cli-bundle": "^2.7.1", + "wp-cli/wp-cli-bundle": "^2.7", "wp-coding-standards/wpcs": "^2.3.0" }, "scripts": { From 97357b2a1328c356afdc86e28f2e2daba0da9cce Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 15:06:44 -0500 Subject: [PATCH 02/22] initial copy wp-cli command from acf-wds-blocks --- inc/wpcli/block-starter/block.json | 36 +++ inc/wpcli/block-starter/block.php | 6 + inc/wpcli/block-starter/editor.js | 3 + inc/wpcli/block-starter/editor.scss | 1 + inc/wpcli/block-starter/script.js | 9 + inc/wpcli/block-starter/style.scss | 1 + inc/wpcli/block-starter/tailwind.config.js | 14 + inc/wpcli/class-blocks-scaffold.php | 297 +++++++++++++++++++++ 8 files changed, 367 insertions(+) create mode 100644 inc/wpcli/block-starter/block.json create mode 100644 inc/wpcli/block-starter/block.php create mode 100644 inc/wpcli/block-starter/editor.js create mode 100644 inc/wpcli/block-starter/editor.scss create mode 100644 inc/wpcli/block-starter/script.js create mode 100644 inc/wpcli/block-starter/style.scss create mode 100644 inc/wpcli/block-starter/tailwind.config.js create mode 100644 inc/wpcli/class-blocks-scaffold.php diff --git a/inc/wpcli/block-starter/block.json b/inc/wpcli/block-starter/block.json new file mode 100644 index 00000000..2ed0b6cb --- /dev/null +++ b/inc/wpcli/block-starter/block.json @@ -0,0 +1,36 @@ +{ + "name": "wd_s/{{name}}", + "title": "{{title}}", + "description": "{{description}}", + "editorStyle": "file:./editor.css", + "editorScript": "file:./editor.js", + "style": "file:./style-script.css", + "script": "file:./script.js", + "category": "WDS", + "icon": "{{icon}}", + "apiVersion": 2, + "keywords": [ + "{{name}}", + "{{keyword}}", + "block" + ], + "acf": { + "mode": "auto", + "renderTemplate": "{{name}}.php" + }, + "supports": { + "align": false, + "anchor": true, + "color": true, + "customClassName": true, + "jsx": true + }, + "example": { + "attributes": { + "mode": "preview", + "data": { + "_is_preview": "true" + } + } + } +} diff --git a/inc/wpcli/block-starter/block.php b/inc/wpcli/block-starter/block.php new file mode 100644 index 00000000..570a8d2d --- /dev/null +++ b/inc/wpcli/block-starter/block.php @@ -0,0 +1,6 @@ + [--title=] [--desc=] [--keyword=] [--icon=] [--namespace=] + * + * ## OPTIONS + * + * + * : The block name. Must only have alphabetical characters. + * + * [--desc=] + * : The bloc description. + * + * [--keyword=] + * : They keyword for the block. + * + * [--icon=] + * : Block Icon. + * + * [--namespace=] + * : Block Namespace. + * : Default: WebDevStudios\wd_s + * + * ## EXAMPLES + * + * wp abs create_portable_block myblock --title="This is myblock" --desc="This block is used for wds." --keywords="myblock" --icon="table-row-before" --namespace="WebDevStudios\wd_s" + * @since 2.0.0 + * @param string $name The block name. + * @param array $assoc_args The block args. + */ + public function create_portable_block( $name, $assoc_args ) { + $this->name = esc_html( $name[0] ); + + // validate name. + if ( ! preg_match( '/^[a-zA-Z0-9\-]+$/', $this->name ) ) { + WP_CLI::error( 'Invalid name, Block name must only contain upper and lowercase letters.', true ); + } + + // Merge with default args. + $args = wp_parse_args( + $assoc_args, + [ + 'title' => ucfirst( $this->name ), + 'desc' => '', + 'keywords' => strtolower( $this->name ), + 'icon' => 'table-row-before', + 'namespace' => 'wd_s', + ] + ); + + // create the directory. + $this->create_block_dir(); + + // create block json. + $this->create_block_json( $args ); + + // create block renderer. + $this->create_block_render_php( $args ); + + // create editor assets. + $this->create_block_editor_assets(); + + // create FE assets. + $this->create_block_assets(); + + // create block php. + $this->create_block_tailwind_config(); + + WP_CLI::success( $this->name . ' block created.' ); + } + + /** + * Init file system. + * + * @since 2.0.0 + */ + private function init_filesystem() { + // File system support. + global $wp_filesystem; + require_once ABSPATH . '/wp-admin/includes/file.php'; + WP_Filesystem(); + + return $wp_filesystem; + } + + /** + * Create the block directory. + * + * @author Biplav Subedi + * @since 2.0.0 + */ + private function create_block_dir() { + $dir = ROOT_PATH . 'src/blocks/' . $this->name; + + if ( ! $this->init_filesystem()->exists( $dir ) ) { + $this->init_filesystem()->mkdir( $dir, 0755 ); + } else { + WP_CLI::error( 'Block directory already exists.', true ); + } + } + + /** + * Create the block render file. + * + * @param array $args Block details. + * @since 2.0.0 + * @author Biplav Subedi + */ + private function create_block_render_php( $args ) { + $local_file = ROOT_PATH . 'inc/wpcli/block-starter/block.php'; + $content = ''; + + if ( $this->init_filesystem()->exists( $local_file ) ) { + $content = $this->init_filesystem()->get_contents( $local_file ); + $content = str_replace( 'wd_s', $args['namespace'], $content ); + if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/block.php', $content ) ) { + WP_CLI::error( 'ERROR :: Could not create a render file.', true ); + } + } else { + WP_CLI::error( 'ERROR :: Could not create a render file.', true ); + } + + } + + /** + * Create the block tailwind config file. + * + * @since 2.0.0 + * @author Biplav Subedi + */ + private function create_block_tailwind_config() { + $dir = ROOT_PATH . 'inc/wpcli/block-starter/tailwind.config.js'; + $content = ''; + + if ( $this->init_filesystem()->exists( $dir ) ) { + $content = $this->init_filesystem()->get_contents( $dir ); + $content = str_replace( '{{blockName}}', $this->name, $content ); + } + + if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/tailwind.config.js', $content ) ) { + WP_CLI::error( 'ERROR :: Could not create a block json file.', true ); + } + + } + + + /** + * Create the block json. + * + * @param array $args Block details. + * @since 2.0.0 + * @author Biplav Subedi + */ + private function create_block_json( $args ) { + $local_file = ROOT_PATH . 'inc/wpcli/block-starter/block.json'; + $content = ''; + + if ( $this->init_filesystem()->exists( $local_file ) ) { + $content = $this->init_filesystem()->get_contents( $local_file ); + $content = str_replace( + [ + '{{name}}', + '{{title}}', + '{{description}}', + '{{icon}}', + 'wd_s', + '{{keyword}}', + ], + [ + $this->name, + $args['title'], + $args['desc'], + $args['icon'], + trailingslashit( $args['namespace'] ), + $args['keyword'], + ], + $content + ); + } + + if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/block.json', $content ) ) { + WP_CLI::error( 'ERROR :: Could not create a block json file.', true ); + } + } + + /** + * Create the block editor styles. + * + * @since 2.0.0 + * @author Biplav Subedi + */ + private function create_block_editor_assets() { + $assets_js = ROOT_PATH . 'inc/wpcli/block-starter/editor.js'; + $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/editor.scss'; + + if ( ! $this->init_filesystem()->exists( $assets_js ) || ! $this->init_filesystem()->exists( $assets_css ) ) { + WP_CLI::error( 'ERROR :: Could not find editor assets.', true ); + } + + // copy editor js. + if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'src/blocks/' . $this->name . '/editor.js' ) ) { + WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + } + + // copy editor css. + if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'src/blocks/' . $this->name . '/editor.scss' ) ) { + WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + } + + } + + /** + * Create the block main styles. + * + * @since 2.0.0 + * @author Biplav Subedi + */ + private function create_block_assets() { + $assets_js = ROOT_PATH . 'inc/wpcli/block-starter/script.js'; + $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/style.scss'; + + if ( ! $this->init_filesystem()->exists( $assets_js ) || ! $this->init_filesystem()->exists( $assets_css ) ) { + WP_CLI::error( 'ERROR :: Could not find block assets.', true ); + } + + // copy editor js. + if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'src/blocks/' . $this->name . '/script.js' ) ) { + WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + } + + // copy editor css. + if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'src/blocks/' . $this->name . '/style.scss' ) ) { + WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + } + + } + +} + +/** + * Registers our command when cli get's initialized. + * + * @since 4.0.0 + * @author Biplav Subedi + * @return void + */ +function cli_register_commands() { + WP_CLI::add_command( 'abs', __NAMESPACE__ . '\Blocks_Scaffold' ); +} +add_action( 'cli_init', __NAMESPACE__ . '\cli_register_commands' ); + +/** + * Register Blocks + * + * @return void + * @author Jenna Hines + * @since 2.0.0 + */ +function wds_acf_register_blocks() { + $wds_acf_blocks = glob( ROOT_PATH . 'build/blocks/*' ); + + foreach ( $wds_acf_blocks as $block ) { + register_block_type( $block ); + } +} +add_action( 'acf/init', __NAMESPACE__ . '\wds_acf_register_blocks' ); From e6f011df3a843fb0e435128d259e9268dd413dbb Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 15:07:53 -0500 Subject: [PATCH 03/22] adding some additional stubs used in the project --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b3d2824d..0fa74983 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "editor.defaultFormatter": "esbenp.prettier-vscode" }, "intelephense.format.enable": false, - "intelephense.stubs": [ "acf", "wordpress" ], + "intelephense.stubs": [ "acf", "wordpress", "standard", "Core", "pcre" ], "workbench.colorCustomizations": { "activityBar.background": "#3F4040", From 87bc6819a54adb0b8d94b6912ee50317f64f3d03 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 15:08:30 -0500 Subject: [PATCH 04/22] scripts to build and watch blocks --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ca08aef..cf5ab137 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,8 @@ "postinstall": "npx lefthook install", "start": "cross-env NODE_ENV=development wp-scripts start", "sync": "browser-sync start --https --proxy https://wdunderscores.test --no-open --files 'build/*.*, **/*.html, **/*.php, !node_modules/**/*.html'", - "watch": "run-p start sync" + "watch": "run-p start sync blocks:watch", + "blocks:build": "cross-env NODE_ENV=production wp-scripts build --webpack-src-dir=src/blocks --webpack-copy-php --output-path=build/blocks --config webpack.prod.js", + "blocks:watch": "cross-env NODE_ENV=production wp-scripts start --webpack-src-dir=src/blocks --webpack-copy-php --output-path=build/blocks" } } From 63750db62fc88b4038a779bde0f6a7f595d839ab Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 15:08:51 -0500 Subject: [PATCH 05/22] including inc/wpcli/ folder --- functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/functions.php b/functions.php index c91bed1d..36514434 100644 --- a/functions.php +++ b/functions.php @@ -24,6 +24,7 @@ function include_inc_files() { 'inc/setup/', // Theme setup. 'inc/shortcodes/', // Load shortcodes. 'inc/template-tags/', // Custom template tags for this theme. + 'inc/wpcli/', ]; foreach ( $files as $include ) { From 7e82049be8d12067afed3aaaceea7d6539a5be62 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 15:14:34 -0500 Subject: [PATCH 06/22] we need this folder for the custom blocks --- src/blocks/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/blocks/.gitkeep diff --git a/src/blocks/.gitkeep b/src/blocks/.gitkeep new file mode 100644 index 00000000..e69de29b From 75d627d3be9367cf5b805971b9f494d8715f747d Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 16:20:19 -0500 Subject: [PATCH 07/22] instead of separated build, adding copy-php setting for blocks --- package.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cf5ab137..a5e7d58d 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ }, "scripts": { "accessibility": "pa11y-ci --reporter=pa11y-ci-reporter-html --sitemap $npm_config_url/sitemap.xml", - "build": "cross-env NODE_ENV=production wp-scripts build --config webpack.prod.js", + "build": "cross-env NODE_ENV=production wp-scripts build --config webpack.prod.js --webpack-copy-php", "build:pot": "composer run-script pot", "build:all": "composer install --quiet && composer run-script pot && npm run build", "check-engines": "wp-scripts check-engines", @@ -79,10 +79,8 @@ "report": "composer run-script report", "packages-update": "wp-scripts packages-update", "postinstall": "npx lefthook install", - "start": "cross-env NODE_ENV=development wp-scripts start", + "start": "cross-env NODE_ENV=development wp-scripts start --webpack-copy-php", "sync": "browser-sync start --https --proxy https://wdunderscores.test --no-open --files 'build/*.*, **/*.html, **/*.php, !node_modules/**/*.html'", - "watch": "run-p start sync blocks:watch", - "blocks:build": "cross-env NODE_ENV=production wp-scripts build --webpack-src-dir=src/blocks --webpack-copy-php --output-path=build/blocks --config webpack.prod.js", - "blocks:watch": "cross-env NODE_ENV=production wp-scripts start --webpack-src-dir=src/blocks --webpack-copy-php --output-path=build/blocks" + "watch": "run-p start sync blocks:watch" } } From 8cbe194b0cea91e14a9e6ab545860df3e7b1e089 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 16:20:58 -0500 Subject: [PATCH 08/22] fixing string replacement for namespace --- inc/wpcli/class-blocks-scaffold.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index 8f255bdd..7ca092ae 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -194,7 +194,7 @@ private function create_block_json( $args ) { '{{title}}', '{{description}}', '{{icon}}', - 'wd_s', + 'wd_s/', '{{keyword}}', ], [ From 56cda02b1abad16231f97e4691ff21fc96ced712 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 28 Apr 2023 16:21:13 -0500 Subject: [PATCH 09/22] composer.lock --- composer.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index d35ec707..8655c622 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c01ad8395880d57f6e2dd05b1b3b9f8f", + "content-hash": "561bb6c7a5252bf32a1db299a8dbc319", "packages": [ { "name": "composer/installers", @@ -5054,5 +5054,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } From a8f077bfd42b1e780021625cb8b10c14e7972b72 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:07:05 -0500 Subject: [PATCH 10/22] adds schema | fixes supports.color and references to scripts and styles --- inc/wpcli/block-starter/block.json | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/inc/wpcli/block-starter/block.json b/inc/wpcli/block-starter/block.json index 2ed0b6cb..23572c8b 100644 --- a/inc/wpcli/block-starter/block.json +++ b/inc/wpcli/block-starter/block.json @@ -1,19 +1,16 @@ { - "name": "wd_s/{{name}}", + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "wds/{{name}}", "title": "{{title}}", "description": "{{description}}", "editorStyle": "file:./editor.css", - "editorScript": "file:./editor.js", - "style": "file:./style-script.css", - "script": "file:./script.js", + "editorScript": "./editor.js", + "style": "file:./style.css", + "script": "./script.js", "category": "WDS", "icon": "{{icon}}", - "apiVersion": 2, - "keywords": [ - "{{name}}", - "{{keyword}}", - "block" - ], + "keywords": [ "{{name}}", "{{keyword}}", "block" ], "acf": { "mode": "auto", "renderTemplate": "{{name}}.php" @@ -21,7 +18,7 @@ "supports": { "align": false, "anchor": true, - "color": true, + "color": {}, "customClassName": true, "jsx": true }, From bcce5f4b6a069451aa35bf728507455dfd00a81b Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:08:38 -0500 Subject: [PATCH 11/22] reverts adding -webpack-copy-php, not needed without tailwind --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 10832121..8f5baabd 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ }, "scripts": { "accessibility": "pa11y-ci --reporter=pa11y-ci-reporter-html --sitemap $npm_config_url/sitemap.xml", - "build": "cross-env NODE_ENV=production wp-scripts build --config webpack.prod.js --webpack-copy-php", + "build": "cross-env NODE_ENV=production wp-scripts build --config webpack.prod.js", "build:pot": "composer run-script pot", "build:all": "composer install --quiet && composer run-script pot && npm run build", "check-engines": "wp-scripts check-engines", @@ -81,7 +81,7 @@ "report": "composer run-script report", "packages-update": "wp-scripts packages-update", "postinstall": "npx lefthook install", - "start": "cross-env NODE_ENV=development wp-scripts start --webpack-copy-php", + "start": "cross-env NODE_ENV=development wp-scripts start", "sync": "browser-sync start --https --proxy https://wdunderscores.test --no-open --files 'build/*.*, **/*.html, **/*.php, !node_modules/**/*.html'", "version": "auto-changelog -p && git add CHANGELOG.md", "watch": "run-p start sync" From 27a920a188106ff2f1b924b8334df2f724d17678 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:10:06 -0500 Subject: [PATCH 12/22] early exit is class is already defined --- inc/wpcli/class-blocks-scaffold.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index 7ca092ae..b3c01ccc 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -7,6 +7,11 @@ namespace WebDevStudios\wd_s; +// Exit if class already exists (for example when the plugin `WDS ACF Blocks` is active). +if ( class_exists( 'Blocks_Scaffold' ) ) { + return; +} + // Define a global path and url. define( 'WebDevStudios\wd_s\ROOT_PATH', trailingslashit( get_template_directory() ) ); define( 'WebDevStudios\wd_s\ROOT_URL', trailingslashit( get_template_directory_uri() ) ); From 9f1eeb1aa0b049129c8ef72448d0b62326cd9509 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:12:11 -0500 Subject: [PATCH 13/22] renames prefix to wds (wd_s is not a valid block name) --- inc/wpcli/class-blocks-scaffold.php | 6 +++--- phpcs.xml.dist | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index b3c01ccc..ab313e6d 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -80,7 +80,7 @@ public function create_portable_block( $name, $assoc_args ) { 'desc' => '', 'keywords' => strtolower( $this->name ), 'icon' => 'table-row-before', - 'namespace' => 'wd_s', + 'namespace' => 'wds', ] ); @@ -148,7 +148,7 @@ private function create_block_render_php( $args ) { if ( $this->init_filesystem()->exists( $local_file ) ) { $content = $this->init_filesystem()->get_contents( $local_file ); - $content = str_replace( 'wd_s', $args['namespace'], $content ); + $content = str_replace( 'wds', $args['namespace'], $content ); if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/block.php', $content ) ) { WP_CLI::error( 'ERROR :: Could not create a render file.', true ); } @@ -199,7 +199,7 @@ private function create_block_json( $args ) { '{{title}}', '{{description}}', '{{icon}}', - 'wd_s/', + 'wds/', '{{keyword}}', ], [ diff --git a/phpcs.xml.dist b/phpcs.xml.dist index bc8c9b0e..a6c5f06d 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -49,7 +49,7 @@ Multiple valid prefixes can be provided as a comma-delimited list. --> - + From a24a7b3e3cceb169d9d4e07e0df06fd851cec281 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:16:48 -0500 Subject: [PATCH 14/22] removes tailwind config --- inc/wpcli/block-starter/tailwind.config.js | 14 ------------ inc/wpcli/class-blocks-scaffold.php | 25 ---------------------- 2 files changed, 39 deletions(-) delete mode 100644 inc/wpcli/block-starter/tailwind.config.js diff --git a/inc/wpcli/block-starter/tailwind.config.js b/inc/wpcli/block-starter/tailwind.config.js deleted file mode 100644 index eed4a927..00000000 --- a/inc/wpcli/block-starter/tailwind.config.js +++ /dev/null @@ -1,14 +0,0 @@ -const { tailwindPreset } = require( '../../../postcss.config' ); - -const blockName = '{{blockName}}'; - -const directoryFiles = [ - `./src/blocks/${ blockName }/*.php`, - `./src/blocks/${ blockName }/*.scss`, - `./src/blocks/${ blockName }/*.js`, -]; - -module.exports = { - presets: [ require( tailwindPreset ) ], - content: directoryFiles, -}; diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index ab313e6d..c390fc12 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -99,9 +99,6 @@ public function create_portable_block( $name, $assoc_args ) { // create FE assets. $this->create_block_assets(); - // create block php. - $this->create_block_tailwind_config(); - WP_CLI::success( $this->name . ' block created.' ); } @@ -158,28 +155,6 @@ private function create_block_render_php( $args ) { } - /** - * Create the block tailwind config file. - * - * @since 2.0.0 - * @author Biplav Subedi - */ - private function create_block_tailwind_config() { - $dir = ROOT_PATH . 'inc/wpcli/block-starter/tailwind.config.js'; - $content = ''; - - if ( $this->init_filesystem()->exists( $dir ) ) { - $content = $this->init_filesystem()->get_contents( $dir ); - $content = str_replace( '{{blockName}}', $this->name, $content ); - } - - if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/tailwind.config.js', $content ) ) { - WP_CLI::error( 'ERROR :: Could not create a block json file.', true ); - } - - } - - /** * Create the block json. * From 9049ec1ae92f29821128ef5cf8c40596a6c81bb9 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:20:04 -0500 Subject: [PATCH 15/22] changes acf registration hook from `acf/init` to `init` | changed blocks folder from `src/blocks` to `/blocks` | css intead of scss --- {src/blocks => blocks}/.gitkeep | 0 inc/wpcli/block-starter/editor.css | 1 + inc/wpcli/block-starter/editor.js | 2 +- inc/wpcli/block-starter/editor.scss | 1 - inc/wpcli/block-starter/script.js | 2 +- inc/wpcli/block-starter/style.css | 1 + inc/wpcli/block-starter/style.scss | 1 - inc/wpcli/class-blocks-scaffold.php | 28 +++++++++++++++------------- 8 files changed, 19 insertions(+), 17 deletions(-) rename {src/blocks => blocks}/.gitkeep (100%) create mode 100644 inc/wpcli/block-starter/editor.css delete mode 100644 inc/wpcli/block-starter/editor.scss create mode 100644 inc/wpcli/block-starter/style.css delete mode 100644 inc/wpcli/block-starter/style.scss diff --git a/src/blocks/.gitkeep b/blocks/.gitkeep similarity index 100% rename from src/blocks/.gitkeep rename to blocks/.gitkeep diff --git a/inc/wpcli/block-starter/editor.css b/inc/wpcli/block-starter/editor.css new file mode 100644 index 00000000..b3c58707 --- /dev/null +++ b/inc/wpcli/block-starter/editor.css @@ -0,0 +1 @@ +/* stylelint-disable-next-line no-empty-source */ diff --git a/inc/wpcli/block-starter/editor.js b/inc/wpcli/block-starter/editor.js index 6e40cd36..21ee7b42 100644 --- a/inc/wpcli/block-starter/editor.js +++ b/inc/wpcli/block-starter/editor.js @@ -1,3 +1,3 @@ -import './editor.scss'; +import './editor.css'; // Editor JS here. diff --git a/inc/wpcli/block-starter/editor.scss b/inc/wpcli/block-starter/editor.scss deleted file mode 100644 index 99166582..00000000 --- a/inc/wpcli/block-starter/editor.scss +++ /dev/null @@ -1 +0,0 @@ -// Editor styles. diff --git a/inc/wpcli/block-starter/script.js b/inc/wpcli/block-starter/script.js index ccdec342..164b1d83 100644 --- a/inc/wpcli/block-starter/script.js +++ b/inc/wpcli/block-starter/script.js @@ -4,6 +4,6 @@ * @package * @since 2.0.0 */ -import './style.scss'; +import './style.css'; // add JS here. diff --git a/inc/wpcli/block-starter/style.css b/inc/wpcli/block-starter/style.css new file mode 100644 index 00000000..b3c58707 --- /dev/null +++ b/inc/wpcli/block-starter/style.css @@ -0,0 +1 @@ +/* stylelint-disable-next-line no-empty-source */ diff --git a/inc/wpcli/block-starter/style.scss b/inc/wpcli/block-starter/style.scss deleted file mode 100644 index 4364ccb1..00000000 --- a/inc/wpcli/block-starter/style.scss +++ /dev/null @@ -1 +0,0 @@ -// Frontend styles. diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index c390fc12..777121cf 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -123,7 +123,7 @@ private function init_filesystem() { * @since 2.0.0 */ private function create_block_dir() { - $dir = ROOT_PATH . 'src/blocks/' . $this->name; + $dir = ROOT_PATH . 'blocks/' . $this->name; if ( ! $this->init_filesystem()->exists( $dir ) ) { $this->init_filesystem()->mkdir( $dir, 0755 ); @@ -146,7 +146,7 @@ private function create_block_render_php( $args ) { if ( $this->init_filesystem()->exists( $local_file ) ) { $content = $this->init_filesystem()->get_contents( $local_file ); $content = str_replace( 'wds', $args['namespace'], $content ); - if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/block.php', $content ) ) { + if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'blocks/' . $this->name . '/' . $this->name . '.php', $content ) ) { WP_CLI::error( 'ERROR :: Could not create a render file.', true ); } } else { @@ -189,7 +189,7 @@ private function create_block_json( $args ) { ); } - if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'src/blocks/' . $this->name . '/block.json', $content ) ) { + if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'blocks/' . $this->name . '/block.json', $content ) ) { WP_CLI::error( 'ERROR :: Could not create a block json file.', true ); } } @@ -202,19 +202,19 @@ private function create_block_json( $args ) { */ private function create_block_editor_assets() { $assets_js = ROOT_PATH . 'inc/wpcli/block-starter/editor.js'; - $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/editor.scss'; + $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/editor.css'; if ( ! $this->init_filesystem()->exists( $assets_js ) || ! $this->init_filesystem()->exists( $assets_css ) ) { WP_CLI::error( 'ERROR :: Could not find editor assets.', true ); } // copy editor js. - if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'src/blocks/' . $this->name . '/editor.js' ) ) { + if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'blocks/' . $this->name . '/editor.js' ) ) { WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); } // copy editor css. - if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'src/blocks/' . $this->name . '/editor.scss' ) ) { + if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'blocks/' . $this->name . '/editor.css' ) ) { WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); } @@ -228,22 +228,24 @@ private function create_block_editor_assets() { */ private function create_block_assets() { $assets_js = ROOT_PATH . 'inc/wpcli/block-starter/script.js'; - $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/style.scss'; + $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/style.css'; - if ( ! $this->init_filesystem()->exists( $assets_js ) || ! $this->init_filesystem()->exists( $assets_css ) ) { + if ( + ! $this->init_filesystem()->exists( $assets_js ) + || ! $this->init_filesystem()->exists( $assets_css ) + ) { WP_CLI::error( 'ERROR :: Could not find block assets.', true ); } // copy editor js. - if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'src/blocks/' . $this->name . '/script.js' ) ) { + if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'blocks/' . $this->name . '/script.js' ) ) { WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); } // copy editor css. - if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'src/blocks/' . $this->name . '/style.scss' ) ) { + if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'blocks/' . $this->name . '/style.css' ) ) { WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); } - } } @@ -268,10 +270,10 @@ function cli_register_commands() { * @since 2.0.0 */ function wds_acf_register_blocks() { - $wds_acf_blocks = glob( ROOT_PATH . 'build/blocks/*' ); + $wds_acf_blocks = glob( ROOT_PATH . 'blocks/*/block.json' ); foreach ( $wds_acf_blocks as $block ) { register_block_type( $block ); } } -add_action( 'acf/init', __NAMESPACE__ . '\wds_acf_register_blocks' ); +add_action( 'init', __NAMESPACE__ . '\wds_acf_register_blocks' ); From 2e555af3fc54b98c65f85b187da0ae63973538fe Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:24:52 -0500 Subject: [PATCH 16/22] exclude generated ACF JSON files --- lefthook.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lefthook.yml b/lefthook.yml index e1cda7bd..6b606ff2 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -25,4 +25,5 @@ pre-commit: run: npx markdownlint-cli {staged_files} --fix other: glob: '*.{yml,json,html}' + exclude: 'acf-json/*.json' run: npx prettier {staged_files} --write From ffdeef9fd990fe052dce478ee84ad51640df21b3 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 26 May 2023 16:29:16 -0500 Subject: [PATCH 17/22] simplified ACF block call-to-action --- acf-json/group_6346c08d323e8.json | 149 +++++++++++++++++++++++ blocks/call-to-action/block.json | 33 +++++ blocks/call-to-action/call-to-action.php | 29 +++++ blocks/call-to-action/editor.asset.php | 5 + blocks/call-to-action/editor.css | 1 + blocks/call-to-action/editor.js | 3 + blocks/call-to-action/index.js | 1 + blocks/call-to-action/script.asset.php | 5 + blocks/call-to-action/script.js | 9 ++ blocks/call-to-action/style.css | 51 ++++++++ blocks/modules/call-to-action-center.php | 56 +++++++++ blocks/modules/call-to-action-left.php | 56 +++++++++ blocks/modules/call-to-action-right.php | 56 +++++++++ 13 files changed, 454 insertions(+) create mode 100644 acf-json/group_6346c08d323e8.json create mode 100644 blocks/call-to-action/block.json create mode 100644 blocks/call-to-action/call-to-action.php create mode 100644 blocks/call-to-action/editor.asset.php create mode 100644 blocks/call-to-action/editor.css create mode 100644 blocks/call-to-action/editor.js create mode 100644 blocks/call-to-action/index.js create mode 100644 blocks/call-to-action/script.asset.php create mode 100644 blocks/call-to-action/script.js create mode 100644 blocks/call-to-action/style.css create mode 100644 blocks/modules/call-to-action-center.php create mode 100644 blocks/modules/call-to-action-left.php create mode 100644 blocks/modules/call-to-action-right.php diff --git a/acf-json/group_6346c08d323e8.json b/acf-json/group_6346c08d323e8.json new file mode 100644 index 00000000..6b7a842d --- /dev/null +++ b/acf-json/group_6346c08d323e8.json @@ -0,0 +1,149 @@ +{ + "key": "group_6346c08d323e8", + "title": "Block: Call to Action", + "fields": [ + { + "key": "field_635294c342393", + "label": "", + "name": "", + "aria-label": "", + "type": "message", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "message": "

Call to Action Block

", + "new_lines": "wpautop", + "esc_html": 0 + }, + { + "key": "field_6346c08d2eb6f", + "label": "Eyebrow", + "name": "eyebrow", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + }, + { + "key": "field_6346c135fd3e5", + "label": "Heading", + "name": "heading", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + }, + { + "key": "field_6346c16186509", + "label": "Content", + "name": "content", + "aria-label": "", + "type": "textarea", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "rows": 3, + "placeholder": "", + "new_lines": "wpautop" + }, + { + "key": "field_6346c13efd3e6", + "label": "Button", + "name": "button_args", + "aria-label": "", + "type": "clone", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "clone": [ "group_59416d894b7c7" ], + "display": "seamless", + "layout": "block", + "prefix_label": 0, + "prefix_name": 0 + }, + { + "key": "field_6346ce226e894", + "label": "Layout", + "name": "layout", + "aria-label": "", + "type": "radio", + "instructions": "Left-aligned or Right-aligned content. The button will be on the opposite side of the content.\r\nCenter will stack and center-align the content.", + "required": 1, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": { + "left": "Left", + "right": "Right", + "center": "Center" + }, + "default_value": "left", + "return_format": "value", + "allow_null": 0, + "other_choice": 0, + "layout": "vertical", + "save_other_choice": 0 + } + ], + "location": [ + [ + { + "param": "block", + "operator": "==", + "value": "wds/call-to-action" + } + ] + ], + "menu_order": 0, + "position": "normal", + "style": "default", + "label_placement": "top", + "instruction_placement": "label", + "hide_on_screen": "", + "active": true, + "description": "", + "show_in_rest": 0, + "modified": 1685136357 +} diff --git a/blocks/call-to-action/block.json b/blocks/call-to-action/block.json new file mode 100644 index 00000000..5ae801d9 --- /dev/null +++ b/blocks/call-to-action/block.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "wds/call-to-action", + "title": "Call to Action", + "description": "This block is used for wds.", + "editorStyle": "file:./editor.css", + "editorScript": "./editor.js", + "style": "file:./style.css", + "script": "./script.js", + "category": "WDS", + "icon": "megaphone", + "keywords": [ "call-to-action", "call-to-action", "block" ], + "acf": { + "mode": "auto", + "renderTemplate": "call-to-action.php" + }, + "supports": { + "align": false, + "anchor": true, + "color": {}, + "customClassName": true, + "jsx": true + }, + "example": { + "attributes": { + "mode": "preview", + "data": { + "_is_preview": "true" + } + } + } +} diff --git a/blocks/call-to-action/call-to-action.php b/blocks/call-to-action/call-to-action.php new file mode 100644 index 00000000..20b93776 --- /dev/null +++ b/blocks/call-to-action/call-to-action.php @@ -0,0 +1,29 @@ + [ 'wds-block', 'wds-block-call-to-action' ], + 'allowed_innerblocks' => [ 'core/heading', 'core/paragraph' ], + 'id' => ( isset( $wds_block ) && ! empty( $wds_block['anchor'] ) ) ? $wds_block['anchor'] : '', + 'fields' => [ 'eyebrow', 'heading', 'content', 'button_args', 'layout' ], +]; + +?> +
+ '; + endif; + + get_template_part( 'blocks/modules/call-to-action-' . get_field( 'layout' ), null, $wds_args ); + ?> +
diff --git a/blocks/call-to-action/editor.asset.php b/blocks/call-to-action/editor.asset.php new file mode 100644 index 00000000..89a47ef4 --- /dev/null +++ b/blocks/call-to-action/editor.asset.php @@ -0,0 +1,5 @@ + array(), + 'version' => 'dcc7a84d-24a4498fa6946bbc7acaf8df', +); diff --git a/blocks/call-to-action/editor.css b/blocks/call-to-action/editor.css new file mode 100644 index 00000000..b3c58707 --- /dev/null +++ b/blocks/call-to-action/editor.css @@ -0,0 +1 @@ +/* stylelint-disable-next-line no-empty-source */ diff --git a/blocks/call-to-action/editor.js b/blocks/call-to-action/editor.js new file mode 100644 index 00000000..21ee7b42 --- /dev/null +++ b/blocks/call-to-action/editor.js @@ -0,0 +1,3 @@ +import './editor.css'; + +// Editor JS here. diff --git a/blocks/call-to-action/index.js b/blocks/call-to-action/index.js new file mode 100644 index 00000000..aa3357bf --- /dev/null +++ b/blocks/call-to-action/index.js @@ -0,0 +1 @@ +import './style.css'; diff --git a/blocks/call-to-action/script.asset.php b/blocks/call-to-action/script.asset.php new file mode 100644 index 00000000..e1823fc8 --- /dev/null +++ b/blocks/call-to-action/script.asset.php @@ -0,0 +1,5 @@ + array(), + 'version' => '17f883e691f5408985a1d4725664e7f5', +); diff --git a/blocks/call-to-action/script.js b/blocks/call-to-action/script.js new file mode 100644 index 00000000..164b1d83 --- /dev/null +++ b/blocks/call-to-action/script.js @@ -0,0 +1,9 @@ +/** + * Block script. + * + * @package + * @since 2.0.0 + */ +import './style.css'; + +// add JS here. diff --git a/blocks/call-to-action/style.css b/blocks/call-to-action/style.css new file mode 100644 index 00000000..196b9345 --- /dev/null +++ b/blocks/call-to-action/style.css @@ -0,0 +1,51 @@ +.wds-block-call-to-action { + margin-left: auto; + margin-right: auto; + padding-left: 1rem; + padding-right: 1rem; + width: 100% +} + +@media (min-width:100%) { + .wds-block-call-to-action { + max-width: 100% + } +} + +@media (min-width:1200px) { + .wds-block-call-to-action { + max-width: 1200px + } +} + +@media (min-width:600px) { + .wds-block-call-to-action .wds-module-call-to-action { + -moz-column-gap: 1rem; + column-gap: 1rem; + display: grid; + grid-template-columns: repeat(12, minmax(0, 1fr)) + } +} + +.wds-block-call-to-action .center-content { + grid-column: span 12/span 12; + text-align: center +} + +@media (min-width:600px) { + + .wds-block-call-to-action .left-content, + .wds-block-call-to-action .right-content { + grid-column: span 9/span 9 + } +} + +.wds-block-call-to-action .right-content { + grid-column-start: 1 +} + +@media (min-width:600px) { + .wds-block-call-to-action .right-content { + grid-column-start: 4 + } +} diff --git a/blocks/modules/call-to-action-center.php b/blocks/modules/call-to-action-center.php new file mode 100644 index 00000000..a9ede995 --- /dev/null +++ b/blocks/modules/call-to-action-center.php @@ -0,0 +1,56 @@ + [ 'wds-module', 'wds-module-call-to-action' ], + 'eyebrow' => false, + 'heading' => false, + 'content' => false, + 'button_args' => false, +]; + +$wds_args = wp_parse_args( $args, $wds_defaults ); + +// Set up element attributes. +$wds_atts = $wds_args['class']; + +?> +
+
+ + + +

+ +
+ + + +
+
diff --git a/blocks/modules/call-to-action-left.php b/blocks/modules/call-to-action-left.php new file mode 100644 index 00000000..460dd4dd --- /dev/null +++ b/blocks/modules/call-to-action-left.php @@ -0,0 +1,56 @@ + [ 'wds-module', 'wds-module-call-to-action' ], + 'eyebrow' => false, + 'heading' => false, + 'content' => false, + 'button_args' => false, +]; + +$wds_args = wp_parse_args( $args, $wds_defaults ); + +// Set up element attributes. +$wds_atts = $wds_args['class']; + +?> +
+
+ + + +

+ +
+ + + +
+
diff --git a/blocks/modules/call-to-action-right.php b/blocks/modules/call-to-action-right.php new file mode 100644 index 00000000..879e6cef --- /dev/null +++ b/blocks/modules/call-to-action-right.php @@ -0,0 +1,56 @@ + [ 'wds-module', 'wds-module-call-to-action' ], + 'eyebrow' => false, + 'heading' => false, + 'content' => false, + 'button_args' => false, +]; + +$wds_args = wp_parse_args( $args, $wds_defaults ); + +// Set up element attributes. +$wds_atts = $wds_args['class']; + +?> +
+
+ + + +

+ +
+ + + +
+
From f6a6c5d8e4d65544946ffcb075f1633a6fb76450 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 2 Jun 2023 15:52:04 -0500 Subject: [PATCH 18/22] removed CSS files | fixed JS file inclusion | set block category --- blocks/call-to-action/block.json | 8 ++-- blocks/call-to-action/editor.asset.php | 2 +- blocks/call-to-action/editor.css | 1 - blocks/call-to-action/editor.js | 2 - blocks/call-to-action/index.js | 1 - blocks/call-to-action/script.asset.php | 2 +- blocks/call-to-action/script.js | 1 - blocks/call-to-action/style.css | 51 ------------------------ inc/wpcli/block-starter/block.json | 8 ++-- inc/wpcli/block-starter/editor.asset.php | 5 +++ inc/wpcli/block-starter/editor.css | 1 - inc/wpcli/block-starter/editor.js | 2 - inc/wpcli/block-starter/script.asset.php | 5 +++ inc/wpcli/block-starter/script.js | 1 - inc/wpcli/block-starter/style.css | 1 - inc/wpcli/class-blocks-scaffold.php | 35 +++++++--------- 16 files changed, 33 insertions(+), 93 deletions(-) delete mode 100644 blocks/call-to-action/editor.css delete mode 100644 blocks/call-to-action/index.js delete mode 100644 blocks/call-to-action/style.css create mode 100644 inc/wpcli/block-starter/editor.asset.php delete mode 100644 inc/wpcli/block-starter/editor.css create mode 100644 inc/wpcli/block-starter/script.asset.php delete mode 100644 inc/wpcli/block-starter/style.css diff --git a/blocks/call-to-action/block.json b/blocks/call-to-action/block.json index 5ae801d9..63483448 100644 --- a/blocks/call-to-action/block.json +++ b/blocks/call-to-action/block.json @@ -4,11 +4,9 @@ "name": "wds/call-to-action", "title": "Call to Action", "description": "This block is used for wds.", - "editorStyle": "file:./editor.css", - "editorScript": "./editor.js", - "style": "file:./style.css", - "script": "./script.js", - "category": "WDS", + "editorScript": "file:./editor.js", + "script": "file:./script.js", + "category": "wds-blocks-category", "icon": "megaphone", "keywords": [ "call-to-action", "call-to-action", "block" ], "acf": { diff --git a/blocks/call-to-action/editor.asset.php b/blocks/call-to-action/editor.asset.php index 89a47ef4..505aed18 100644 --- a/blocks/call-to-action/editor.asset.php +++ b/blocks/call-to-action/editor.asset.php @@ -1,5 +1,5 @@ array(), - 'version' => 'dcc7a84d-24a4498fa6946bbc7acaf8df', + 'version' => false, ); diff --git a/blocks/call-to-action/editor.css b/blocks/call-to-action/editor.css deleted file mode 100644 index b3c58707..00000000 --- a/blocks/call-to-action/editor.css +++ /dev/null @@ -1 +0,0 @@ -/* stylelint-disable-next-line no-empty-source */ diff --git a/blocks/call-to-action/editor.js b/blocks/call-to-action/editor.js index 21ee7b42..626553d3 100644 --- a/blocks/call-to-action/editor.js +++ b/blocks/call-to-action/editor.js @@ -1,3 +1 @@ -import './editor.css'; - // Editor JS here. diff --git a/blocks/call-to-action/index.js b/blocks/call-to-action/index.js deleted file mode 100644 index aa3357bf..00000000 --- a/blocks/call-to-action/index.js +++ /dev/null @@ -1 +0,0 @@ -import './style.css'; diff --git a/blocks/call-to-action/script.asset.php b/blocks/call-to-action/script.asset.php index e1823fc8..505aed18 100644 --- a/blocks/call-to-action/script.asset.php +++ b/blocks/call-to-action/script.asset.php @@ -1,5 +1,5 @@ array(), - 'version' => '17f883e691f5408985a1d4725664e7f5', + 'version' => false, ); diff --git a/blocks/call-to-action/script.js b/blocks/call-to-action/script.js index 164b1d83..89edcf11 100644 --- a/blocks/call-to-action/script.js +++ b/blocks/call-to-action/script.js @@ -4,6 +4,5 @@ * @package * @since 2.0.0 */ -import './style.css'; // add JS here. diff --git a/blocks/call-to-action/style.css b/blocks/call-to-action/style.css deleted file mode 100644 index 196b9345..00000000 --- a/blocks/call-to-action/style.css +++ /dev/null @@ -1,51 +0,0 @@ -.wds-block-call-to-action { - margin-left: auto; - margin-right: auto; - padding-left: 1rem; - padding-right: 1rem; - width: 100% -} - -@media (min-width:100%) { - .wds-block-call-to-action { - max-width: 100% - } -} - -@media (min-width:1200px) { - .wds-block-call-to-action { - max-width: 1200px - } -} - -@media (min-width:600px) { - .wds-block-call-to-action .wds-module-call-to-action { - -moz-column-gap: 1rem; - column-gap: 1rem; - display: grid; - grid-template-columns: repeat(12, minmax(0, 1fr)) - } -} - -.wds-block-call-to-action .center-content { - grid-column: span 12/span 12; - text-align: center -} - -@media (min-width:600px) { - - .wds-block-call-to-action .left-content, - .wds-block-call-to-action .right-content { - grid-column: span 9/span 9 - } -} - -.wds-block-call-to-action .right-content { - grid-column-start: 1 -} - -@media (min-width:600px) { - .wds-block-call-to-action .right-content { - grid-column-start: 4 - } -} diff --git a/inc/wpcli/block-starter/block.json b/inc/wpcli/block-starter/block.json index 23572c8b..3803eed4 100644 --- a/inc/wpcli/block-starter/block.json +++ b/inc/wpcli/block-starter/block.json @@ -4,11 +4,9 @@ "name": "wds/{{name}}", "title": "{{title}}", "description": "{{description}}", - "editorStyle": "file:./editor.css", - "editorScript": "./editor.js", - "style": "file:./style.css", - "script": "./script.js", - "category": "WDS", + "editorScript": "file:./editor.js", + "script": "file:./script.js", + "category": "wds-blocks-category", "icon": "{{icon}}", "keywords": [ "{{name}}", "{{keyword}}", "block" ], "acf": { diff --git a/inc/wpcli/block-starter/editor.asset.php b/inc/wpcli/block-starter/editor.asset.php new file mode 100644 index 00000000..505aed18 --- /dev/null +++ b/inc/wpcli/block-starter/editor.asset.php @@ -0,0 +1,5 @@ + array(), + 'version' => false, +); diff --git a/inc/wpcli/block-starter/editor.css b/inc/wpcli/block-starter/editor.css deleted file mode 100644 index b3c58707..00000000 --- a/inc/wpcli/block-starter/editor.css +++ /dev/null @@ -1 +0,0 @@ -/* stylelint-disable-next-line no-empty-source */ diff --git a/inc/wpcli/block-starter/editor.js b/inc/wpcli/block-starter/editor.js index 21ee7b42..626553d3 100644 --- a/inc/wpcli/block-starter/editor.js +++ b/inc/wpcli/block-starter/editor.js @@ -1,3 +1 @@ -import './editor.css'; - // Editor JS here. diff --git a/inc/wpcli/block-starter/script.asset.php b/inc/wpcli/block-starter/script.asset.php new file mode 100644 index 00000000..505aed18 --- /dev/null +++ b/inc/wpcli/block-starter/script.asset.php @@ -0,0 +1,5 @@ + array(), + 'version' => false, +); diff --git a/inc/wpcli/block-starter/script.js b/inc/wpcli/block-starter/script.js index 164b1d83..89edcf11 100644 --- a/inc/wpcli/block-starter/script.js +++ b/inc/wpcli/block-starter/script.js @@ -4,6 +4,5 @@ * @package * @since 2.0.0 */ -import './style.css'; // add JS here. diff --git a/inc/wpcli/block-starter/style.css b/inc/wpcli/block-starter/style.css deleted file mode 100644 index b3c58707..00000000 --- a/inc/wpcli/block-starter/style.css +++ /dev/null @@ -1 +0,0 @@ -/* stylelint-disable-next-line no-empty-source */ diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index 777121cf..26c9d730 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -201,23 +201,21 @@ private function create_block_json( $args ) { * @author Biplav Subedi */ private function create_block_editor_assets() { - $assets_js = ROOT_PATH . 'inc/wpcli/block-starter/editor.js'; - $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/editor.css'; + $asset_js = ROOT_PATH . 'inc/wpcli/block-starter/editor.js'; + $asset_php = ROOT_PATH . 'inc/wpcli/block-starter/editor.asset.php'; - if ( ! $this->init_filesystem()->exists( $assets_js ) || ! $this->init_filesystem()->exists( $assets_css ) ) { + if ( ! $this->init_filesystem()->exists( $asset_js ) ) { WP_CLI::error( 'ERROR :: Could not find editor assets.', true ); } // copy editor js. - if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'blocks/' . $this->name . '/editor.js' ) ) { + if ( ! $this->init_filesystem()->copy( $asset_js, ROOT_PATH . 'blocks/' . $this->name . '/editor.js' ) ) { WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); } - - // copy editor css. - if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'blocks/' . $this->name . '/editor.css' ) ) { - WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + // copy editor.asset.php. + if ( ! $this->init_filesystem()->copy( $asset_php, ROOT_PATH . 'blocks/' . $this->name . '/editor.asset.php' ) ) { + WP_CLI::error( 'ERROR :: Could not create editor asset php file.', true ); } - } /** @@ -227,24 +225,21 @@ private function create_block_editor_assets() { * @author Biplav Subedi */ private function create_block_assets() { - $assets_js = ROOT_PATH . 'inc/wpcli/block-starter/script.js'; - $assets_css = ROOT_PATH . 'inc/wpcli/block-starter/style.css'; + $asset_js = ROOT_PATH . 'inc/wpcli/block-starter/script.js'; + $asset_php = ROOT_PATH . 'inc/wpcli/block-starter/script.asset.php'; - if ( - ! $this->init_filesystem()->exists( $assets_js ) - || ! $this->init_filesystem()->exists( $assets_css ) - ) { + if ( ! $this->init_filesystem()->exists( $asset_js ) ) { WP_CLI::error( 'ERROR :: Could not find block assets.', true ); } // copy editor js. - if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'blocks/' . $this->name . '/script.js' ) ) { - WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + if ( ! $this->init_filesystem()->copy( $asset_js, ROOT_PATH . 'blocks/' . $this->name . '/script.js' ) ) { + WP_CLI::error( 'ERROR :: Could not create script js file.', true ); } - // copy editor css. - if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'blocks/' . $this->name . '/style.css' ) ) { - WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); + // copy script.asset.php. + if ( ! $this->init_filesystem()->copy( $asset_php, ROOT_PATH . 'blocks/' . $this->name . '/script.asset.php' ) ) { + WP_CLI::error( 'ERROR :: Could not create script asset php file.', true ); } } From 9e6c8784407b8f70cefa455badc16d7a9c5445b6 Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 2 Jun 2023 16:16:18 -0500 Subject: [PATCH 19/22] test exlude acf json files --- acf-json/group_6346c08d323e8.json | 298 +++++++++++++++--------------- 1 file changed, 150 insertions(+), 148 deletions(-) diff --git a/acf-json/group_6346c08d323e8.json b/acf-json/group_6346c08d323e8.json index 6b7a842d..05b3146b 100644 --- a/acf-json/group_6346c08d323e8.json +++ b/acf-json/group_6346c08d323e8.json @@ -1,149 +1,151 @@ { - "key": "group_6346c08d323e8", - "title": "Block: Call to Action", - "fields": [ - { - "key": "field_635294c342393", - "label": "", - "name": "", - "aria-label": "", - "type": "message", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "message": "

Call to Action Block

", - "new_lines": "wpautop", - "esc_html": 0 - }, - { - "key": "field_6346c08d2eb6f", - "label": "Eyebrow", - "name": "eyebrow", - "aria-label": "", - "type": "text", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "default_value": "", - "maxlength": "", - "placeholder": "", - "prepend": "", - "append": "" - }, - { - "key": "field_6346c135fd3e5", - "label": "Heading", - "name": "heading", - "aria-label": "", - "type": "text", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "default_value": "", - "maxlength": "", - "placeholder": "", - "prepend": "", - "append": "" - }, - { - "key": "field_6346c16186509", - "label": "Content", - "name": "content", - "aria-label": "", - "type": "textarea", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "default_value": "", - "maxlength": "", - "rows": 3, - "placeholder": "", - "new_lines": "wpautop" - }, - { - "key": "field_6346c13efd3e6", - "label": "Button", - "name": "button_args", - "aria-label": "", - "type": "clone", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "clone": [ "group_59416d894b7c7" ], - "display": "seamless", - "layout": "block", - "prefix_label": 0, - "prefix_name": 0 - }, - { - "key": "field_6346ce226e894", - "label": "Layout", - "name": "layout", - "aria-label": "", - "type": "radio", - "instructions": "Left-aligned or Right-aligned content. The button will be on the opposite side of the content.\r\nCenter will stack and center-align the content.", - "required": 1, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "choices": { - "left": "Left", - "right": "Right", - "center": "Center" - }, - "default_value": "left", - "return_format": "value", - "allow_null": 0, - "other_choice": 0, - "layout": "vertical", - "save_other_choice": 0 - } - ], - "location": [ - [ - { - "param": "block", - "operator": "==", - "value": "wds/call-to-action" - } - ] - ], - "menu_order": 0, - "position": "normal", - "style": "default", - "label_placement": "top", - "instruction_placement": "label", - "hide_on_screen": "", - "active": true, - "description": "", - "show_in_rest": 0, - "modified": 1685136357 -} + "key": "group_6346c08d323e8", + "title": "Block: Call to Action", + "fields": [ + { + "key": "field_635294c342393", + "label": "", + "name": "", + "aria-label": "", + "type": "message", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "message": "

Call to Action Block<\/h2>", + "new_lines": "wpautop", + "esc_html": 0 + }, + { + "key": "field_6346c08d2eb6f", + "label": "Eyebrow", + "name": "eyebrow", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + }, + { + "key": "field_6346c135fd3e5", + "label": "Heading", + "name": "heading", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + }, + { + "key": "field_6346c16186509", + "label": "Content", + "name": "content", + "aria-label": "", + "type": "textarea", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "rows": 3, + "placeholder": "", + "new_lines": "wpautop" + }, + { + "key": "field_6346c13efd3e6", + "label": "Button", + "name": "button_args", + "aria-label": "", + "type": "clone", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "clone": [ + "group_59416d894b7c7" + ], + "display": "seamless", + "layout": "block", + "prefix_label": 0, + "prefix_name": 0 + }, + { + "key": "field_6346ce226e894", + "label": "Layout", + "name": "layout", + "aria-label": "", + "type": "radio", + "instructions": "Left-aligned or Right-aligned content. The button will be on the opposite side of the content.\r\nCenter will stack and center-align the content.", + "required": 1, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": { + "left": "Left", + "right": "Right", + "center": "Center" + }, + "default_value": "left", + "return_format": "value", + "allow_null": 0, + "other_choice": 0, + "layout": "vertical", + "save_other_choice": 0 + } + ], + "location": [ + [ + { + "param": "block", + "operator": "==", + "value": "wds\/call-to-action" + } + ] + ], + "menu_order": 0, + "position": "normal", + "style": "default", + "label_placement": "top", + "instruction_placement": "label", + "hide_on_screen": "", + "active": true, + "description": "", + "show_in_rest": 0, + "modified": 1685740553 +} \ No newline at end of file From 038f9adb93d59c50cab81a576f0449a684f44f5d Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Fri, 2 Jun 2023 16:18:18 -0500 Subject: [PATCH 20/22] properly exclude generated ACF field groups (otherwise changes to field groups stop commits) --- lefthook.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lefthook.yml b/lefthook.yml index 6b606ff2..9e4ca127 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -25,5 +25,6 @@ pre-commit: run: npx markdownlint-cli {staged_files} --fix other: glob: '*.{yml,json,html}' - exclude: 'acf-json/*.json' + exclude: 'group_*.json' run: npx prettier {staged_files} --write + stage_fixed: true From 936cac3b5635caf77e68ad0fa438707ab1070d4e Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 7 Jun 2023 01:47:45 +0800 Subject: [PATCH 21/22] WDSUS-7 - Change CTA block category --- blocks/call-to-action/block.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/call-to-action/block.json b/blocks/call-to-action/block.json index 5ae801d9..67bf352e 100644 --- a/blocks/call-to-action/block.json +++ b/blocks/call-to-action/block.json @@ -8,7 +8,7 @@ "editorScript": "./editor.js", "style": "file:./style.css", "script": "./script.js", - "category": "WDS", + "category": "wds-blocks-category", "icon": "megaphone", "keywords": [ "call-to-action", "call-to-action", "block" ], "acf": { From b42f28ca5f970c7e1f4bb1a67176be656dd5f5cd Mon Sep 17 00:00:00 2001 From: guzmandrade-wds Date: Wed, 21 Jun 2023 16:16:00 -0500 Subject: [PATCH 22/22] porting changes from `wd_f` --- acf-json/group_6346c08d323e8.json | 12 ++++-------- blocks/modules/call-to-action-center.php | 16 +++++++++------- blocks/modules/call-to-action-left.php | 16 +++++++++------- blocks/modules/call-to-action-right.php | 16 +++++++++------- inc/wpcli/block-starter/block.php | 2 +- inc/wpcli/class-blocks-scaffold.php | 2 +- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/acf-json/group_6346c08d323e8.json b/acf-json/group_6346c08d323e8.json index bffc85e7..7f246471 100644 --- a/acf-json/group_6346c08d323e8.json +++ b/acf-json/group_6346c08d323e8.json @@ -83,9 +83,9 @@ { "key": "field_6346c13efd3e6", "label": "Button", - "name": "button_args", + "name": "button", "aria-label": "", - "type": "clone", + "type": "link", "instructions": "", "required": 0, "conditional_logic": 0, @@ -94,11 +94,7 @@ "class": "", "id": "" }, - "clone": [ "group_59416d894b7c7" ], - "display": "seamless", - "layout": "block", - "prefix_label": 0, - "prefix_name": 0 + "return_format": "array" }, { "key": "field_6346ce226e894", @@ -145,5 +141,5 @@ "active": true, "description": "", "show_in_rest": 0, - "modified": 1685740553 + "modified": 1687376907 } diff --git a/blocks/modules/call-to-action-center.php b/blocks/modules/call-to-action-center.php index a9ede995..e42241ed 100644 --- a/blocks/modules/call-to-action-center.php +++ b/blocks/modules/call-to-action-center.php @@ -10,11 +10,11 @@ */ $wds_defaults = [ - 'class' => [ 'wds-module', 'wds-module-call-to-action' ], - 'eyebrow' => false, - 'heading' => false, - 'content' => false, - 'button_args' => false, + 'class' => [ 'wds-module', 'wds-module-call-to-action' ], + 'eyebrow' => false, + 'heading' => false, + 'content' => false, + 'button' => false, ]; $wds_args = wp_parse_args( $args, $wds_defaults ); @@ -48,9 +48,11 @@ endif; // Button. - if ( ! empty( $wds_args['button_args']['button'] ) ) : + if ( ! empty( $wds_args['button'] ) ) : ?> - + + + diff --git a/blocks/modules/call-to-action-left.php b/blocks/modules/call-to-action-left.php index 460dd4dd..1d307a3d 100644 --- a/blocks/modules/call-to-action-left.php +++ b/blocks/modules/call-to-action-left.php @@ -10,11 +10,11 @@ */ $wds_defaults = [ - 'class' => [ 'wds-module', 'wds-module-call-to-action' ], - 'eyebrow' => false, - 'heading' => false, - 'content' => false, - 'button_args' => false, + 'class' => [ 'wds-module', 'wds-module-call-to-action' ], + 'eyebrow' => false, + 'heading' => false, + 'content' => false, + 'button' => false, ]; $wds_args = wp_parse_args( $args, $wds_defaults ); @@ -48,9 +48,11 @@ endif; // Button. - if ( ! empty( $wds_args['button_args']['button'] ) ) : + if ( ! empty( $wds_args['button'] ) ) : ?> - + + + diff --git a/blocks/modules/call-to-action-right.php b/blocks/modules/call-to-action-right.php index 879e6cef..9454166a 100644 --- a/blocks/modules/call-to-action-right.php +++ b/blocks/modules/call-to-action-right.php @@ -10,11 +10,11 @@ */ $wds_defaults = [ - 'class' => [ 'wds-module', 'wds-module-call-to-action' ], - 'eyebrow' => false, - 'heading' => false, - 'content' => false, - 'button_args' => false, + 'class' => [ 'wds-module', 'wds-module-call-to-action' ], + 'eyebrow' => false, + 'heading' => false, + 'content' => false, + 'button' => false, ]; $wds_args = wp_parse_args( $args, $wds_defaults ); @@ -48,9 +48,11 @@ endif; // Button. - if ( ! empty( $wds_args['button_args']['button'] ) ) : + if ( ! empty( $wds_args['button'] ) ) : ?> - + + + diff --git a/inc/wpcli/block-starter/block.php b/inc/wpcli/block-starter/block.php index 570a8d2d..61467ac8 100644 --- a/inc/wpcli/block-starter/block.php +++ b/inc/wpcli/block-starter/block.php @@ -2,5 +2,5 @@ /** * Your block render code goes here. * - * @package wd_s + * @package wds */ diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php index 26c9d730..a94ca417 100644 --- a/inc/wpcli/class-blocks-scaffold.php +++ b/inc/wpcli/class-blocks-scaffold.php @@ -80,7 +80,7 @@ public function create_portable_block( $name, $assoc_args ) { 'desc' => '', 'keywords' => strtolower( $this->name ), 'icon' => 'table-row-before', - 'namespace' => 'wds', + 'namespace' => 'wds/', ] );