<commit_before># Laravel Pug

[![Packagist](https://img.shields.io/packagist/v/bkwld/laravel-pug.svg)](https://packagist.org/packages/bkwld/laravel-pug)
[![Build Status](https://travis-ci.org/BKWLD/laravel-pug.svg?branch=master)](https://travis-ci.org/BKWLD/laravel-pug)
[![StyleCI](https://styleci.io/repos/63732751/shield?style=flat)](https://styleci.io/repos/63732751)
[![codecov](https://codecov.io/gh/BKWLD/laravel-pug/branch/master/graph/badge.svg)](https://codecov.io/gh/BKWLD/laravel-pug)
[![Code Climate](https://codeclimate.com/github/BKWLD/laravel-pug/badges/gpa.svg)](https://codeclimate.com/github/BKWLD/laravel-pug)
[![License](https://poser.pugx.org/bkwld/laravel-pug/license)](https://packagist.org/packages/bkwld/laravel-pug)

A small package that adds support for compiling Pug (Jade) templates
to Laravel via [Pug.php](https://github.com/pug-php/pug).
Both vanilla php and [Blade syntax](https://laravel.com/docs/5.5/blade)
is supported within the view.


## Installation

First you need composer if you have'nt yet: https://getcomposer.org/download/

Now open a terminal at the root of your laravel project. If it's a new project,
create it with: `composer create-project --prefer-dist laravel/laravel my-new-project`
(replace *my-new-project* with your own project name,
[see the documentation for further information](https://laravel.com/docs/5.5#installing-laravel))

Then run `composer require bkwld/laravel-pug`.

To get a line and offset in pug source files well formatted in standard
Laravel error display to debug errors, we recommend
you to implement the following in your **app/Exceptions/ExceptionHandler**:

```php
<?php

namespace App\Exceptions;

use Bkwld\LaravelPug\ExceptionHandlerTrait;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    use ExceptionHandlerTrait;
    
    /* ... */

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        return $this->filterErrorResponse($exception, $request, parent::render($request, $exception));
    }
    
}
```

Note: this will works for pure `.pug` file, not `.pug.blade` since the
error will happen in the blade engine.

## Usage

Any file with the extension `.pug` will be compiled as a pug template.
Laravel Pug also registers the `.pug.php`, `.pug.blade`, and `.pug.blade.php`
as well as the `.jade`, `.jade.php`, `.jade.blade`, and `.jade.blade.php`
extensions with Laravel and forwards compile requests on to Pug.php but
we highly recommend you to use the clean and standard extension `.pug`
that will be recognized by most systems. It compiles your Pug templates
in the same way as Blade templates; the compiled template is put in your
storage directory. Thus, you don't suffer compile times on every page load.

In other words, just put your Pug files in the regular views directory
and name them like `whatever.pug`. You reference them in Laravel like normal:

* **Laravel 4** : `View::make('home.whatever')` for `app/views/home/whatever.pug`
* **Laravel 5** : `view('home.whatever')` for `resources/views/home/whatever.pug`

The Pug view files can work side-by-side with regular PHP views. To use Blade
templating within your Pug, just name the files with `.pug.blade` or
`.pug.blade.php` extensions. This feature is designed for transition
purpose, since every blade features are available in pug, you would not
need both. And be aware that this mode will first render your template with
pug, then give the output to render to blade, it means your template must
have a valid pug syntax and must render a valid blade template. This also
means blade directives are only available through pug text output, see the
example below:
```pug
| @if ($one === 1)
div $one = 1
| @endif
p {{ $two }}
```
If you render this with the following values: `['one' => 1, 'two' => 2]`, you
will get:
```html
<div>$one = 1</div>
<p>2</p>
```
PS: note that you would get the same output with the following pure pug code:
```pug
if one === 1
  div $one = 1
p=two
```
<commit_msg>Lumen section in the README<commit_after># Laravel Pug

[![Packagist](https://img.shields.io/packagist/v/bkwld/laravel-pug.svg)](https://packagist.org/packages/bkwld/laravel-pug)
[![Build Status](https://travis-ci.org/BKWLD/laravel-pug.svg?branch=master)](https://travis-ci.org/BKWLD/laravel-pug)
[![StyleCI](https://styleci.io/repos/63732751/shield?style=flat)](https://styleci.io/repos/63732751)
[![codecov](https://codecov.io/gh/BKWLD/laravel-pug/branch/master/graph/badge.svg)](https://codecov.io/gh/BKWLD/laravel-pug)
[![Code Climate](https://codeclimate.com/github/BKWLD/laravel-pug/badges/gpa.svg)](https://codeclimate.com/github/BKWLD/laravel-pug)
[![License](https://poser.pugx.org/bkwld/laravel-pug/license)](https://packagist.org/packages/bkwld/laravel-pug)

A small package that adds support for compiling Pug (Jade) templates
to Laravel via [Pug.php](https://github.com/pug-php/pug).
Both vanilla php and [Blade syntax](https://laravel.com/docs/5.5/blade)
is supported within the view.


## Installation

First you need composer if you have'nt yet: https://getcomposer.org/download/

Now open a terminal at the root of your laravel project. If it's a new project,
create it with: `composer create-project --prefer-dist laravel/laravel my-new-project`
(replace *my-new-project* with your own project name,
[see the documentation for further information](https://laravel.com/docs/5.5#installing-laravel))

Then run `composer require bkwld/laravel-pug`.

To get a line and offset in pug source files well formatted in standard
Laravel error display to debug errors, we recommend
you to implement the following in your **app/Exceptions/ExceptionHandler**:

```php
<?php

namespace App\Exceptions;

use Bkwld\LaravelPug\ExceptionHandlerTrait;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    use ExceptionHandlerTrait;
    
    /* ... */

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        return $this->filterErrorResponse($exception, $request, parent::render($request, $exception));
    }
    
}
```

Note: this will works for pure `.pug` file, not `.pug.blade` since the
error will happen in the blade engine.

## Usage

Any file with the extension `.pug` will be compiled as a pug template.
Laravel Pug also registers the `.pug.php`, `.pug.blade`, and `.pug.blade.php`
as well as the `.jade`, `.jade.php`, `.jade.blade`, and `.jade.blade.php`
extensions with Laravel and forwards compile requests on to Pug.php but
we highly recommend you to use the clean and standard extension `.pug`
that will be recognized by most systems. It compiles your Pug templates
in the same way as Blade templates; the compiled template is put in your
storage directory. Thus, you don't suffer compile times on every page load.

In other words, just put your Pug files in the regular views directory
and name them like `whatever.pug`. You reference them in Laravel like normal:

* **Laravel 4** : `View::make('home.whatever')` for `app/views/home/whatever.pug`
* **Laravel 5** : `view('home.whatever')` for `resources/views/home/whatever.pug`

The Pug view files can work side-by-side with regular PHP views. To use Blade
templating within your Pug, just name the files with `.pug.blade` or
`.pug.blade.php` extensions. This feature is designed for transition
purpose, since every blade features are available in pug, you would not
need both. And be aware that this mode will first render your template with
pug, then give the output to render to blade, it means your template must
have a valid pug syntax and must render a valid blade template. This also
means blade directives are only available through pug text output, see the
example below:
```pug
| @if ($one === 1)
div $one = 1
| @endif
p {{ $two }}
```
If you render this with the following values: `['one' => 1, 'two' => 2]`, you
will get:
```html
<div>$one = 1</div>
<p>2</p>
```
PS: note that you would get the same output with the following pure pug code:
```pug
if one === 1
  div $one = 1
p=two
```

### Use in Lumen

Register the service in `bootstrap/app.php`
(**Register Service Providers** section is the dedicated place):

```php
$app->register(Bkwld\LaravelPug\ServiceProvider::class);
```

Then you can use it with `view()`:
```
$router->get('/', function () use ($router) {
    // will render resources/views/test.pug
    return view('test', [
        'name' => 'Bob',
    ]);
});
```
{'fraction_non_alphanumeric': 0.1270948149814419, 'fraction_numerical': 0.0067483972556517825, 'mean_word_length': 4.246017699115044, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 32, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3558875', 'n_tokens_mistral': 2956, 'n_tokens_neox': 2821, 'n_words': 964}