Elhebert / laravel-sri

Subresource Integrity hash generator for laravel
MIT License
40 stars 16 forks source link

[v3] Blade component #62

Closed Elhebert closed 3 years ago

Elhebert commented 4 years ago

I finally found some time to draft a PR for the blade component.

For more details check #57

It's a first draft, but here's what the API could look like. This would simplify the usage of the package.

<x:sri.script src="/public/js/app.js" />
<!-- <script src="{{ asset("/public/js/app.js") }}" integrity= "..." /> -->

<x:sri.script.mix src="/public/js/app.js />
<!-- <script src="{{ mix("/public/js/app.js") }}"  integrity= "..." /> -->

<x:sri.link href="/public/css/app.css" rel="stylesheet" />
<!-- <link href="{{ asset("/public/css/app.css") }} rel="stylesheet"  integrity= "..." /> -->

<x:sri.link.mix href="/public/css/app.css" rel="stylesheet" />
<!-- <link href="{{ mix("/public/css/app.css") }} rel="stylesheet"  integrity= "..." /> -->
Elhebert commented 4 years ago

Just added basic tests and cleaned up after removing the blade directive. I also updated the API a little bit and moved the mix part as an attribute to you have the same component for asset and mix which is less maintenance 🤔

<x:sri.script src="/public/js/app.js" />
<!-- <script src="{{ asset("/public/js/app.js") }}" integrity= "..." /> -->

<x:sri.script src="/public/js/app.js" mix />
<!-- <script src="{{ mix("/public/js/app.js") }}" integrity= "..." /> -->

<x:sri.link href="/public/css/app.css" rel="stylesheet" />
<!-- <link href="{{ asset("/public/css/app.css") }} rel="stylesheet"  integrity= "..." /> -->

<x:sri.link href="/public/css/app.css" rel="stylesheet" mix />
<!-- <link href="{{ mix("/public/css/app.css") }} rel="stylesheet"  integrity= "..." /> -->
Elhebert commented 4 years ago

I decided to drop Laravel 7 support. I had to many issues with the tests.

I also added a @once directive around the component to never re-render the component more than once.