Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Helper function? #83

Closed
tabacitu opened this issue Aug 18, 2023 · 4 comments
Closed

[Feature Request] Helper function? #83

tabacitu opened this issue Aug 18, 2023 · 4 comments

Comments

@tabacitu
Copy link
Member

We got some feedback that a helper function could be useful. And indeed it'd be easy to create a basset() function that returns... what? That's the question. What would it return?

It could be:

  • (a) the path to the internalized assed, so you can do <script src="{{ basset('https://path/to/file.js') }}">
  • (b) the entire output, as a string, so you can do {{ basset('https://path/to/file.js') }} instead of @basset('https://path/to/file.js')
  • (c) an object that implements Stringable... so if you echo it it's the same thing as (a) above... but you could also do other stuff to it like... I don't know 😅

So... probably (a) right? @promatik what do you think?

@tabacitu
Copy link
Member Author

Just realized if we do (a) or (c)... this would make basset() a drop-in replacement for Laravel's asset() helper. Which I think is great.

So you'd have two ways of using Basset:

  • @basset() to replace your <script src="https://path/to/file.js">
  • basset('https://path/to/file.js') to replace your asset('https://path/to/file.js')

🤯

@pxpm
Copy link
Contributor

pxpm commented Aug 18, 2023

Guess the helper would be a wrapper around Basset::getUrl() then. 👍

@tabacitu
Copy link
Member Author

🤷‍♂️ does that work if the asset hasn't been internalized yet? I don't think so. @promatik will know more, but I think it'd be more like:

public function basset(string $asset) {
    $status = Basset::basset($asset);

    // TODO: Maybe do some checks if the asset hasn't been internalized? I don't know.

    return Basset::getUrl($asset);
}

But in any case, yes, that would be the return, Basset::getUrl()

@promatik
Copy link
Contributor

Hey @tabacitu let's move this to #85 👌
I've made some changes there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants