RejectedSoftware Forums

Sign up

Change to diet handling of spacing?

I just did an "upgrade" to my dub repository, and all of my diet
template spacing is messed up. What happened? I have fixed most of it
(seems to be the space between the tag and the contained text is now not
part of the inner text, leading to many words running together)

In addition, I want to make this work, and I can't get it to work:

| (
a(href="somelink")>< click here
| )

No matter what I try, I can't get that closing parenthesis to hug the
anchor tag.

Before, this worked just fine (and with just the > directive on the
anchor). Is this a bug, or am I missing something?

-Steve

Re: Change to diet handling of spacing?

Am 11.04.2017 um 01:32 schrieb Steven Schveighoffer:

I just did an "upgrade" to my dub repository, and all of my diet
template spacing is messed up. What happened? I have fixed most of it
(seems to be the space between the tag and the contained text is now not
part of the inner text, leading to many words running together)

In addition, I want to make this work, and I can't get it to work:

| (
a(href="somelink")>< click here
| )

No matter what I try, I can't get that closing parenthesis to hug the
anchor tag.

Before, this worked just fine (and with just the > directive on the
anchor). Is this a bug, or am I missing something?

This pretty sure is a but. I'll have a look. A possible workaround would
be to disable pretty printing by passing a custom traits struct to render:

 @dietTraits struct DT { enum htmlOutputStyle = 

HTMLOutputStyle.compact; }

 render!("template.dt", DT, ...);

Re: Change to diet handling of spacing?

On 4/14/17 10:25 AM, Sönke Ludwig wrote:

Am 11.04.2017 um 01:32 schrieb Steven Schveighoffer:

I just did an "upgrade" to my dub repository, and all of my diet
template spacing is messed up. What happened? I have fixed most of it
(seems to be the space between the tag and the contained text is now not
part of the inner text, leading to many words running together)

In addition, I want to make this work, and I can't get it to work:

| (
a(href="somelink")>< click here
| )

No matter what I try, I can't get that closing parenthesis to hug the
anchor tag.

Before, this worked just fine (and with just the > directive on the
anchor). Is this a bug, or am I missing something?

This pretty sure is a but. I'll have a look. A possible workaround would
be to disable pretty printing by passing a custom traits struct to
render:

@dietTraits struct DT { enum htmlOutputStyle =

HTMLOutputStyle.compact; }

render!("template.dt", DT, ...);


Sorry to be pedantic, but just the second problem (unable to have no
space between anchor and parens) is a bug, or is the whole changing of
space handling a bug? I can't imagine anyone who has a lot of existing
diet code is going to like how the spacing has all been removed. In many
cases, I have to put trailing spaces at the end of text lines so the
words don't run together.

If it's a bug that will be fixed, I can revert to a previous vibe.d
rather than go through and make sure I have extra spaces everywhere.

-Steve

Re: Change to diet handling of spacing?

On Mon, 17 Apr 2017 08:40:49 -0400, Steven Schveighoffer wrote:

On 4/14/17 10:25 AM, Sönke Ludwig wrote:

Am 11.04.2017 um 01:32 schrieb Steven Schveighoffer:

I just did an "upgrade" to my dub repository, and all of my diet
template spacing is messed up. What happened? I have fixed most of it
(seems to be the space between the tag and the contained text is now not
part of the inner text, leading to many words running together)

In addition, I want to make this work, and I can't get it to work:

| (
a(href="somelink")>< click here
| )

No matter what I try, I can't get that closing parenthesis to hug the
anchor tag.

Before, this worked just fine (and with just the > directive on the
anchor). Is this a bug, or am I missing something?

This pretty sure is a but. I'll have a look. A possible workaround would
be to disable pretty printing by passing a custom traits struct to
render:

@dietTraits struct DT { enum htmlOutputStyle =

HTMLOutputStyle.compact; }

render!("template.dt", DT, ...);


Sorry to be pedantic, but just the second problem (unable to have no
space between anchor and parens) is a bug, or is the whole changing of
space handling a bug? I can't imagine anyone who has a lot of existing
diet code is going to like how the spacing has all been removed. In many
cases, I have to put trailing spaces at the end of text lines so the
words don't run together.

If it's a bug that will be fixed, I can revert to a previous vibe.d
rather than go through and make sure I have extra spaces everywhere.

-Steve

Sorry, I skipped the first paragraph. Just >< not working is a bug (fixed as #27 now). The missing white space in general is a consequence of the new compact output mode, and partially due to a small "optimization", where a tag that contains just text is rendered as <foo>text</foo> instead of putting the text on its own line.

Generally, the idea is that it must be possible for the compact output mode to generate output with no extraneous white space. Any white space except for newlines within text blocks ("." suffix) must be explicit.

At least, since inline tags are now supported, examples like the one above can be written more conveniently as | (#[a(href="someline") click here]), with the bonus of having the white space clearly defined.

Re: Change to diet handling of spacing?

On 4/18/17 9:42 AM, Sönke Ludwig wrote:

Sorry, I skipped the first paragraph. Just >< not working is a bug (fixed as #27 now).

Thanks, that will be good.

The missing white space in general is a consequence of the new compact output mode, and partially due to a small "optimization", where a tag that contains just text is rendered as <foo>text</foo> instead of putting the text on its own line.

So here is a typical issue I had. My layout template shows the user
being logged in or not, and if so, what the username is. So that snippit
looks like this:

     - if("username" in req.params)
       | Logged in as
       span#username #{req.params["username"]}
       a(href='/logout') Logout
     - else
       | Not Logged in
       a(href='/login') Login

In order to make this "correct", I had to add trailing spaces to e.g.
"Logged in as", so it doesn't say "Logged in asschveiguyLogout"

The problem I see happening to many people is that they write their
templates without thinking about spacing. HTML is nice in that it just
concatenates all whitespace into one space. So you don't have to think
about spacing, because most of the time it works.

In the places where you WANT spacing to be compact, you can add those ><
things, and will get the correct result. And those cases aren't as
numerous as the former ones.

I see a lot of people having problems with the new spacing mode. It
might be good to allow for the old mode via a parameter to the render
function. I know you specified a way to do compact spacing earlier in
the thread, is there a way to specify the old mode?

Generally, the idea is that it must be possible for the compact output mode to generate output with no extraneous white space. Any white space except for newlines within text blocks ("." suffix) must be explicit.

I get it and agree. I think the issue is going to be existing code bases
which did not care about spacing.

At least, since inline tags are now supported, examples like the one above can be written more conveniently as | (#[a(href="someline") click here]), with the bonus of having the white space clearly defined.

This is great news, I didn't know about it! Will make my diet code much
easier to read and write. Is there documentation about this? Is it part
of the standard vibe.d template engine or do I need to use diet-ng?

-Steve

Re: Change to diet handling of spacing?

On 4/20/17 8:08 AM, Steven Schveighoffer wrote:

On 4/18/17 9:42 AM, Sönke Ludwig wrote:

At least, since inline tags are now supported, examples like the one
above can be written more conveniently as | (#[a(href="someline")<br>click here]), with the bonus of having the white space clearly defined.

This is great news, I didn't know about it! Will make my diet code much
easier to read and write. Is there documentation about this? Is it part
of the standard vibe.d template engine or do I need to use diet-ng?

Nevermind that last question, looks like vibe.d already imports diet-ng,
so the question is moot :)

I also kind of figured out by trial and error how to do it, though docs
would be nice to update.

-Steve

Re: Change to diet handling of spacing?

On Thu, 20 Apr 2017 08:08:57 -0400, Steven Schveighoffer wrote:

On 4/18/17 9:42 AM, Sönke Ludwig wrote:

Sorry, I skipped the first paragraph. Just >< not working is a bug (fixed as #27 now).

Thanks, that will be good.

The missing white space in general is a consequence of the new compact output mode, and partially due to a small "optimization", where a tag that contains just text is rendered as <foo>text</foo> instead of putting the text on its own line.

So here is a typical issue I had. My layout template shows the user
being logged in or not, and if so, what the username is. So that snippit
looks like this:

     - if("username" in req.params)
       | Logged in as
       span#username #{req.params["username"]}
       a(href='/logout') Logout
     - else
       | Not Logged in
       a(href='/login') Login

In order to make this "correct", I had to add trailing spaces to e.g.
"Logged in as", so it doesn't say "Logged in asschveiguyLogout"

The problem I see happening to many people is that they write their
templates without thinking about spacing. HTML is nice in that it just
concatenates all whitespace into one space. So you don't have to think
about spacing, because most of the time it works.

In the places where you WANT spacing to be compact, you can add those ><
things, and will get the correct result. And those cases aren't as
numerous as the former ones.

I see a lot of people having problems with the new spacing mode. It
might be good to allow for the old mode via a parameter to the render
function. I know you specified a way to do compact spacing earlier in
the thread, is there a way to specify the old mode?

Generally, the idea is that it must be possible for the compact output mode to generate output with no extraneous white space. Any white space except for newlines within text blocks ("." suffix) must be explicit.

I get it and agree. I think the issue is going to be existing code bases
which did not care about spacing.

At least, since inline tags are now supported, examples like the one above can be written more conveniently as | (#[a(href="someline") click here]), with the bonus of having the white space clearly defined.

This is great news, I didn't know about it! Will make my diet code much
easier to read and write. Is there documentation about this? Is it part
of the standard vibe.d template engine or do I need to use diet-ng?

-Steve

Supporting the old mode (or one that mimics it as closely as possible) shouldn't be difficult. Alternatively, maybe the mentioned optimization should just be changed to <foo>text</foo> in places where the text would otherwise be on a separate line. Of course the problem remains for people who want to have minimal output.