Coder Social home page Coder Social logo

include tag whitespace about fluid HOT 13 CLOSED

sebastienros avatar sebastienros commented on July 17, 2024
include tag whitespace

from fluid.

Comments (13)

sebastienros avatar sebastienros commented on July 17, 2024 1

Sorry if I am being verbose on this thread, but it's important that we all understand the pros and cons of each solution.

Right now Fluid will strip the whitespace before a block tag content, which happens in this case. The idea is that in most cases we don't want to render indentations before code flow tags, like assign, if, for, ...

Take this example:

{% for i in (1..10) %}
  {% assign foo = i %}
{% endfor %}

Without this default behavior, we would get an output containing 10 empty lines, though nothing should be rendered.

You can take a look a this file for tests that show how it handles whitespace: https://github.com/sebastienros/fluid/blob/dev/Fluid.Tests/WhiteSpaceTests.cs

What I would suggest right now to solve your problem, is that we create a custom tag that would indent a section, like this:

{% indent: 4 %}
  {% include 'foo' %}
{% endindent %}

The result would be that every line in the block would be indented by 4 spaces. We would add an optional parameter with the string to repeat, like tabs.

from fluid.

hishamco avatar hishamco commented on July 17, 2024

As I can see from your code snippet before, seems the for statement can't preserve the spaces.

@sebastienros is this how it works?, or is it a bug? Coz I see DotLiquid preserve the spaces

from fluid.

sebastienros avatar sebastienros commented on July 17, 2024

from fluid.

hishamco avatar hishamco commented on July 17, 2024

For simplification we should preserve the whitespace, or add an option as you suggest before, but I don't think specifying the behavior per tag is a good option

from fluid.

sebastienros avatar sebastienros commented on July 17, 2024

from fluid.

hishamco avatar hishamco commented on July 17, 2024

Sounds good, let me check ..

from fluid.

arnederuwe avatar arnederuwe commented on July 17, 2024

just fyi, dotLiquid supports this scenario only if the contents of my AutoProperty.liquid example are only one line.

If my AutoProperty.liquid would be this:

[Column]
public {{ col.PropertyType }} {{ col.PropertyName }} { get; set; }

The results in dotLiquid would be

        [Column]
public string Name { get; set; }
        [Column]
public int PrincipalId { get; set; }

I would expect multiline included files to be evenly whitespaced

from fluid.

sebastienros avatar sebastienros commented on July 17, 2024

if the contents of my templates are only one line

That's not what it does, it's just rendering the whitespace, for each time the block is rendered. Nothing to do with {% include %} or the fact that it's only one line. It happens to look how you would like because it does it.

What could be done though is to add a property to the include tag such that new lines are also padded. And the padded value could be global variable in your main template such that you can call it recursively.

We should still handle the whitespace issue that you have found. And look at liquid if it supports what I just described.

from fluid.

sebastienros avatar sebastienros commented on July 17, 2024

/cc @RSuter I assume you would love that

from fluid.

arnederuwe avatar arnederuwe commented on July 17, 2024

relevant liquid issue: Shopify/liquid#925

It seems liquid and dotLiquid behave exactly the same in this scenario.
Just a question, but why does liquid strip whitespaces by default? Is'nt that what {% -%} is for?
EDIT, I read your docs ;) and it indeed seems like a nice improvement over liquid, but I think the Include tag is the exception to this rule

I think your indent solution is a good idea, as it would keep the compatibility with liquid templates. Depending on how Shopify/liquid#925 turns out, you could add the new tag syntax discussed there and deprecate the indent tag, or keep both.

For me this isn't that big (urgent) of an issue, I'm currently using Roslyn at the end of my code generation to format everything nicely, but it would be nice to ditch that dependency

from fluid.

sebastienros avatar sebastienros commented on July 17, 2024

You are right, we still need to fix the fact that the whitespace is ignored in this case.

To behave exactly the same as the reference implementation we could have a flag. Let me check.

from fluid.

hishamco avatar hishamco commented on July 17, 2024

Make an option such as EnableWhitespace will be handy

from fluid.

sebastienros avatar sebastienros commented on July 17, 2024

The 2.x version doesn't strip whitespaces by default anymore, and there are options to change the behavior for each type of tags.

from fluid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.