Skip to content

Instrument iterables ala jinja ? #125

Closed

Description

@sqlalchemy-bot

Migrated issue, originally created by Michael Bayer (@zzzeek)

i.e. user does this:

% for x in collection:
    % if lastelement:
    % endif
% endif

we see the magic name "lastelement". We then compile to this:

% for lastelement, x in __M_marklast(collection):
    % if lastelement:
    % endif
% endif

easy !

tentative 0.3 feature. May come out.


Attachments: loop_instrumentation.patch | loop_instrumentation.2.patch | 125.patch

Activity

  1. sqlalchemy-bot commented on Jan 20, 2010

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • changed title from "Instrument interables ala jinja ?" to "Instrument iterables ala jinja ?"
  2. sqlalchemy-bot commented on Jan 21, 2010

    @sqlalchemy-bot
    Author

    Philip Jenvey (@pjenvey) wrote:

    I don't like this kind of magic. Some of the loop attributes Jinja provides could use enumerate or itertools.cycle instead, only the ones taking into account the end index of the loop aren't easily done

    http://jinja.pocoo.org/2/documentation/templates#for

    But how useful are those in practice anyway? Useful enough to warrant the magic? In some simpler cases you can even replace a check for the end of the loop with a check for the beginning of the loop, e.g.

    % for foo in bar:
       ${foo.name}
       % if not last:
           ,
       % endif
    
    # ->
    
    % for i, foo in enumerate(bar):
        % if i != 0:
            ,
        % end if
        ${foo.name}
    
  3. sqlalchemy-bot commented on Jan 22, 2010

    @sqlalchemy-bot
    Author

    Anonymous wrote:

    It's very useful to have access to first, last and cycle item. Productivity boost:)

    This is the second feature lacking in Mako (just after not having escape char for %) for my uses cases.

  4. sqlalchemy-bot commented on Jan 22, 2010

    @sqlalchemy-bot
    Author

    Anonymous wrote:

    Also keep in mind for nested loops.

    Something like this would come in handy:

    % for i in foobar as first_loop:
      % for j in foobar:
          % if first_loop.first:
              first!
          % endif
       ...
    
  5. sqlalchemy-bot commented on Mar 5, 2010

    @sqlalchemy-bot
    Author

    Michael Bayer (@zzzeek) wrote:

    pushing this off since I'd like to fast track 0.3 a bit

  6. sqlalchemy-bot commented on Mar 5, 2010

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • removed labels: bug, caching
    • added labels: compiler, feature
    • changed milestone from "0.3" to "0.4"
  7. sqlalchemy-bot commented on Nov 13, 2010

    @sqlalchemy-bot
    Author

    Michael Bayer (@zzzeek) wrote:

    this is a nice to have but i think 0.4 needs to come out faster than this

  8. sqlalchemy-bot commented on Nov 13, 2010

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • removed milestone (was: "0.4")
  9. sqlalchemy-bot commented on Mar 18, 2012

    @sqlalchemy-bot
    Author

    Anonymous wrote:

    It's safe to ignore the first loop_instrumentation patch. The second one has all the same changes plus a from __future__ import with_statement for people still using python2.5.

  10. sqlalchemy-bot commented on Mar 24, 2012

    @sqlalchemy-bot
    Author

    Michael Bayer (@zzzeek) wrote:

    let's move over to https://bitbucket.org/zzzeek/mako-loop for dev on this

  11. sqlalchemy-bot commented on Mar 29, 2012

    @sqlalchemy-bot
    Author

    Michael Bayer (@zzzeek) wrote:

    merged it in 6e7ad2d - spectacular !!

  12. sqlalchemy-bot commented on Mar 29, 2012

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions