-
Notifications
You must be signed in to change notification settings - Fork 7
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
Don't output empty lines for control flow template arguments #9
Comments
DesignThe design principle of slt2: keep the implementation simple. We should have a consistent and well-designed rule for dealing with whitespaces. I don't want to turn this project into a pile of special cases. What others doSo I investigated some other template processors to see how they deal with whitespaces: Handlebars introduced a grammar that user can control whitespace stripping in a fine-grained way: http://handlebarsjs.com/expressions.html#whitespace-control handlebars-lang/handlebars.js#336 . But I think this seems too complicated. Jinja2's
And a shocking fact: PHP deletes newlines after closing tag: https://brian.moonspot.net/php-history-newline-closing-tag My ideaI think the Jinja's
Your code will output:
My idea is slightly different than Jinja's rule. The option name is
ImplementationI will implement this feature myself because I think the current code need some refactor and unit testing. |
Maybe I don't have enough time to refactor it soon (in this week). You are welcome to contribute if you like :). |
Thanks for the feedback, I'll take a look at it. |
My Ideas on implementing this feature (and refactor slt2 at the same time): Instead of
Example:
This would create the following table:
One possible way to handle includes: Call |
Your idea is very similar to mine: adding a lexing phase, just like what compilers do. And yes, But for me, I prefer there would be only 2 types of chunks:
After I think you can just implement My current plan is the API will be changed in v2.0. And #12 may also be considered in v2.0 (or v2.1). |
So no table of lines, only chunks. That's much easier to implement as I just noticed while trying to implement what I had proposed. |
Yes, your example will be parsed as: {
" bla \n ",
"#{some template stuff}#",
" \n \n",
......
} I think there's no need to break the template into lines. And the chunk's type can be determined by |
I noticed, that when I write something like this:
The output is something like:
If I don't want these two empty lines, I would have to write everything into one line like:
This is really ugly to read though. Would you be willing to accept a pull request that would check if a line only contains a control flow template parameter and, if so, doesn't emit those empty lines. (This could be hidden behind some kind of configuration parameter if necessary).
If this is a feature that you think will fit into the scope of slt2, I'd take a look if it is possible to implement this.
The text was updated successfully, but these errors were encountered: