spatie / laravel-blade-comments
将调试注释添加到渲染后的输出中
Requires
- php: ^8.1
- illuminate/contracts: ^9.28|^10|^11.0
- illuminate/view: ^9.28|^10|^11.0
- spatie/laravel-package-tools: ^1.13
Requires (Dev)
- laravel/pint: ^1.10
- livewire/livewire: *
- nunomaduro/collision: ^7|^8.0
- orchestra/testbench: ^8.5.4|^9.0
- pestphp/pest: ^2.6.1
- pestphp/pest-plugin-arch: ^2.1.2
- pestphp/pest-plugin-laravel: ^2.0
- spatie/pest-plugin-snapshots: ^2.0.1
README
在查看渲染页面的HTML时,您可能已经无法确定哪个Blade视图负责哪个HTML。这个包将在每个渲染视图前后添加HTML,这样您就可以立即知道要更改输出的Blade视图/组件。
当您使用喜欢的浏览器的开发工具检查页面的一部分时,您会立即看到哪个Blade视图渲染了特定内容。这里有一个演示,我们检查了我们的公司网站上的面包屑。很明显,面包屑是由front.pages.docs.partials.breadcrumbs
Blade视图渲染的。
在HTML文档的顶部,我们还会添加一些有关最顶层的Blade视图和请求的额外信息。
支持我们
我们投入了大量资源来创建一流的开放源代码包。您可以通过购买我们的付费产品之一来支持我们。
我们非常感谢您从家乡寄给我们一张明信片,说明您使用了哪个我们的包。您可以在我们的联系页面上找到我们的地址。我们将所有收到的明信片发布在我们的虚拟明信片墙上。
安装
您可以通过composer安装此包
composer require spatie/laravel-blade-comments --dev
您可以选择使用以下命令发布配置文件
php artisan vendor:publish --tag="blade-comments-config"
这是发布配置文件的内容
return [ 'enable' => env('APP_DEBUG'), /* * These classes provide regex for adding comments for * various Blade directives. */ 'blade_commenters' => [ Spatie\BladeComments\Commenters\BladeCommenters\BladeComponentCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\AnonymousBladeComponentCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\ExtendsCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\IncludeCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\IncludeIfCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\IncludeWhenCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\LivewireComponentCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\LivewireDirectiveCommenter::class, Spatie\BladeComments\Commenters\BladeCommenters\SectionCommenter::class, ], /* * These classes will add comments at the top of the response. */ 'request_commenters' => [ Spatie\BladeComments\Commenters\RequestCommenters\ViewCommenter::class, Spatie\BladeComments\Commenters\RequestCommenters\RouteCommenter::class, ], /* * This middleware will add extra information about the request * to the start of a rendered HTML page. */ 'middleware' => [ Spatie\BladeComments\Http\Middleware\AddRequestComments::class, ], /* * This class is responsible for calling the registered Blade commenters. * In most case, you don't need to modify this class. */ 'precompiler' => Spatie\BladeComments\BladeCommentsPrecompiler::class, 'excludes' => [ /** * Add includes you don't want to be affected by the package here. * For example: * 'styles.theme', * 'partials.sidebar', */ 'includes' => [ ] ] ];
用法
在安装此包后,您会立即看到每个Blade视图的开始和结束位置都注入了HTML注释。
排除视图
有时您可能不希望将HTML注释包围在一个include中。例如,当您使用部分来向页面添加一些CSS时。在这些情况下,您可以将视图添加到配置文件中的excludes.includes
数组中。
使用您自己的Blade Commenters
您可以轻松扩展此包以添加更多注释。在blade_commenters
配置文件的blade_commenters
键中,您可以添加您自己的BladeCommenter
。任何实现以下接口的类都可以作为BladeCommenter
namespace Spatie\BladeComments\Commenters\BladeCommenters; interface BladeCommenter { /* * Should return a regex pattern that will be used * in preg_replace. */ public function pattern(): string; /* * Should return a replacement string that will be * used in preg_replace. */ public function replacement(): string; }
请查看随包提供的BladeCommenters
以获取示例。
使用您自己的请求评论者
此包在HTML页面顶部添加有关请求的有用信息。这是通过所谓的请求评论者完成的。您可以在blade-comments
配置文件的request_commenters
键中找到默认请求评论者。
您可以在那里添加您自己的请求评论者。任何实现以下接口的类都可以作为RequestCommentor
namespace Spatie\BladeComments\Commenters\RequestCommenters; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response; interface RequestCommenter { public function comment(Request $request, Response $response): ?string; }
如果comment
函数返回一个字符串,它将被注入到HTML文档的顶部。请查看随包提供的请求评论者以获取示例。
测试
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请查看我们的安全政策了解如何报告安全漏洞。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。