beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.63k stars 1.39k forks source link

Problem with TWIG template support #991

Open prettydiff opened 8 years ago

prettydiff commented 8 years ago

https://github.com/Glavin001/atom-beautify/issues/1122

bitwiseman commented 5 years ago

Fpr reference:

Description

With craft cms your twig files are all saved as HTML, so when trying to solve this I saved as .twig just in case to see if that would fix the problem, but no luck. It seems that twig elements such as {{ }}, {# #}, {% %} are all placed inline and indentation is ignored. If it helps, I have it set to beautify on save.

Expected Results

The beautified code should have looked like:

{#
# Design Index template
# _________________________
#
# This template gets loaded whenever the Design index is requested, because
# the Design Index single_entry section's Template setting is set to
# "design/_index".
#
# An `entry` variable will be automatically passed to this template, which will
# be set to the Design Index entry.
#}

{# Rearrange entries #}
{% if filmEntries|length and designerEntries|length %}
    {% for i in 0..(filmEntries|length - 1) %}
        {# Film Entry #}
        {% set entries = entries|merge([filmEntries.nth(i)]) %}
        {# Designer Entries #}
        {% set entries = entries|merge(
            designerEntries[i * filmOffset : filmOffset]
        ) %}
    {% endfor %}
    {% set entries = entries|merge(
        designerEntries[filmOffset * filmEntries|length : filmOffset]
    ) %}
{% elseif designerEntries|length and filmEntries|length == 0 %}
    {# No short films in this year #}
    {% set entries = designerEntries %}
{% elseif filmEntries|length  and designerEntries|length == 0 %}
    {% set entries = filmEntries %}
{% endif %}