├── .editorconfig ├── .styleci.yml ├── LICENSE.md ├── README.md ├── _screenshot.png ├── assets ├── css │ └── laravel-tracer.css └── js │ └── laravel-tracer.js ├── composer.json ├── config └── tracer.php └── src ├── Middleware └── AssetsMiddleware.php ├── Tracer.php └── TracerServiceProvider.php /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) Appstract 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 13 | > all 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 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Tracer 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/appstract/laravel-tracer.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-tracer) 4 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 5 | [![Total Downloads](https://img.shields.io/packagist/dt/appstract/laravel-tracer.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-tracer) 6 | 7 | 8 | Tracer shows the paths of all the Blade files that are loaded into your templates. This could be very convenient for a number of reasons: 9 | * If you're working on a large project with alot of views/partials 10 | * New to a project and want to get a quick overview of the structure of pages 11 | * If you're completely new to Laravel and want to play around with views/partials/templates etc 12 | 13 | ![Screenshot](_screenshot.png?raw=true) 14 | 15 | ## Installation 16 | 17 | First install this package via Composer: 18 | 19 | ```sh 20 | $ composer require appstract/laravel-tracer --dev 21 | ``` 22 | 23 | Publish the config file: 24 | 25 | ```sh 26 | $ php artisan vendor:publish --provider="Appstract\Tracer\TracerServiceProvider" 27 | ``` 28 | 29 | A tracer.php file will be created in your `app/config` directory. 30 | 31 | 32 | ## Basic usage 33 | 34 | In `app/config/tracer.php`, if trace is set to true you see the paths of all the Blade files that are loaded into your templates. To remove the paths simply set trace to false. If your views are located at another directory you can set the correct path here. 35 | 36 | 37 | ### Toggle traces 38 | 39 | A tracer.js file will be created in your `public/js` directory. This gets injected at the end of your app ``` ``` section. 40 | 41 | Use the keybord shortcut ```ctrl+z ``` inside your app to toggle the traces. 42 | 43 | If you wish to disable Tracer and remove the existing traces, you can simply clear the compiled view files using the `php artisan view:clear` command. 44 | 45 | 46 | ## Testing 47 | 48 | ``` bash 49 | $ composer test 50 | ``` 51 | 52 | ## Contributing 53 | 54 | Contributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-tracer/graphs/contributors) :) 55 | 56 | ## About Appstract 57 | 58 | Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on [Medium](https://medium.com/appstract). You can [follow us on Twitter](https://twitter.com/teamappstract), [buy us a beer](https://www.paypal.me/teamappstract/10) or [support us on Patreon](https://www.patreon.com/appstract). 59 | 60 | ## License 61 | 62 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 63 | -------------------------------------------------------------------------------- /_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appstract/laravel-tracer/64b6cb334ddea3bc4c8527d66b6e2050223f39fd/_screenshot.png -------------------------------------------------------------------------------- /assets/css/laravel-tracer.css: -------------------------------------------------------------------------------- 1 | .laravel-trace { 2 | display: block; 3 | outline: 1px dotted #F4645F; 4 | } 5 | 6 | .laravel-trace.no-trace { 7 | display: inline; 8 | border: none; 9 | } 10 | 11 | .laravel-trace.no-trace .path { 12 | display: none; 13 | } 14 | 15 | .laravel-trace .path { 16 | background: #fff; 17 | color: #000; 18 | margin: 1; 19 | font-size: 12px; 20 | } -------------------------------------------------------------------------------- /assets/js/laravel-tracer.js: -------------------------------------------------------------------------------- 1 | document.addEventListener("DOMContentLoaded", function(e) { 2 | 3 | function toggleTrace() { 4 | var traces = document.getElementsByClassName('laravel-trace'); 5 | 6 | for(var i = 0; i < traces.length; i++){ 7 | if (traces[i].classList.contains('no-trace')) { 8 | traces[i].classList.remove('no-trace'); 9 | } else { 10 | traces[i].classList.add('no-trace'); 11 | } 12 | } 13 | } 14 | 15 | function KeyPress(e) { 16 | var evtobj = window.event? event : e 17 | if (evtobj.keyCode == 90 && evtobj.ctrlKey) toggleTrace(); 18 | } 19 | 20 | document.onkeydown = KeyPress; 21 | 22 | }); -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "appstract/laravel-tracer", 3 | "description": "Adds the paths of all loaded views/partials to your templates.", 4 | "keywords": ["appstract", "laravel", "blade", "path", "hints", "php"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Bob Krijnen", 9 | "email": "hello@appstract.team", 10 | "homepage": "https://appstract.team", 11 | "role": "Developer" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.5.0" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "Appstract\\Tracer\\": "src/" 20 | } 21 | }, 22 | "extra": { 23 | "laravel": { 24 | "providers": [ 25 | "Appstract\\Tracer\\TracerServiceProvider" 26 | ] 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /config/tracer.php: -------------------------------------------------------------------------------- 1 | true, 7 | 8 | // Default path where your compiled views are located 9 | 'path' => '/storage/framework/views', 10 | 11 | ]; 12 | -------------------------------------------------------------------------------- /src/Middleware/AssetsMiddleware.php: -------------------------------------------------------------------------------- 1 | content(); 14 | 15 | $content = str_replace( 16 | '', 17 | ' 18 | 19 | ', 20 | $content 21 | ); 22 | 23 | return $response->setContent($content); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Tracer.php: -------------------------------------------------------------------------------- 1 | files = File::allFiles(base_path().(config('tracer.path', '/storage/framework/views'))); 33 | $this->realPath = '

lastCompiled)) ?>

'; 34 | $this->debug = config('tracer.trace'); 35 | } 36 | 37 | /** 38 | * Start the tracer. 39 | * @return [type] [description] 40 | */ 41 | public function trace() 42 | { 43 | foreach ($this->files as $file) { 44 | ($this->debug === true) ? $this->addTrace($file) : $this->removeTrace($file); 45 | } 46 | } 47 | 48 | /** 49 | * Add the trace to the view. 50 | * @param [type] $file [description] 51 | */ 52 | public function addTrace($file) 53 | { 54 | // If the file does not contain the trace, add it. 55 | if (strpos(File::get($file), $this->realPath) === false && $this->debug == true) { 56 | File::prepend($file, $this->realPath); 57 | File::append($file, '
'); 58 | } 59 | } 60 | 61 | /** 62 | * Remove the trace from the view. 63 | * @param [type] $file [description] 64 | * @return [type] [description] 65 | */ 66 | public function removeTrace($file) 67 | { 68 | // If the file does contain the trace, remove it. 69 | if (strpos(File::get($file), $this->realPath) !== false) { 70 | $content = str_replace($this->realPath, '', File::get($file)); 71 | File::put($file, $content); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/TracerServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 17 | __DIR__.'/../config/tracer.php' => config_path('tracer.php'), 18 | __DIR__.'/../assets/css/laravel-tracer.css' => public_path('css/laravel-tracer.css'), 19 | __DIR__.'/../assets/js/laravel-tracer.js' => public_path('js/laravel-tracer.js'), 20 | ]); 21 | 22 | $tracer = (new Tracer)->trace(); 23 | 24 | // Add AssetsMiddlware 25 | if (config('tracer.trace')) { 26 | $kernel->prependMiddleware('Appstract\Tracer\Middleware\AssetsMiddleware'); 27 | } 28 | } 29 | 30 | /** 31 | * Register the application services. 32 | * 33 | * @return void 34 | */ 35 | public function register() 36 | { 37 | $this->mergeConfigFrom(__DIR__.'/../config/tracer.php', 'tracer'); 38 | $this->app->make('Appstract\Tracer\Tracer'); 39 | } 40 | } 41 | --------------------------------------------------------------------------------