Skip to content

Commit f598ac7

Browse files
Add Statamic 6 / Laravel 12 support (#46)
* feat: add Statamic 6 support - Update composer.json constraints for statamic/cms ^6.0, symfony/* ^8.0 - Update TestCase for Statamic 6 compatibility (Manifest class moved) - Resolves #45 * docs: add Statamic 6 badge and requirement to README, simplify editions config in tests --------- Co-authored-by: Jonas List <jonas.list@visuellverstehen.de>
1 parent c00b335 commit f598ac7

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Statamic 4](https://img.shields.io/badge/Statamic-v4-FF269E?style=for-the-badge&link=https://statamic.com)](https://statamic.com/addons/visuellverstehen/classify)
22
[![Statamic 5](https://img.shields.io/badge/Statamic-v5-FF269E?style=for-the-badge&link=https://statamic.com)](https://statamic.com/addons/visuellverstehen/classify)
3+
[![Statamic 6](https://img.shields.io/badge/Statamic-v6-FF269E?style=for-the-badge&link=https://statamic.com)](https://statamic.com/addons/visuellverstehen/classify)
34
[![Latest version on Packagist](https://img.shields.io/packagist/v/visuellverstehen/statamic-classify.svg?style=for-the-badge)](https://packagist.org/packages/visuellverstehen/statamic-classify)
45

56
# Classify
@@ -9,7 +10,7 @@ Classify is a useful helper to add CSS classes to all HTML tags generated by the
910

1011
## Requirements
1112

12-
- Statamic v4 || v5
13+
- Statamic v4 || v5 || v6
1314
- Laravel 10 || 11 || 12
1415
- PHP 8.2+
1516

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "visuellverstehen/statamic-classify",
33
"description": "A useful helper to add CSS classes to all HTML tags generated by the bard editor.",
4-
"keywords": [ "statamic", "addon", "bard", "css", "prose", "typography", "v4", "v5" ],
4+
"keywords": [ "statamic", "addon", "bard", "css", "prose", "typography", "v4", "v5", "v6" ],
55
"license": "MIT",
66
"type": "statamic-addon",
77
"autoload": {
@@ -25,9 +25,9 @@
2525
"require": {
2626
"php": "^8.2 || ^8.3 || ^8.4",
2727
"laravel/framework": "^10.0 || ^11.0 || ^12.0",
28-
"statamic/cms": "^4.0 || ^5.0",
29-
"symfony/dom-crawler": "^6.0 || ^7.0",
30-
"symfony/css-selector": "^5.4 || ^6.0 || ^7.0"
28+
"statamic/cms": "^4.0 || ^5.0 || ^6.0",
29+
"symfony/dom-crawler": "^6.0 || ^7.0 || ^8.0",
30+
"symfony/css-selector": "^5.4 || ^6.0 || ^7.0 || ^8.0"
3131
},
3232
"require-dev": {
3333
"orchestra/testbench": "^8 || ^9 || ^10",

src/HtmlParser.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public function parse(Tag $tag, string $value): string
3232
$node->setAttribute('class', $tag->classes);
3333
}
3434

35-
// Generate the HTML with our class adjustments made.
36-
$result = $crawler->html();
35+
// DomCrawler wraps fragments in head/body; return the body contents when present.
36+
$body = $crawler->filter('body');
3737

38-
// Removes the <body> and </body> tags that get added since it's a fragment.
39-
$result = substr($result, 6);
38+
if ($body->count() > 0) {
39+
return $body->html();
40+
}
4041

41-
return substr($result, 0, -7);
42+
return $crawler->html();
4243
}
4344
}

tests/TestCase.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace VV\Classify\Tests;
44

55
use Orchestra\Testbench\TestCase as OrchestraTestCase;
6-
use Statamic\Extend\Manifest;
76
use Statamic\Statamic;
87

98
class TestCase extends OrchestraTestCase
@@ -58,7 +57,11 @@ protected function getEnvironmentSetUp($app)
5857
{
5958
parent::getEnvironmentSetUp($app);
6059

61-
$app->make(Manifest::class)->manifest = [
60+
$manifestClass = class_exists(\Statamic\Addons\Manifest::class)
61+
? \Statamic\Addons\Manifest::class
62+
: \Statamic\Extend\Manifest::class;
63+
64+
$app->make($manifestClass)->manifest = [
6265
'visuellverstehen/statamic-classify' => [
6366
'id' => 'visuellverstehen/statamic-classify',
6467
'namespace' => 'VV\\Classify\\',
@@ -75,24 +78,18 @@ protected function resolveApplicationConfiguration($app)
7578
{
7679
parent::resolveApplicationConfiguration($app);
7780

78-
$configs = [
79-
'assets', 'cp', 'forms', 'routes', 'static_caching',
80-
'sites', 'stache', 'system', 'users',
81-
];
81+
$configDirectory = __DIR__.'/../vendor/statamic/cms/config';
82+
$configPaths = glob($configDirectory.'/*.php') ?: [];
8283

83-
foreach ($configs as $config) {
84-
$path = __DIR__."/../vendor/statamic/cms/config/{$config}.php";
85-
86-
// Statamic 5 does not have a `sites` config anymore, so we better check first
87-
if (file_exists($path)) {
88-
$app['config']->set("statamic.$config", require($path));
89-
}
84+
foreach ($configPaths as $path) {
85+
$config = basename($path, '.php');
86+
$app['config']->set("statamic.$config", require $path);
9087
}
9188

9289
// Setting the user repository to the default flat file system
9390
$app['config']->set('statamic.users.repository', 'file');
9491

95-
// Assume the pro edition within tests
92+
// Assume the free edition within tests
9693
$app['config']->set('statamic.editions.pro', false);
9794
}
9895
}

0 commit comments

Comments
 (0)