#2594: Template system should handle whitespace better
----------------------------------------------------------+-----------------
          Reporter:  Gary Wilson <gary.wil...@gmail.com>  |         Owner:  
jshedd
            Status:  new                                  |     Milestone:      
  
         Component:  Template system                      |       Version:  SVN 
  
        Resolution:                                       |      Keywords:      
  
             Stage:  Someday/Maybe                        |     Has_patch:  1   
  
        Needs_docs:  0                                    |   Needs_tests:  0   
  
Needs_better_patch:  0                                    |  
----------------------------------------------------------+-----------------
Comment (by jshedd):

 As requested by Alex_Gaynor, running Gary Wilson's benchmark:

 {{{
 python -m timeit -n 50 -s "from views import my_render" "my_render()"

 Django 1.1.1:
 50 loops, best of 3: 3.64 msec per loop
 50 loops, best of 3: 3.66 msec per loop
 50 loops, best of 3: 3.65 msec per loop

 Trunk, without patch:
 50 loops, best of 3: 4.12 msec per loop
 50 loops, best of 3: 4.11 msec per loop
 50 loops, best of 3: 4.14 msec per loop

 Trunk, with patch:
 50 loops, best of 3: 4.13 msec per loop
 50 loops, best of 3: 4.11 msec per loop
 50 loops, best of 3: 4.13 msec per loop
 }}}

 Script looked like:
 {{{
 #!python
 from django.template import Context, Template
 from django.conf import settings
 settings.configure()

 def my_render():
     s = """\
 <html>
 <body>
     <div id="content">
     {% if items %}
     <ul>
         <li>Single item:</li>
         <li>
         {{ item.0.name }}
         </li>
     {% for item in items %}

         {% if item.name %}
         <li>{{ item.name }}</li>
         {% endif %}
         {% if not item.name %}
         <li>No name item</li>
         {% endif %}
         {% for item in fooitems %}
         <li>{{ item.name }}</li>
         {% endfor %}
         {% if item.des %}
         <li>{{ item.des }}</li>
         {% endif %}
     {% endfor %}
     {% if items %}
         <li>Spaceless items to follow:</li>
         {% spaceless %}
         {% for item in items %}

         <li>{{ item.name }}</li>
         {% endfor %}
         {% endspaceless %}
     {% endif %}
     </ul>
     {% endif %}
     {% if items %}
     <ul>
     {% for item in items %}
         {{ item.name }}
     {% endfor %}
     {% for foo in foos %}

         {{ foo }}
     {% endfor %}
     {% for item in items %}
         <li>huh{{ foo }}</li>
     {% endfor %}
     </ul>
     {% endif %}
     {% if items %}<p>We have items.</p>{% endif %}
     {% if items %}
     <p>We have items.</p>
     {% endif %}
     {% if foo %}<p>We have foo.</p>{% endif %}
     {% if foo %}
     <p>We have foo.</p>
     {% endif %}
     </div>
 </body>
 </html>
 """
     class Item:
         pass
     items = []
     for x in range(4):
         item = Item()
         item.name = 'item' + str(x)
         items.append(item)
     t = Template(s)
     c = Context({'items': items})
     return t.render(c)
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/2594#comment:18>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to