Skip to content

Commit

Permalink
Merge pull request #23 from t-hamano/wp6.0
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
t-hamano authored May 22, 2022
2 parents 325feab + f02247d commit bff10ca
Show file tree
Hide file tree
Showing 17 changed files with 4,976 additions and 10,536 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
printWidth: 100,
bracketSpacing: true,
parenSpacing: true,
bracketSameLine: false,
},
],
},
Expand Down
9 changes: 8 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
const config = {
...require( '@wordpress/prettier-config' ),
semi: true,
useTabs: true,
Expand All @@ -7,4 +7,11 @@ module.exports = {
printWidth: 100,
bracketSpacing: true,
parenSpacing: true,
// Set new property instead of jsxBracketSameLine
bracketSameLine: false,
}

// Remove deprecated property
delete config.jsxBracketSameLine

module.exports = config;
6 changes: 6 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
build/
vendor/
*.js
*.xml
*.md
9 changes: 0 additions & 9 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@ module.exports = {
'@wordpress/stylelint-config/scss',
'stylelint-config-recess-order',
],
ignoreFiles: [
'build/**/*.css',
'node_modules/**/*.css',
'vendor/**/*.css',
'**/*.js',
'**/*.svg',
'.stylelintrc.js'
],
rules: {
'no-descending-specificity': null,
'function-calc-no-invalid': null,
'selector-class-pattern': null,
'font-weight-notation': null,
}
Expand Down
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,75 @@ $ npm install
$ npm run build
```

## Filters

### `flexible_spacer_block_breakpoint( $breakpoint, $is_editor )`

Filters media query breakpoints.

#### Parameters

- `$breakpoint`

*(array)* media query breakpoints ( `md` / `sm` ).

- `$is_editor`

*(bool)* Whether it is rendered on the editor.

#### Return

*(array)* New media query breakpoints.

#### Example

```php
function custom_flexible_spacer_block_breakpoint( $breakpoint, $is_editor ) {
// Override media query breakpoints.
return array(
'md' => 1000,
'sm' => 500,
);
}
add_filter( 'flexible_spacer_block_breakpoint', 'custom_flexible_spacer_block_breakpoint', 10, 2 );
```

### `flexible_spacer_block_inline_css( $css, $is_editor )`

Filters Generated inline styles.

#### Parameters

- `$css`

*(string)* Generated inline styles.

- `$is_editor`

*(bool)* Whether it is rendered on the editor.

#### Return

*(string)* New inline styles.

#### Example

```php
function custom_flexible_spacer_block_inline_css( $css, $is_editor ) {
// Override z-index value for negative space on the front-end.
if ( ! $is_editor ) {
return str_replace( 'z-index:2;', 'z-index:5;', $css );
}
return $css;
}
add_filter( 'flexible_spacer_block_inline_css', 'custom_flexible_spacer_block_inline_css', 10, 2 );
```

## Resources

### Image for screenshot
* License: CC0 Public Domain
* Source: https://pxhere.com/ja/photo/245
## Author

[Tetsuaki Hamano (Github)](https://github.com/t-hamano)
[Aki Hamano (Github)](https://github.com/t-hamano)
47 changes: 44 additions & 3 deletions classes/class-enqueue.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package Flexible_Spacer_Block
* @author Tetsuaki Hamano
* @author Aki Hamano
* @license GPL-2.0+
*/

Expand Down Expand Up @@ -75,7 +75,7 @@ public function admin_enqueue_scripts( $hook ) {
* Register block
*/
public function register_block() {
register_block_type_from_metadata( FSB_PATH . '/src/' );
register_block_type_from_metadata( FSB_PATH . '/build/js' );
}

/**
Expand Down Expand Up @@ -109,7 +109,18 @@ private function create_inline_style( $is_editor = true ) {
'sm' => FSB_BREAKPOINT_SM,
);

$breakpoint = get_option( 'flexible_spacer_block_breakpoint', $defaults );
$breakpoint = get_option( 'flexible_spacer_block_breakpoint', $defaults );

/**
* Filters media query breakpoints.
*
* @since 1.3.0
*
* @param array $breakpoint media query breakpoints.
* @param bool $is_editor Whether it is rendered on the editor.
*/
$breakpoint = apply_filters( 'flexible_spacer_block_breakpoint', $breakpoint, $is_editor );

$breakpoint_lg_min = $breakpoint['md'] + 1;
$breakpoint_md_max = $breakpoint['md'];
$breakpoint_md_min = $breakpoint['sm'] + 1;
Expand Down Expand Up @@ -186,6 +197,36 @@ private function create_inline_style( $is_editor = true ) {
EOM;
}

$css = self::minify_css( $css );

/**
* Filters Generated inline styles.
*
* @since 1.3.0
*
* @param string $css Generated inline styles.
* @param bool $is_editor Whether it is rendered on the editor.
*/
return apply_filters( 'flexible_spacer_block_inline_css', $css, $is_editor );
}

/**
* Minify CSS
*
* @return string
*/
private function minify_css( $css ) {
$replaces = array();

// phpcs:disable Generic.Formatting.MultipleStatementAlignment
$replaces['/@charset [^;]+;/'] = '';
$replaces['/([\s:]url\()[\"\']([^\"\']+)[\"\'](\)[\s;}])/'] = '${1}${2}${3}';
$replaces['/(\/\*(?=[!]).*?\*\/|\"(?:(?!(?<!\\\)\").)*\"|\'(?:(?!(?<!\\\)\').)*\')|\s+/'] = '${1} ';
$replaces['/(\/\*(?=[!]).*?\*\/|\"(?:(?!(?<!\\\)\").)*\"|\'(?:(?!(?<!\\\)\').)*\')|\/\*.*?\*\/|\s+([:])\s+|\s+([)])|([(:])\s+/s'] = '${1}${2}${3}${4}';
$replaces['/\s*(\/\*(?=[!]).*?\*\/|\"(?:(?!(?<!\\\)\").)*\"|\'(?:(?!(?<!\\\)\').)*\'|[ :]calc\([^;}]+\)[ ;}]|[!$&+,\/;<=>?@^_{|}~]|\A|\z)\s*/s'] = '${1}';
// phpcs:enable

$css = preg_replace( array_keys( $replaces ), array_values( $replaces ), $css );
return $css;
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/class-init.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package Flexible_Spacer_Block
* @author Tetsuaki Hamano
* @author Aki Hamano
* @license GPL-2.0+
*/

Expand Down
2 changes: 1 addition & 1 deletion classes/class-options.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package Flexible_Spacer_Block
* @author Tetsuaki Hamano
* @author Aki Hamano
* @license GPL-2.0+
*/

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "tetsuaki.hamano/flexible-spacer-block",
"name": "t-hamano/flexible-spacer-block",
"description": "WordPress plugin to add white space between blocks and customize its height for each device.",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Tetsuaki Hamano"
"name": "Aki Hamano"
}
],
"require-dev": {
Expand Down
6 changes: 3 additions & 3 deletions flexible-spacer-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Plugin Name: Flexible Spacer Block
* Description: Add white space between blocks and customize its height for each device.
* Version: 1.2.3
* Author: Tetsuaki Hamano
* Version: 1.3.0
* Author: Aki Hamano
* Author URI: https://github.com/t-hamano
* License: GPL2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: flexible-spacer-block
* @package Flexible_Spacer_Block
* @author Tetsuaki Hamano
* @author Aki Hamano
* @license GPL-2.0+
*/

Expand Down
Loading

0 comments on commit bff10ca

Please sign in to comment.