Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
👌 IMPROVE: Docs & Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadawais committed Nov 29, 2018
1 parent 2946d04 commit 60cc429
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 74 deletions.
26 changes: 12 additions & 14 deletions examples/01-single-block/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Enqueue CSS/JS of all the blocks.
*
* @since 1.0.0
* @since 1.0.0
* @package CGB
*/

Expand All @@ -16,8 +16,7 @@
/**
* Enqueue Gutenberg block assets for both frontend + backend.
*
* `wp-editor`: WP editor styles.
*
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function single_block_cgb_block_assets() {
Expand All @@ -26,21 +25,20 @@ function single_block_cgb_block_assets() {
'single_block-cgb-style-css', // Handle.
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
} // End function single_block_cgb_block_assets().
}

// Hook: Frontend assets.
add_action( 'enqueue_block_assets', 'single_block_cgb_block_assets' );

/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: internationalize the block's text.
* `wp-editor`: WP editor styles.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function single_block_cgb_editor_assets() {
Expand All @@ -49,17 +47,17 @@ function single_block_cgb_editor_assets() {
'single_block-cgb-block-js', // Handle.
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: File modification time.
);

// Styles.
wp_enqueue_style(
'single_block-cgb-block-editor-css', // Handle.
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
);
} // End function single_block_cgb_editor_assets().
}

// Hook: Editor assets.
add_action( 'enqueue_block_editor_assets', 'single_block_cgb_editor_assets' );
add_action( 'enqueue_block_editor_assets', 'single_block_cgb_editor_assets' );
22 changes: 10 additions & 12 deletions examples/02-single-block-ejected/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Enqueue CSS/JS of all the blocks.
*
* @since 1.0.0
* @since 1.0.0
* @package CGB
*/

Expand All @@ -16,8 +16,7 @@
/**
* Enqueue Gutenberg block assets for both frontend + backend.
*
* `wp-editor`: WP editor styles.
*
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function single_block_cgb_block_assets() {
Expand All @@ -26,7 +25,7 @@ function single_block_cgb_block_assets() {
'single_block-cgb-style-css', // Handle.
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
} // End function single_block_cgb_block_assets().

Expand All @@ -36,11 +35,10 @@ function single_block_cgb_block_assets() {
/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: internationalize the block's text.
* `wp-editor`: WP editor styles.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function single_block_cgb_editor_assets() {
Expand All @@ -49,17 +47,17 @@ function single_block_cgb_editor_assets() {
'single_block-cgb-block-js', // Handle.
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: File modification time.
);

// Styles.
wp_enqueue_style(
'single_block-cgb-block-editor-css', // Handle.
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
);
} // End function single_block_cgb_editor_assets().

// Hook: Editor assets.
add_action( 'enqueue_block_editor_assets', 'single_block_cgb_editor_assets' );
add_action( 'enqueue_block_editor_assets', 'single_block_cgb_editor_assets' );
22 changes: 10 additions & 12 deletions examples/03-multi-block/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Enqueue CSS/JS of all the blocks.
*
* @since 1.0.0
* @since 1.0.0
* @package CGB
*/

Expand All @@ -16,8 +16,7 @@
/**
* Enqueue Gutenberg block assets for both frontend + backend.
*
* `wp-editor`: WP editor styles.
*
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function multi_block_cgb_block_assets() {
Expand All @@ -26,7 +25,7 @@ function multi_block_cgb_block_assets() {
'multi_block-cgb-style-css', // Handle.
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
} // End function multi_block_cgb_block_assets().

Expand All @@ -36,11 +35,10 @@ function multi_block_cgb_block_assets() {
/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: internationalize the block's text.
* `wp-editor`: WP editor styles.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function multi_block_cgb_editor_assets() {
Expand All @@ -49,17 +47,17 @@ function multi_block_cgb_editor_assets() {
'multi_block-cgb-block-js', // Handle.
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: File modification time.
);

// Styles.
wp_enqueue_style(
'multi_block-cgb-block-editor-css', // Handle.
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
);
} // End function multi_block_cgb_editor_assets().

// Hook: Editor assets.
add_action( 'enqueue_block_editor_assets', 'multi_block_cgb_editor_assets' );
add_action( 'enqueue_block_editor_assets', 'multi_block_cgb_editor_assets' );
22 changes: 10 additions & 12 deletions examples/04-multi-block-ejected/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Enqueue CSS/JS of all the blocks.
*
* @since 1.0.0
* @since 1.0.0
* @package CGB
*/

Expand All @@ -16,8 +16,7 @@
/**
* Enqueue Gutenberg block assets for both frontend + backend.
*
* `wp-editor`: WP editor styles.
*
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function multi_block_cgb_block_assets() {
Expand All @@ -26,7 +25,7 @@ function multi_block_cgb_block_assets() {
'multi_block-cgb-style-css', // Handle.
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
} // End function multi_block_cgb_block_assets().

Expand All @@ -36,11 +35,10 @@ function multi_block_cgb_block_assets() {
/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: internationalize the block's text.
* `wp-editor`: WP editor styles.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function multi_block_cgb_editor_assets() {
Expand All @@ -49,17 +47,17 @@ function multi_block_cgb_editor_assets() {
'multi_block-cgb-block-js', // Handle.
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ) // Version: File modification time.
);

// Styles.
wp_enqueue_style(
'multi_block-cgb-block-editor-css', // Handle.
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
);
} // End function multi_block_cgb_editor_assets().

// Hook: Editor assets.
add_action( 'enqueue_block_editor_assets', 'multi_block_cgb_editor_assets' );
add_action( 'enqueue_block_editor_assets', 'multi_block_cgb_editor_assets' );
18 changes: 8 additions & 10 deletions examples/05-a11y-input/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
/**
* Enqueue Gutenberg block assets for both frontend + backend.
*
* `wp-editor`: WP editor styles.
*
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function a11y_input_cgb_block_assets() {
Expand All @@ -26,7 +25,7 @@ function a11y_input_cgb_block_assets() {
'a11y_input-cgb-style-css', // Handle.
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
} // End function a11y_input_cgb_block_assets().

Expand All @@ -36,11 +35,10 @@ function a11y_input_cgb_block_assets() {
/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: internationalize the block's text.
* `wp-editor`: WP editor styles.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function a11y_input_cgb_editor_assets() {
Expand All @@ -49,7 +47,7 @@ function a11y_input_cgb_editor_assets() {
'a11y_input-cgb-block-js', // Handle.
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: File modification time.
true // Enqueue the script in the footer.
);

Expand All @@ -58,7 +56,7 @@ function a11y_input_cgb_editor_assets() {
'a11y_input-cgb-block-editor-css', // Handle.
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
);
} // End function a11y_input_cgb_editor_assets().

Expand Down
26 changes: 12 additions & 14 deletions packages/cgb-scripts/template/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,38 @@
/**
* Enqueue Gutenberg block assets for both frontend + backend.
*
* `wp-editor`: WP editor styles.
*
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function <% blockNamePHPLower %>_cgb_block_assets() {
function <% blockNamePHPLower %>_cgb_block_assets() { // phpcs:ignore
// Styles.
wp_enqueue_style(
'<% blockNamePHPLower %>-cgb-style-css', // Handle.
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
array( 'wp-editor' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
);
} // End function <% blockNamePHPLower %>_cgb_block_assets().
}

// Hook: Frontend assets.
add_action( 'enqueue_block_assets', '<% blockNamePHPLower %>_cgb_block_assets' );

/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: internationalize the block's text.
* `wp-editor`: WP editor styles.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
* @since 1.0.0
*/
function <% blockNamePHPLower %>_cgb_editor_assets() {
function <% blockNamePHPLower %>_cgb_editor_assets() { // phpcs:ignore
// Scripts.
wp_enqueue_script(
'<% blockNamePHPLower %>-cgb-block-js', // Handle.
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: File modification time.
true // Enqueue the script in the footer.
);

Expand All @@ -58,9 +56,9 @@ function <% blockNamePHPLower %>_cgb_editor_assets() {
'<% blockNamePHPLower %>-cgb-block-editor-css', // Handle.
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
);
} // End function <% blockNamePHPLower %>_cgb_editor_assets().
}

// Hook: Editor assets.
add_action( 'enqueue_block_editor_assets', '<% blockNamePHPLower %>_cgb_editor_assets' );

0 comments on commit 60cc429

Please sign in to comment.