New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument iterables ala jinja ? #125

Closed
sqlalchemy-bot opened this Issue Jan 19, 2010 · 12 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Jan 19, 2010

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

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 20, 2010

Changes by Michael Bayer (@zzzeek):

  • changed title from "Instrument interables ala jinja ?" to "Instrument iterables ala jinja ?"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 21, 2010

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}
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 22, 2010

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.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jan 22, 2010

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
   ...
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 5, 2010

Michael Bayer (@zzzeek) wrote:

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

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 5, 2010

Changes by Michael Bayer (@zzzeek):

  • removed labels: bug, caching
  • added labels: compiler, feature
  • changed milestone from "0.3" to "0.4"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 13, 2010

Michael Bayer (@zzzeek) wrote:

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

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 13, 2010

Changes by Michael Bayer (@zzzeek):

  • removed milestone (was: "0.4")
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 18, 2012

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.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 24, 2012

Michael Bayer (@zzzeek) wrote:

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

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 29, 2012

Michael Bayer (@zzzeek) wrote:

merged it in 6e7ad2d - spectacular !!

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 29, 2012

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