Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧑‍💻 Change default editorStyles implementation from URL to local theme path #367

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Roots/Acorn/Assets/Concerns/Enqueuable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Roots\Acorn\Assets\Concerns;

use Illuminate\Support\Str;
use Roots\Acorn\Filesystem\Filesystem;

trait Enqueuable
{
/**
Expand Down Expand Up @@ -85,7 +88,24 @@ public function enqueue()
*/
public function editorStyles()
{
$this->css(fn ($handle, $src) => add_editor_style($src));
$relativePath = (new Filesystem)->getRelativePath(
Str::finish(get_theme_file_path(), '/'),
$this->path
);

$this->css(function ($handle, $src) use ($relativePath) {
if (! Str::startsWith($src, $this->uri)) {
return add_editor_style($src);
}

$style = Str::of($src)
->after($this->uri)
->ltrim('/')
->start("{$relativePath}/")
->toString();

add_editor_style($style);
});

return $this;
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Assets/BundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
$manifest = json_decode(file_get_contents($this->fixture('bud_single_runtime/public/entrypoints.json')), JSON_OBJECT_AS_ARRAY);
$app = new Bundle('app', $manifest['app'], $this->fixture('bud_single_runtime'), 'https://k.jo');

$app->js(fn ($handle, $src, $dependencies) => assertMatchesSnapshot(compact('handle', 'src', 'dependencies'))
);
$app->js(fn ($handle, $src, $dependencies) => assertMatchesSnapshot(compact('handle', 'src', 'dependencies')));

$app->css(fn ($handle, $src) => assertMatchesSnapshot(compact('handle', 'src'))
);
$app->css(fn ($handle, $src) => assertMatchesSnapshot(compact('handle', 'src')));
});

it('can enqueue css', function () {
Expand All @@ -46,6 +44,7 @@
$manifest = json_decode(file_get_contents($this->fixture('bud_single_runtime/public/entrypoints.json')), JSON_OBJECT_AS_ARRAY);
$app = new Bundle('app', $manifest['app'], $this->fixture('bud_single_runtime'), 'https://k.jo');

$this->stub('get_theme_file_path', fn ($path = '') => $this->fixture('bud_v6_single_runtime/public/'.$path));
$this->stub('add_editor_style', fn (...$args) => assertMatchesSnapshot($args));

$app->editorStyles();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- 'https://k.jo/public/app.2.4476c5f869ee7584ba3c.css'
- ../../bud_single_runtime/public/app.2.4476c5f869ee7584ba3c.css
Loading