SublimeHyperClick icon indicating copy to clipboard operation
SublimeHyperClick copied to clipboard

match Twig include tags with extra parameters

Open braver opened this issue 3 years ago • 2 comments

Ensures matches for just the file for tag style with extra parameters:

{% include 'template.html' with {'foo': 'bar'} %}

https://twig.symfony.com/doc/3.x/tags/include.html

Previously the regex would match from the first quote all the way to the last quote, but it shouldn't include the extra object with parameters.

Tested in regex101

braver avatar Jun 14 '22 08:06 braver

This PR is fine for sure.


I am using https://github.com/jfcherng-sublime/ST-my-settings/blob/dc509e19387cfa9ad827e78ee3b4dbb7e2f83791/Packages/User/HyperClick.sublime-settings#L80-L86 (although ' can be used in filename actually)

I think we don't have to match the rest of the string right after we have found the filename (the leading {% is quite a strong assertion). Anyway, merging them gives better performance and maintainability(?).

jfcherng avatar Jun 14 '22 09:06 jfcherng

Hm, yours has less repetition for sure, but for some of my test cases it doesn't work. You seem to have dropped the {{ include('file', {params}) }} form.

<div id="regular-event">
    <section class="eticket">
        {{ include('Etickets/_eticket_header.html.twig', {
            event : event,
            production : production,
            type: 'regular'
        }) }}
        <div class="eticket-body">
            {% for ticket in tickets %}
                {{ include('Etickets/_eticket_body.html.twig', { ticket: ticket, type: 'regular'}) }}
            {% endfor %}
        </div>
    </section>
</div>

But yeah, you don't have to match all the way to the end of the statement. The opening of the statement and the initial include, etc., keyword are good indicators of the intent.


Edit: added example.

braver avatar Jul 01 '22 09:07 braver

@aziz are you still maintaining this package? I would like to help out.

braver avatar Mar 22 '23 11:03 braver

I cannot add collaborators but I'd vouch for @braver and @jfcherng

cristianl avatar Mar 22 '23 14:03 cristianl

@cristianl thanks for merging! Can you tag a release with the latest changes?

@aziz to consider: we could also move the repo to the SublimeText org where multiple experienced package developers maintain lots of packages.

braver avatar Mar 22 '23 17:03 braver

2.6.0 is now up. Sorry for the long delay.

cristianl avatar Mar 23 '23 23:03 cristianl