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

Ignore empty lines in indent filter #681 #685

Merged
merged 2 commits into from Jul 7, 2017

Conversation

3 participants
@jkfran
Contributor

jkfran commented Feb 28, 2017

Ignore empty lines in indent filter #681

@ThiefMaster

This comment has been minimized.

Show comment
Hide comment
@ThiefMaster

ThiefMaster Feb 28, 2017

Member

Could you please rebase the PR? Generally it's a good idea to use separate branches based off upstream/master for PRs instead of doing the changes in your own master branch.

While this can be done when merging a PR, sometimes people merge using a merge commit instead of rebase/squash and in that case the extra noise would remain in the upstream history forever.

Member

ThiefMaster commented Feb 28, 2017

Could you please rebase the PR? Generally it's a good idea to use separate branches based off upstream/master for PRs instead of doing the changes in your own master branch.

While this can be done when merging a PR, sometimes people merge using a merge commit instead of rebase/squash and in that case the extra noise would remain in the upstream history forever.

Show outdated Hide outdated jinja2/filters.py
rv = (u'\n' + indention).join(s.splitlines())
lines = s.splitlines()
rv = lines.pop(0) + u'\n'
rv += u'\n'.join([indention + l if l else l for l in lines])

This comment has been minimized.

@ThiefMaster

ThiefMaster Feb 28, 2017

Member

lowercase-L is not a good choice (and actually disallowed as per PEP8, just like uppercase-i)

@ThiefMaster

ThiefMaster Feb 28, 2017

Member

lowercase-L is not a good choice (and actually disallowed as per PEP8, just like uppercase-i)

@jkfran

This comment has been minimized.

Show comment
Hide comment
@jkfran

jkfran Feb 28, 2017

Contributor

Hello @ThiefMaster thank you!
I'm sorry for the merge commits. What do you think now?

Contributor

jkfran commented Feb 28, 2017

Hello @ThiefMaster thank you!
I'm sorry for the merge commits. What do you think now?

@ThiefMaster

I'd really like to see some unit tests for this. An optional argument to the filter to keep the old behavior would be nice too - while I don't see any good reason for that behavior people might want it for some reason I can't imagine right now.

Show outdated Hide outdated jinja2/filters.py
rv = (u'\n' + indention).join(s.splitlines())
lines = s.splitlines()
rv = lines.pop(0) + u'\n'
rv += u'\n'.join([indention + line if line else line for line in lines])

This comment has been minimized.

@ThiefMaster

ThiefMaster Feb 28, 2017

Member

the [] isn't needed since there's only one argument to join()

@ThiefMaster

ThiefMaster Feb 28, 2017

Member

the [] isn't needed since there's only one argument to join()

This comment has been minimized.

@jkfran

jkfran Mar 1, 2017

Contributor

@ThiefMaster well it's Generator Expressions vs. List Comprehension, I was reading and you are right for these case Generator Expression is better.
http://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehension

@jkfran

jkfran Mar 1, 2017

Contributor

@ThiefMaster well it's Generator Expressions vs. List Comprehension, I was reading and you are right for these case Generator Expression is better.
http://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehension

@ThiefMaster

This comment has been minimized.

Show comment
Hide comment
@ThiefMaster

ThiefMaster Mar 13, 2017

Member

Could you add an entry to the changelog file? The PR looks good so far (not a fan of the all-lowercase-no-underscore naming of the argument but the existing one uses the same scheme it's consistent).

Member

ThiefMaster commented Mar 13, 2017

Could you add an entry to the changelog file? The PR looks good so far (not a fan of the all-lowercase-no-underscore naming of the argument but the existing one uses the same scheme it's consistent).

@davidism davidism self-requested a review Apr 5, 2017

Show outdated Hide outdated jinja2/filters.py
rv = (u'\n' + indention).join(s.splitlines())
else:
lines = s.splitlines()
rv = lines.pop(0) + u'\n'

This comment has been minimized.

@davidism

davidism Apr 6, 2017

Member

This adds a trailing newline if there is only one line, unlike indentblanklines=True.

@davidism

davidism Apr 6, 2017

Member

This adds a trailing newline if there is only one line, unlike indentblanklines=True.

Show outdated Hide outdated jinja2/filters.py
else:
lines = s.splitlines()
rv = lines.pop(0) + u'\n'
rv += u'\n'.join(indention + line if line else line for line in lines)

This comment has been minimized.

@davidism

davidism Apr 6, 2017

Member

This removes leading and trailing blank lines, unlike indentblanklines=True.

@davidism

davidism Apr 6, 2017

Member

This removes leading and trailing blank lines, unlike indentblanklines=True.

Show outdated Hide outdated tests/test_filters.py
tmpl = env.from_string('{{ foo|indent(2) }}|{{ foo|indent(2, true) }}')
text = '\n'.join([' '.join(['foo', 'bar'] * 2)] * 2)
tmpl = env.from_string('{{ foo|indent(2) }}|'
'{{ foo|indent(2, true, true) }}')

This comment has been minimized.

@davidism

davidism Apr 6, 2017

Member

Let's split each case into separate renders rather than separating them with |.

@davidism

davidism Apr 6, 2017

Member

Let's split each case into separate renders rather than separating them with |.

Show outdated Hide outdated tests/test_filters.py
assert out == ('foo bar foo bar\n foo bar foo bar| '
'foo bar foo bar\n foo bar foo bar')
assert out == ('foo bar\n\n foo baz\n foo bar\n\n foo baz| '
'foo bar\n \n foo baz\n foo bar\n \n foo baz')

This comment has been minimized.

@davidism

davidism Apr 6, 2017

Member

This doesn't cover indent(2, False, True) or indent(2, True, False).

@davidism

davidism Apr 6, 2017

Member

This doesn't cover indent(2, False, True) or indent(2, True, False).

Show outdated Hide outdated jinja2/filters.py
@@ -445,7 +445,7 @@ def do_urlize(eval_ctx, value, trim_url_limit=None, nofollow=False,
return rv
def do_indent(s, width=4, indentfirst=False):
def do_indent(s, width=4, indentfirst=False, indentblanklines=False):

This comment has been minimized.

@davidism

davidism Apr 6, 2017

Member

I know @ThiefMaster said it's consistent with indentfirst, but I'd rather just break consistency and use the easier to read indent_blank_lines.

@davidism

davidism Apr 6, 2017

Member

I know @ThiefMaster said it's consistent with indentfirst, but I'd rather just break consistency and use the easier to read indent_blank_lines.

This comment has been minimized.

@davidism

davidism Apr 6, 2017

Member

If you want to, also change the signature to do_indent, s, width=4, indent_first=False, indent_blank_lines=False, indentfirst=None) and raise a deprecation warning if indentfirst is not None. Not required though, I can follow up with this after merging.

@davidism

davidism Apr 6, 2017

Member

If you want to, also change the signature to do_indent, s, width=4, indent_first=False, indent_blank_lines=False, indentfirst=None) and raise a deprecation warning if indentfirst is not None. Not required though, I can follow up with this after merging.

jkfran and others added some commits Mar 1, 2017

shorten arguments
add test for single line
update changelog

@davidism davidism merged commit e276843 into pallets:master Jul 7, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment