├── .github ├── FUNDING.yml └── workflows │ ├── coverage.yml │ └── tests.yml ├── composer.json ├── config └── config.php └── src ├── Exception.php ├── ExceptionHandlerTrait.php ├── Install.php ├── PugBladeCompiler.php ├── PugCompiler.php ├── PugException.php ├── PugHandlerInterface.php ├── PugHandlerTrait.php ├── ServiceProvider.php └── config └── config.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: kylekatarnls, weotch 2 | open_collective: pug-php 3 | tidelift: packagist/pug-php/pug 4 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Coverage 2 | 3 | on: 4 | push: 5 | branches: [ '**' ] 6 | pull_request: 7 | branches: [ '**' ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | php: ['8.2'] 17 | setup: ['stable'] 18 | 19 | name: PHP 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Setup PHP 25 | uses: shivammathur/setup-php@v2 26 | with: 27 | php-version: ${{ matrix.php }} 28 | tools: composer:v2 29 | coverage: pcov 30 | 31 | - name: Cache Composer packages 32 | id: composer-cache 33 | uses: actions/cache@v2 34 | with: 35 | path: vendor 36 | key: ${{ runner.os }}-${{ matrix.setup }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} 37 | restore-keys: | 38 | ${{ runner.os }}-${{ matrix.setup }}-php-${{ matrix.php }}- 39 | 40 | - name: Code Climate Test Reporter Preparation 41 | run: | 42 | curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter 43 | chmod +x ./cc-test-reporter 44 | ./cc-test-reporter before-build 45 | env: 46 | CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} 47 | 48 | - name: Install dependencies 49 | if: steps.composer-cache.outputs.cache-hit != 'true' 50 | run: | 51 | ${{ matrix.php >= 8 && 'composer require --no-update phpunit/phpunit:^9.5.10 --no-interaction;' || '' }} 52 | composer update --prefer-dist --no-interaction ${{ format('--prefer-{0}', matrix.setup) || '' }} 53 | 54 | - name: Run test suite 55 | run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml 56 | 57 | - name: Code Climate Test Reporter 58 | if: ${{ env.CC_TEST_REPORTER_ID != '' }} 59 | run: | 60 | cp coverage.xml clover.xml 61 | bash <(curl -s https://codecov.io/bash) 62 | ./cc-test-reporter after-build --coverage-input-type clover --exit-code 0 63 | env: 64 | CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} 65 | CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} 66 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: [ '**' ] 6 | pull_request: 7 | branches: [ '**' ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] 17 | setup: ['lowest', 'stable', 'next'] 18 | 19 | name: PHP ${{ matrix.php }} - ${{ matrix.setup }} 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Setup PHP 25 | uses: shivammathur/setup-php@v2 26 | with: 27 | php-version: ${{ matrix.php }} 28 | tools: composer:v2 29 | 30 | - name: Cache Composer packages 31 | id: composer-cache 32 | uses: actions/cache@v2 33 | with: 34 | path: vendor 35 | key: ${{ runner.os }}-${{ matrix.setup }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} 36 | restore-keys: | 37 | ${{ runner.os }}-${{ matrix.setup }}-php-${{ matrix.php }}- 38 | 39 | - name: Install dependencies 40 | if: steps.composer-cache.outputs.cache-hit != 'true' 41 | run: | 42 | ${{ matrix.php >= 8 && 'composer require --no-update phpunit/phpunit:^9.5.10 --no-interaction;' || '' }} 43 | composer update --prefer-dist --no-interaction ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} 44 | env: 45 | MULTI_TESTER_LABELS: install 46 | 47 | - name: Run test suite 48 | run: vendor/bin/phpunit --no-coverage --verbose 49 | env: 50 | MULTI_TESTER_LABELS: script 51 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bkwld/laravel-pug", 3 | "description": "Pug view adapter for Laravel", 4 | "type": "library", 5 | "require": { 6 | "php": "^7.2 || ^8.0", 7 | "illuminate/support": ">=6", 8 | "illuminate/view": ">=6", 9 | "phug/component": "^1.1.3", 10 | "pug-php/pug": "^3.3.1", 11 | "pug-php/pug-assets": "^1.0.1", 12 | "pug/installer": "^1.0.0", 13 | "composer-plugin-api": "^1.0 || ^2.0" 14 | }, 15 | "require-dev": { 16 | "composer/composer": "^1.2 || ^2.0", 17 | "phpunit/phpunit": "^8.5" 18 | }, 19 | "minimum-stability": "dev", 20 | "license": "MIT", 21 | "authors": [ 22 | { 23 | "name": "kylekatarnls", 24 | "homepage": "https://github.com/kylekatarnls" 25 | }, 26 | { 27 | "name": "Robert Reinhard", 28 | "email": "info@bukwild.com" 29 | } 30 | ], 31 | "autoload": { 32 | "psr-4": { 33 | "Bkwld\\LaravelPug\\": "src/" 34 | } 35 | }, 36 | "scripts": { 37 | "post-install-cmd": [ 38 | "Pug\\Installer\\Installer::onAutoloadDump" 39 | ], 40 | "post-update-cmd": [ 41 | "Pug\\Installer\\Installer::onAutoloadDump" 42 | ] 43 | }, 44 | "extra": { 45 | "branch-alias": { 46 | "dev-master": "2.x-dev" 47 | }, 48 | "installer": "Bkwld\\LaravelPug\\Install::publishVendor", 49 | "laravel": { 50 | "providers": [ 51 | "Bkwld\\LaravelPug\\ServiceProvider" 52 | ] 53 | } 54 | }, 55 | "config": { 56 | "allow-plugins": { 57 | "nodejs-php-fallback/nodejs-php-fallback": true, 58 | "pug/installer": true 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | = 5. 5 | * Passthrough php-pug config options. 6 | * 7 | * @see https://www.phug-lang.com/#options 8 | */ 9 | 10 | ]; 11 | -------------------------------------------------------------------------------- /src/Exception.php: -------------------------------------------------------------------------------- 1 | container->has('laravel-pug.pug')) { 15 | /** @var Pug $pug */ 16 | $pug = $this->container->get('laravel-pug.pug'); 17 | 18 | try { 19 | $compiler = $pug->getCompiler(); 20 | $exception = $compiler->getFormatter()->getDebugError( 21 | $exception, 22 | file_get_contents($exception->getFile()), 23 | $compiler->getPath() 24 | ); 25 | } catch (\Throwable $caughtException) { 26 | $exception = $caughtException; 27 | } catch (\Exception $caughtException) { 28 | $exception = $caughtException; 29 | } 30 | } 31 | 32 | if (!$request->expectsJson() && $exception instanceof LocatedException) { 33 | $className = get_class($exception->getPrevious() ?: $exception); 34 | $location = $exception->getLocation(); 35 | $line = $location->getLine(); 36 | $offset = $location->getOffset(); 37 | $path = realpath($location->getPath()); 38 | $content = $response->getContent(); 39 | $content = str_replace('Phug\\Util\\Exception\\LocatedException', $className, $content); 40 | $posNamespace = max(0, strrpos($className, '\\')); 41 | 42 | $content = preg_replace('/ 43 |
) 80 | ([^<]+) 81 | (<\/pre>) 82 | /x', function ($match) use ($path, $line) { 83 | $code = []; 84 | $source = explode("\n", @file_get_contents($path)); 85 | $before = 19; 86 | $after = 7; 87 | $start = max(0, $line - $before); 88 | 89 | for ($i = $start; $i < $line + $after; $i++) { 90 | if (isset($source[$i])) { 91 | $code[] = $source[$i]; 92 | } 93 | } 94 | 95 | $code = implode("\n", $code); 96 | 97 | return $match[1].($start + 1).$match[3].$code.$match[5]; 98 | }, $content); 99 | 100 | if ($offset) { 101 | $content = str_replace('