Django

Code

Ticket #3532 (closed: fixed)

Opened 2 years ago

Last modified 5 months ago

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

Reported by: ampaze@gmx.net Assigned to: adrian
Milestone: Component: Template system
Version: SVN Keywords: spaceless template tag
Cc: treborhudson@gmail.com Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

spaceless.diff (5.0 kB) - added by Rob Hudson <treborhudson@gmail.com> on 02/21/07 10:46:09.
Spaceless with optional numeric argument patch
reintroduce_space.diff (0.8 kB) - added by shugyoku on 04/14/08 22:40:13.
Reintroduce spaces for anchor tags that enclose text

Change History

02/21/07 01:27:59 changed by Rob Hudson <treborhudson@gmail.com>

  • cc set to treborhudson@gmail.com.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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 %}

02/21/07 01:59:30 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

Sounds good, someone write up the patch.

02/21/07 10:46:09 changed by Rob Hudson <treborhudson@gmail.com>

  • attachment spaceless.diff added.

Spaceless with optional numeric argument patch

02/21/07 10:50:07 changed by Rob Hudson <treborhudson@gmail.com>

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.

02/21/07 11:23:49 changed by ampaze@gmx.net

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.

02/21/07 11:42:31 changed by Manoj Govindan <egmanoj@gmail.com>

  • has_patch set to 1.

02/21/07 14:05:29 changed by SmileyChris

  • 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.

02/21/07 18:43:01 changed by Rob Hudson <treborhudson@gmail.com>

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?

03/30/07 21:48:43 changed by russellm

  • 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.

03/31/07 20:09:21 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

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

08/19/07 07:40:32 changed 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).

04/14/08 22:40:13 changed by shugyoku

  • attachment reintroduce_space.diff added.

Reintroduce spaces for anchor tags that enclose text

04/14/08 22:42:16 changed 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/Change #3532 (Give the template tag "spaceless" an option wether to leave a single space or none.)




Change Properties
Action