fitztrev / laravel-html-minify

Minifies the HTML output of Laravel 4 applications
https://github.com/fitztrev/laravel-html-minify/wiki/Laravel-5---5.1-HTML-Minifying
MIT License
414 stars 76 forks source link

@image helper does not work with minification #58

Open bigappleinsider opened 8 years ago

bigappleinsider commented 8 years ago

The following does not work with minification:

<img alt="{{ $media->altText }}" src="@image($media, ['transformation' => $transformation], 'jpg')" />

I had to replace all image helpers:

<img alt="{{ $media->altText }}" src="{{ Abc\View\get_image_link($media, ['transformation' => $transformation], 'jpg') }}" />

We register image helper in app/lib/View/ViewServiceProvider.php as following:

require 'helpers.php';

use Blade;
use Cloudinary;
use Config;
use Illuminate\Support\ServiceProvider;

class ViewServiceProvider extends ServiceProvider
{
    protected $bladeExtensions = [
        'asset' => '$1<?= Abc\View\get_timestamped_asset_link$2 ?>',
        'image' => '$1<?= Abc\View\get_image_link$2 ?>',
    ];

    public function register()
    {
        Cloudinary::config(
            [
                'cloud_name' => Config::get('cloudinary.cloud')
                , 'cname' => 'images.abc.com'
            ]
        );

        foreach ($this->bladeExtensions as $tagName => $interpolation) {
            Blade::extend(function ($view, $compiler) use ($tagName, $interpolation) {
                $pattern = $compiler->createMatcher($tagName);

                return preg_replace($pattern, $interpolation, $view);
            });
        }
    }
}

Can you suggest another solution?