prettydiff icon indicating copy to clipboard operation
prettydiff copied to clipboard

Beautify Twig Hash & Array

Open rubas opened this issue 6 years ago • 2 comments

1. Hash

Source

{% include 'any.twig' with { 'foo':bar} %}

Expected

{% include 'any.twig' with { 'foo': bar } %}

Result

{% include 'any.twig' with { 'foo':bar} %}

2. Array

Source

{% set foo = [1,{"foo":"bar"}] %}

Expected

{% set foo = [1, {"foo": "bar"}] %}

Result

{% set foo = [1,{"foo":"bar"}] %}

rubas avatar Aug 30 '19 12:08 rubas

I am not currently parsing the insides of the Twig tags, but I certainly should be. If I were to parse it similarly to how I parse JavaScript the output would look like:

Default presentation

<a>
    {% include 'any.twig' with {
        'foo' : bar
    } %}
</a>

and

<a>
    {% set foo = [
        1, {
            "foo": "bar"
        }
    ] %}
</a>

Setting options format_array and format_object to value inline

<a>
    {% include 'any.twig' with {
        'foo' : bar,
        'cat' : "meow"
    } %}
</a>
<a>
    {% include 'any.twig' = {
        'foo': bar, 'cat': "meow"
    } %}
</a>

and

<a>
    {% set foo = [
        1, {"foo": "bar"}
    ] %}
</a>

prettydiff avatar Aug 31 '19 10:08 prettydiff

That looks neat! As long as it is consistent, I'm very happy.

rubas avatar Sep 02 '19 06:09 rubas