Code

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#3532 closed (fixed)

Give the template tag "spaceless" an option wether to leave a single space or none.

Reported by: ampaze@… Owned by: adrian
Component: Template system Version: master
Severity: Keywords: spaceless template tag
Cc: treborhudson@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

As I am having CSS trouble with IE, I need to have absolutely no whitechars between list elements.

{% spaceless %} seems to be the way to go. And while it removes all the
whitespaces, it puts a single space back, for convenience i guess.

I think this means to either extend the spaceless tag to be able to choose
what to do or make a new one?

Attachments (2)

spaceless.diff (5.0 KB) - added by Rob Hudson <treborhudson@…> 7 years ago.
Spaceless with optional numeric argument patch
reintroduce_space.diff (823 bytes) - added by shugyoku 6 years ago.
Reintroduce spaces for anchor tags that enclose text

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by Rob Hudson <treborhudson@…>

  • Cc treborhudson@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I agree... when I first used this I expected no spaces (in other words: spaceless). I too would like a "no I really mean spaceless" templatetag.

Perhaps spaceless should be renamed to normalize or something?

Or change the templatetag to accept an optional numeric value for the number of spaces to put back with the default being 1? ie: {% spaceless 0 %}{% endspaceless %}

comment:2 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Accepted

Sounds good, someone write up the patch.

Changed 7 years ago by Rob Hudson <treborhudson@…>

Spaceless with optional numeric argument patch

comment:3 Changed 7 years ago by Rob Hudson <treborhudson@…>

I was about to code the patch to add spaces if none existed, but since this wasn't there before, I decided not to.

Would it be worth considering, that if the numeric value is > 0, to add spaces between tags if none existed prior? This would have the benefit that all spaces are uniform. It should be as simple as changing the \s+ to a \s*? in the regex, but I'm not convinced this is the best way to go.

comment:4 Changed 7 years ago by ampaze@…

Nice work! In my opinion {% spaceless %} should not add spaces, if there weren't any in the first place.

Btw. I think that the actual number of spaces added, is actually not that important, as multiple spaces will be shown as one by the browser anyway.

comment:5 Changed 7 years ago by Manoj Govindan <egmanoj@…>

  • Has patch set

comment:6 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Accepted to Ready for checkin

Thanks Rob

If we worry about adding spaces to tags it's a slight change in current functionality. For now let's stick with this. Like ampaze says it probably doesn't really matter about how many spaces. So maybe having a numeric value is a wee bit overkill but it solves the problem so I'm marking as ready.

comment:7 Changed 7 years ago by Rob Hudson <treborhudson@…>

Personally, I think the default should be no spaces, with an option to add spaces. Would there be objections to that? Or does that break BC?

comment:8 Changed 7 years ago by russellm

  • Triage Stage changed from Ready for checkin to Design decision needed

I'm inclined to agree on the 'spaceless should mean spaceless' issue. I'm moving this discussion to the dev list so we can get an offical pronouncement on whether backwards compatibility is worth maintaining here.

comment:9 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [4885]) Fixed #3532 -- Made spaceless template tag remove all spaces, rather than preserving a single space. Thanks for the suggestion, ampaze@….

comment:10 Changed 7 years ago by anonymous

This change broke my site, of course, as it undid the change described here: #1227 :-(

Guess I have to roll my own spaceless filter so I get something I can trust (it would be nice with one that understands PRE tags anyway).

Changed 6 years ago by shugyoku

Reintroduce spaces for anchor tags that enclose text

comment:11 Changed 6 years ago by shugyoku

For others who need to, this patch can help reintroduce spaces between anchor tags that enclose text (ilke the example in #1227).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.