diff --git a/.github/workflows/built-release.yml b/.github/workflows/built-release.yml new file mode 100644 index 0000000..9da461d --- /dev/null +++ b/.github/workflows/built-release.yml @@ -0,0 +1,14 @@ +name: Built Release + +on: + push: + branches: + - develop + - main + - production + +jobs: + built-release: + uses: alleyinteractive/.github/.github/workflows/built-release.yml@main + with: + node: 16 diff --git a/CHANGELOG.md b/CHANGELOG.md index caa8039..5055258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Change Log This project adheres to [Semantic Versioning](http://semver.org/). +## 1.4.0 + +* Migrates code into the `Alley\WP\Asset_Manager` namespace. Legacy classes such + as `Asset_Manager_Scripts` and `Asset_Manager_Styles` are aliased to their new + namespace for backward compatibility. Helper functions are left un-namespaced. +* Adds a dependency on Composer autoloader. For submodules, you can track the + `production-built` branch of the plugin or any tagged release (which will be + built) to include the dependencies. + ## 1.3.6 * Adds support for running the plugin on a Windows hosting environment (#57) diff --git a/asset-manager.php b/asset-manager.php index 1b316ff..d1ab338 100644 --- a/asset-manager.php +++ b/asset-manager.php @@ -7,16 +7,6 @@ * @package AssetManager */ -/* -Plugin Name: Asset Manager -Plugin URI: https://github.com/alleyinteractive/wp-asset-manager -Description: Add more robust functionality to enqueuing static assets -Author: Alley Interactive -Version: 1.4.0 -License: GPLv2 or later -Author URI: https://www.alleyinteractive.com/ -*/ - /** * Filesystem path to AssetManager. */ @@ -28,14 +18,14 @@ } else { add_action( 'admin_notices', - function() { + function () { ?>

@@ -54,7 +44,7 @@ class_alias( \Alley\WP\Asset_Manager\Preload::class, 'Asset_Manager_Preload' ); class_alias( \Alley\WP\Asset_Manager\SVG_Sprite::class, 'Asset_Manager_SVG_Sprite' ); // Require the helpers that are used to interact with the plugin. -require_once __DIR__ . '/inc/helpers.php'; +require_once __DIR__ . '/src/helpers.php'; /** * Map plugin meta capabilities. diff --git a/composer.json b/composer.json index 2370b34..324ec2f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "extra": { "wordpress-autoloader": { "autoload": { - "Alley\\WP\\Asset_Manager\\": "inc/" + "Alley\\WP\\Asset_Manager\\": "src/" }, "autoload-dev": { "Alley\\WP\\Asset_Manager\\Tests\\": "tests/" diff --git a/package.json b/package.json new file mode 100644 index 0000000..a99ba29 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "@alleyinteractive/wp-asset-manager", + "version": "1.4.0", + "description": "Asset Manager is a toolkit for managing front-end assets and more tightly controlling where, when, and how they're loaded.", + "scripts": { + "build": "echo 'No build step defined'", + "release": "npx @alleyinteractive/create-release@latest" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/alleyinteractive/wp-asset-manager.git" + }, + "author": "", + "license": "GPL-2.0+", + "bugs": { + "url": "https://github.com/alleyinteractive/wp-asset-manager/issues" + }, + "homepage": "https://github.com/alleyinteractive/wp-asset-manager#readme" +} diff --git a/inc/class-asset-manager.php b/src/class-asset-manager.php similarity index 100% rename from inc/class-asset-manager.php rename to src/class-asset-manager.php diff --git a/inc/class-preload.php b/src/class-preload.php similarity index 100% rename from inc/class-preload.php rename to src/class-preload.php diff --git a/inc/class-scripts.php b/src/class-scripts.php similarity index 100% rename from inc/class-scripts.php rename to src/class-scripts.php diff --git a/inc/class-styles.php b/src/class-styles.php similarity index 100% rename from inc/class-styles.php rename to src/class-styles.php diff --git a/inc/class-svg-sprite.php b/src/class-svg-sprite.php similarity index 96% rename from inc/class-svg-sprite.php rename to src/class-svg-sprite.php index 6d57b18..3e8c570 100644 --- a/inc/class-svg-sprite.php +++ b/src/class-svg-sprite.php @@ -8,7 +8,8 @@ namespace Alley\WP\Asset_Manager; use DOMDocument; - +use DOMElement; +use DOMText; /** * Asset_Manager_SVG_Sprite class. @@ -22,21 +23,21 @@ class SVG_Sprite { * * @var string */ - public static $_svg_directory; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore + public static ?string $_svg_directory; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore /** * Array for attributes to add to each symbol. * * @var array */ - public static $_global_attributes; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore + public static ?array $_global_attributes; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore /** * The sprite document. * * @var DOMDocument */ - public $sprite_document; + public DOMDocument $sprite_document; /** * The sprite document. @@ -57,14 +58,14 @@ class SVG_Sprite { * * @var array */ - public $sprite_map = []; + public array $sprite_map = []; /** * Allowed tags and attributes for echoing and elements. * * @var array */ - public $kses_svg_allowed_tags = [ + public array $kses_svg_allowed_tags = [ 'svg' => [], 'use' => [ 'href' => true, @@ -83,12 +84,10 @@ protected function __construct() { */ add_filter( 'safe_style_css', - function ( $styles ) { - $styles[] = 'left'; - $styles[] = 'overflow'; - $styles[] = 'position'; - return $styles; - } + fn ( $styles ) => [ + ...array_values( $styles ), + [ 'left', 'overflow', 'position' ], + ], ); add_filter( 'wp_kses_allowed_html', [ $this, 'extend_kses_post_with_use_svg' ] ); @@ -395,7 +394,7 @@ public function add_asset( $asset ): void { return; } - list( $asset, $symbol ) = $this->create_symbol( $asset ); + [ $asset, $symbol ] = $this->create_symbol( $asset ); if ( ! ( $symbol instanceof DOMElement ) ) { return; diff --git a/inc/concerns/trait-asset-error.php b/src/concerns/trait-asset-error.php similarity index 100% rename from inc/concerns/trait-asset-error.php rename to src/concerns/trait-asset-error.php diff --git a/inc/concerns/trait-conditions.php b/src/concerns/trait-conditions.php similarity index 100% rename from inc/concerns/trait-conditions.php rename to src/concerns/trait-conditions.php diff --git a/inc/concerns/trait-singleton.php b/src/concerns/trait-singleton.php similarity index 100% rename from inc/concerns/trait-singleton.php rename to src/concerns/trait-singleton.php diff --git a/inc/helpers.php b/src/helpers.php similarity index 99% rename from inc/helpers.php rename to src/helpers.php index 3ed30b3..ddf4a87 100644 --- a/inc/helpers.php +++ b/src/helpers.php @@ -22,7 +22,7 @@ * * @return bool True if the path is valid, false otherwise. */ - function am_validate_path( string $path ) : bool { + function am_validate_path( string $path ): bool { return in_array( validate_file( $path ), [ 0, 2 ], true ) && file_exists( $path ); } } diff --git a/inc/kses-svg.php b/src/kses-svg.php similarity index 100% rename from inc/kses-svg.php rename to src/kses-svg.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 834511e..2cf6038 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,12 +5,10 @@ * @package WP_Irving */ -use function Mantle\Testing\tests_add_filter; - require_once __DIR__ . '/../vendor/autoload.php'; \Mantle\Testing\manager() - ->loaded( fn () => require dirname( __DIR__ ) . '/asset-manager.php' ) + ->loaded( fn () => require dirname( __DIR__ ) . '/wp-asset-manager.php' ) ->install(); if ( ! function_exists( 'get_echo' ) ) : diff --git a/tests/class-test-case.php b/tests/class-test-case.php index 0487a5e..8234382 100644 --- a/tests/class-test-case.php +++ b/tests/class-test-case.php @@ -31,8 +31,9 @@ abstract class Test_Case extends \Mantle\Testkit\Test_Case { 'src' => 'http://www.example.org/wp-content/themes/example/static/css/test-two.css', ]; - public $global_attributes; - public $svg_directory; + public array $global_attributes = [ 'focusable' => 'false', 'aria-hidden' => 'true' ]; + + public string $svg_directory; protected function setUp(): void { parent::setUp(); @@ -41,39 +42,23 @@ protected function setUp(): void { remove_all_filters( 'am_asset_conditions', 10 ); add_filter( 'am_asset_conditions', - function() { - return [ - 'global' => true, - 'article_post_type' => true, - 'single' => true, - 'archive' => false, - 'has_slideshow' => false, - 'has_video' => false, - ]; - } - ); - add_filter( - 'am_inline_script_context', - function() { - return 'assetContext'; - } + fn () => [ + 'global' => true, + 'article_post_type' => true, + 'single' => true, + 'archive' => false, + 'has_slideshow' => false, + 'has_video' => false, + ] ); - $this->svg_directory = dirname( __FILE__ ) . '/mocks/'; - add_filter( - 'am_modify_svg_directory', - function() { - return $this->svg_directory; - } - ); + add_filter( 'am_inline_script_context', fn () => 'assetContext' ); + + $this->svg_directory = __DIR__ . '/mocks/'; + add_filter( 'am_modify_svg_directory', fn () => $this->svg_directory ); $this->global_attributes = [ 'focusable' => 'false', 'aria-hidden' => 'true' ]; - add_filter( - 'am_global_svg_attributes', - function( $attrs ) { - return array_merge( $attrs, $this->global_attributes ); - } - ); + add_filter( 'am_global_svg_attributes', fn ( $attrs ) => array_merge( $attrs, $this->global_attributes ) ); $this->reset_assets(); $this->acting_as( 'administrator' ); @@ -99,7 +84,7 @@ public function reset_assets() { 'href' => true, ], ]; - SVG_Sprite::$_global_attributes = null; + SVG_Sprite::$_global_attributes = []; SVG_Sprite::$_svg_directory = null; SVG_Sprite::instance()->create_sprite_sheet(); diff --git a/wp-asset-manager.php b/wp-asset-manager.php new file mode 100644 index 0000000..6d09db4 --- /dev/null +++ b/wp-asset-manager.php @@ -0,0 +1,19 @@ +