Skip to content

Releases: inpsyde/assets

2.8.3

16 Dec 13:24
f198d7d
Compare
Choose a tag to compare

This release is just a QoL release with some improvements on Github Workflows and adding PHP 8.1 and PHP 8.2 into testing routine.

  • ScriptHandler // allow $path to be null for wp_set_script_translations().
  • composer.json // make use of worpdress-stubs for pslam.
  • github/workflows // add support for PHP 8.1 and 8.2. Make use of inpsyde/reusable-workflows.
  • phpunit.xml.dist // upgrade config.
  • Run CI on PR-s
  • Add explicit "WordPress plugin" to README

2.8.2

30 Jun 07:43
116ff4c
Compare
Choose a tag to compare
  • Deprecated Script::useDependencyExtractionPlugin().
  • Improved Script::resolveDependencyExtractionPlugin() by setting earlier the "loaded" state to avoid calling logic multiple times.
  • docs/assets.md // update documentation.

2.8.1

04 Mar 13:02
1721dec
Compare
Choose a tag to compare

Improvements

  • Change AssetHookResolver::$context visibility to protected to make the class extendable.

Fixes

  • Psalm and PHPCS.

props @nlemoine

2.8

11 Nov 09:16
6383ccc
Compare
Choose a tag to compare
2.8

New feature "custom CSS properties (vars)"

inpsyde/assets now supports via Inpsyde\Assets\Style() to register custom CSS properties (vars).

The new API looks like following:

use Inpsyde\Assets\Style;

$style = new Style('foo', 'www.example.com/style.css');

// to a specific selector/element.
$style->withCssVars(
	'.some-element', 
	['white' => '#fff', 'black' => '000']
);
// or to :root
$style->withCssVars(
	':root', 
	['grey' => '#ddd']
);

The StyleHandler will automatically check if there are CSS vars available via Style::cssVars() and add them via wp_add_inline_style() to your handle.

Registered CSS vars will be automatically prefixed with -- if not present. The example from above will generate following output (prettified for the sake of readability):

<style id="foo-inline-css">
.some-element {
	--white:#fff;
	--black:#000;
}
:root {
	--grey:#ddd;
}
</style>

2.7

06 Aug 06:50
5eedca1
Compare
Choose a tag to compare
2.7

New Features

Asset now supports registration/enqueuing styles and scripts in wp-activate.php via Asset::ACTIVATE. Also the default Asset::location() was changed to Asset::FRONTEND | Asset::ACTIVATE.

Props @websupporter & @gmazzap


Documentation

inpsyde/assets now uses Github Pages for documentation. Check out the documentation here: https://inpsyde.github.io/assets/

You can also checkout our Inpsyde Jekyll Theme - which is based on Just the docs here: https://github.com/inpsyde/jekyll-inpsyde-theme

Thanks to @tangrufus and @judy-inpsyde for the awesome work! 💪

2.6

19 Jul 11:40
83ce23d
Compare
Choose a tag to compare
2.6

Improvments

Most of the time we relied on WordPress functions wp_register_*()- and wp_enqueue_*() to set a $version which is for example based on the filemtime of the Asset. Webpack and @wordpress/dependency-extraction-webpack-plugin are allowing to add hashes for easier cache handling. This broke the loading of generated dependency extraction files due a different format of file names.

With this release of inpsyde/assets we will add support for generated dependency extraction files with and without hashes in following format:

  • {fileName}.asset.json
  • {fileName}.{hash}.asset.json
  • {fileName}.asset.php
  • {fileName}.{hash}.asset.php

Quality

  • Set theme jekyll-theme-slate. You can now read the documentation on https://inpsyde.github.io/assets/
  • psalm & phpcs.
  • Improve .gitattributes
  • testing.yml // run steps in parallel instead of depending on "quality".

Props @tangrufus @judy-inpsyde and myself ;)

2.5.3

01 Apr 08:03
4af9e2b
Compare
Choose a tag to compare

Bugfixes

  • Add handling for localize parameter in AssetFactory #26
  • Add handling for translation parameter in AssetFactory #26

Improvements

  • Split AssetFactory::validateConfig() into separate methods
  • Add .phpunit.result.cache to .gitignore

props @dnaber-de @retrorism

2.5.2

26 Mar 08:05
c14c733
Compare
Choose a tag to compare

Bugfix

  • AssetFactory // Add support for inline scripts.

props @nlemoine

2.5.1

25 Mar 14:51
e69eda8
Compare
Choose a tag to compare

Bugfix

  • AssetFactory // fix method call for Asset::withDependencies() to use spread operator on array input.

props @cristianobaptista

2.5

22 Mar 12:46
6303cd3
Compare
Choose a tag to compare
2.5

New Features

New API on Asset: Attributes

The public API of Inpsyde\Assets\Asset introduces 2 new methods Asset::attributes(): array and Asset::withAttributes(array $attributes): Asset and a new OutputFilter Inpsyde\Assets\OutputFilter\AttributesOutputFilter.

This allows us more flexible to update the attributes of script- and link-tags. You can now do following:

<?php
use Inpsyde\Assets\Style;
use Inpsyde\Assets\Script;

$script = new Script('my-handle', 'script.js');
$script->withAttributes(
    [
        'async' => true,
        'data-value' => 'key',
        'nonce' => wp_create_nonce()
    ]
);
// <script src="script.js" id="my-handle-js" async data-value="key" nonce="{generated nonce}"></script> 

$style = new Style('my-handle', 'style.css');
$style->withAttributes(
    [
        'data-value' => 'key',
        'nonce' => wp_create_nonce()
    ]
);
// <link rel="stylesheet" href="style.css" id="my-handle-css" data-value="key" nonce="{generated nonce}" />

[!] Note: Existing attributes like "src" or "id" are not overwriteable. The Inpsyde\Assets\OutputFilter\AttributesOutputFilter only sets attributes which are not already existent on the html-tag.

Following will not work:

<?php
use Inpsyde\Assets\Script;

$script = new Script('my-handle', 'script.js');
$script->withAttributes(['src' => 'another-script.js']); // Will not overwrite "script.js"

Deprecations

AsyncScriptOutputFilter and DeferScriptOutputFilter and the corrosponding methods Script::useAsyncFilter() and Script:.useDeferFilter() are set to deprecated. Everything will still work as normal, but the Script-methods will now map internally to the new AttributsOutputFilter.

In future, you should replace them as following:

Async:

<?php
// before
$script = new Script('my-handle', 'script.js');
$script->useAsyncFilter();

// after
$script = new Script('my-handle', 'script.js');
$script->withAttributes(['async' => true']);

Defer:

<?php
// before
$script = new Script('my-handle', 'script.js');
$script->useDeferFilter();

// after
$script = new Script('my-handle', 'script.js');
$script->withAttributes(['defer' => true']);

Internal refactor BaseAsset

The Inpsyde\Assets\BaseAsset will now not use anymore internally $config and does not support injecting $config as fourth param in constructor. This decision was made while refactoring the usage of internal variables and to have a more consitent API. The Inpsyde\Assets\AssetFactory was updated to now use the public API methods instead of just injecting the third parameter.

You only need to adapt your code if you're using following:

<?php
use Inpsyde\Assets\Asset;
use Inpsyde\Assets\Script;

// before - does not work anymore
$script = new Script('my-handle', 'script.js', Asset::FRONTEND, ['enqueue' => false]);

// after
$script = new Script('my-handle', 'script.js', Asset::FRONTEND);
$script->canEnqueue(false);

Improvements

  • Inpsyde\Assets\symlinkedAssetFolder() - make use of wp_mkdir_p() instead mkdir().
  • Util // move AssetHookResolver and AssetPathResolver into new domain.

Quality

  • testing.yml // test setup php with coverage:pcov
  • Docs // Assets - update conditional comments.
  • OutputFilter // update docs to have correct order.
  • Upgrade to PHPUnit 8.
  • Update documentation for Customizer Preview hook.