├── .github
├── FUNDING.yml
└── workflows
│ └── tests.yml
├── .gitignore
├── LICENSE.md
├── README.md
├── composer.json
├── phpunit.xml.dist
├── src
├── DebugEngine.php
├── DebugEngineResolver.php
└── ViewDebugServiceProvider.php
└── tests
├── BasicTest.php
├── DebugEngineTest.php
├── TestCase.php
└── fixtures
└── views
├── subview.blade.php
└── view.blade.php
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [jasonvarga]
2 |
--------------------------------------------------------------------------------
/.github/workflows/tests.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on:
4 | push:
5 | pull_request:
6 | schedule:
7 | - cron: '0 0 * * *'
8 |
9 | jobs:
10 | php-tests:
11 | runs-on: ${{ matrix.os }}
12 |
13 | strategy:
14 | matrix:
15 | php: [8.2, 8.3, 8.4]
16 | laravel: [11.*, 12.*]
17 | stability: [prefer-lowest, prefer-stable]
18 | os: [ubuntu-latest]
19 |
20 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
21 |
22 | steps:
23 | - name: Checkout code
24 | uses: actions/checkout@v1
25 |
26 | - name: Setup PHP
27 | uses: shivammathur/setup-php@v2
28 | with:
29 | php-version: ${{ matrix.php }}
30 | coverage: none
31 |
32 | - name: Install dependencies
33 | uses: nick-invision/retry@v2
34 | with:
35 | timeout_minutes: 5
36 | max_attempts: 5
37 | command: |
38 | composer require "illuminate/contracts:${{ matrix.laravel }}" --dev --no-interaction --no-update
39 | composer update --${{ matrix.stability }} --prefer-dist --no-interaction
40 |
41 | - name: Execute tests
42 | run: vendor/bin/phpunit
43 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | .phpunit.result.cache
3 | composer.lock
4 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Jason Varga
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel View Debug
2 |
3 | Adds HTML comments to the start and end of each view, so you can more easily keep track of what's being used.
4 |
5 | [Inspired by this feature request.](https://github.com/statamic/ideas/issues/139)
6 |
7 | ## Example
8 |
9 | You may have a Blade file like this:
10 |
11 | ```
12 | My view file
13 |
14 | @include('sub-view')
15 |
16 | More stuff
17 | ```
18 |
19 | It will be rendered like this:
20 |
21 | ```
22 |
23 | My view file
24 |
25 |
26 | Sub view
27 |
28 |
29 | More stuff
30 |
31 | ```
32 |
33 | Of course, since they are HTML comments, it will look no different unless you view the source.
34 |
35 | ## Installation
36 |
37 | You can install the package via composer:
38 |
39 | ```bash
40 | composer require pixelfear/laravel-view-debug --dev
41 | ```
42 |
43 | ## Usage
44 |
45 | This package will be enabled while your app is in debug mode.
46 |
47 | ## Livewire
48 |
49 | This package will conflict with Livewire because it would result in components having more than a single root node.
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "pixelfear/laravel-view-debug",
3 | "description": "Debug Laravel views",
4 | "license": "MIT",
5 | "require": {
6 | "laravel/framework": "^11.0 || ^12.0"
7 | },
8 | "require-dev": {
9 | "orchestra/testbench": "^9.0 || ^10.0"
10 | },
11 | "autoload": {
12 | "psr-4": {
13 | "Pixelfear\\ViewDebug\\": "src"
14 | }
15 | },
16 | "autoload-dev": {
17 | "psr-4": {
18 | "Tests\\": "tests"
19 | }
20 | },
21 | "config": {
22 | "sort-packages": true
23 | },
24 | "extra": {
25 | "laravel": {
26 | "providers": [
27 | "Pixelfear\\ViewDebug\\ViewDebugServiceProvider"
28 | ]
29 | }
30 | },
31 | "conflict": {
32 | "livewire/livewire": "*"
33 | },
34 | "minimum-stability": "dev",
35 | "prefer-stable": true
36 | }
37 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 | ./tests
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/DebugEngine.php:
--------------------------------------------------------------------------------
1 | engine = $engine;
17 | }
18 |
19 | public function get($path, $data = [])
20 | {
21 | return vsprintf('%s', [
22 | $path,
23 | $this->engine->get($path, $data),
24 | $path
25 | ]);
26 | }
27 |
28 | public function __call($method, $parameters)
29 | {
30 | return $this->forwardDecoratedCallTo($this->engine, $method, $parameters);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/DebugEngineResolver.php:
--------------------------------------------------------------------------------
1 | resolver = $resolver;
14 | }
15 |
16 | public function register($engine, $resolver)
17 | {
18 | return $this->resolver->register($engine, $resolver);
19 | }
20 |
21 | public function resolve($engine)
22 | {
23 | return new DebugEngine($this->resolver->resolve($engine));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/ViewDebugServiceProvider.php:
--------------------------------------------------------------------------------
1 | app->extend('view.engine.resolver', function ($resolver) {
13 | return new DebugEngineResolver($resolver);
14 | });
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/BasicTest.php:
--------------------------------------------------------------------------------
1 | Some view contents.
26 |
27 | Sub view contents.
28 |
29 | Some more view contents.
30 |
31 | CONTENTS;
32 |
33 | $this->assertEquals($expected, view('view')->render());
34 | }
35 |
36 | #[Test]
37 | function it_doesnt_add_comments_when_debug_mode_is_disabled()
38 | {
39 | $expected = <<assertEquals($expected, view('view')->render());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/DebugEngineTest.php:
--------------------------------------------------------------------------------
1 | shouldReceive('foo')->with('bar')->andReturn('baz');
18 |
19 | $engine = new DebugEngine($mock);
20 |
21 | $this->assertEquals('baz', $engine->foo('bar'));
22 | }
23 |
24 | #[Test]
25 | public function it_forwards_calls_to_engine_and_allows_fluency()
26 | {
27 | $mock = Mockery::mock(Engine::class);
28 | $mock->shouldReceive('foo')->with('bar')->andReturnSelf();
29 |
30 | $engine = new DebugEngine($mock);
31 |
32 | $this->assertSame($engine, $engine->foo('bar'));
33 | }
34 |
35 | #[Test]
36 | public function it_throw_bad_method_call_exception()
37 | {
38 | $this->expectException(BadMethodCallException::class);
39 | $this->expectExceptionMessage('Call to undefined method Pixelfear\\ViewDebug\\DebugEngine::foo()');
40 |
41 | $mock = Mockery::mock(Engine::class);
42 | $mock->shouldReceive('foo')->with('bar')->andThrow(
43 | BadMethodCallException::class,
44 | 'Call to undefined method '.get_class($mock).'::foo()'
45 | );
46 |
47 | $engine = new DebugEngine($mock);
48 |
49 | $engine->foo('bar');
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 | set('app.debug', true);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/fixtures/views/subview.blade.php:
--------------------------------------------------------------------------------
1 | Sub view contents.
2 |
--------------------------------------------------------------------------------
/tests/fixtures/views/view.blade.php:
--------------------------------------------------------------------------------
1 | Some view contents.
2 |
3 | @include('subview')
4 |
5 | Some more view contents.
6 |
--------------------------------------------------------------------------------