shorten arguments
Before adoption: this commit came in with the history the project adopted, so no landing records it.
add test for single line update changelog
authored by David Lord · committed by David Lord · parent bb8ef40 · Browse files · 3 files·+48 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+48 added−23 removed
- tests:+19 added−8 removed
- other:+29 added−15 removed
Provenance
- Commit
baa18e0- Tree
50cea78- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
bb8ef40
3 files changed+48 added−23 removed
modified:jinja2/filters.py+27 added-15 removed
524 unmodified lines525 rv = Markup(rv)526 return rv527 528 529-def do_indent(s, width=4, indent_first=False, indent_blank_lines=False, indentfirst=None):530- """Return a copy of the passed string, each line indented by531- 4 spaces. The first line is not indented. If you want to532- change the number of spaces or indent the first line too533- you can pass additional parameters to the filter:529+def do_indent(530+ s, width=4, first=False, blank=False, indentfirst=None531+):532+ """Return a copy of the string with each line indented by 4 spaces. The533+ first line and blank lines are not indented by default.534 535- .. sourcecode:: jinja535+ :param width: Number of spaces to indent by.536+ :param first: Don't skip indenting the first line.537+ :param blank: Don't skip indenting empty lines.538 537- {{ mytext|indent(2, true) }}538- indent by two spaces and indent the first line too.539+ .. versionchanged:: 2.10540+ Blank lines are not indented by default.541+542+ Rename the ``indentfirst`` argument to ``first``.543 """544 if indentfirst is not None:541- warnings.warn('The use of indentfirst is obsolete. '542- 'You should use indent_first instead.', DeprecationWarning)543- indent_first = indentfirst544- s += '\n' # this quirk is necessary for splitlines method545+ warnings.warn(DeprecationWarning(546+ 'The "indentfirst" argument is renamed to "first".'547+ ), stacklevel=2)548+ first = indentfirst549+550+ s += u'\n' # this quirk is necessary for splitlines method551 indention = u' ' * width546- if indent_blank_lines:552+553+ if blank:554 rv = (u'\n' + indention).join(s.splitlines())555 else:556 lines = s.splitlines()557 rv = lines.pop(0)558+559 if lines:552- rv += u'\n' + u'\n'.join(indention + line if line else line for line in lines)553- if indent_first:560+ rv += u'\n' + u'\n'.join(561+ indention + line if line else line for line in lines562+ )563+564+ if first:565 rv = indention + rv566+567 return rv568 569 570 @environmentfilter613 unmodified linesmodified:tests/test_filters.py+19 added-8 removed
135 unmodified lines136 assert out == 'a|b'137 138 def test_indent(self, env):139 text = '\n'.join(['', 'foo bar', ''])140- tmpl = env.from_string('{{ foo|indent(2, false, false) }}')141- assert tmpl.render(foo=text) == '\n foo bar\n'142- tmpl = env.from_string('{{ foo|indent(1, false, true) }}')143- assert tmpl.render(foo=text) == '\n foo bar\n '144- tmpl = env.from_string('{{ foo|indent(1, true, false) }}')145- assert tmpl.render(foo=text) == ' \n foo bar\n'146- tmpl = env.from_string('{{ foo|indent(1, true, true) }}')147- assert tmpl.render(foo=text) == ' \n foo bar\n '140+ t = env.from_string('{{ foo|indent(2, false, false) }}')141+ assert t.render(foo=text) == '\n foo bar\n'142+ t = env.from_string('{{ foo|indent(2, false, true) }}')143+ assert t.render(foo=text) == '\n foo bar\n '144+ t = env.from_string('{{ foo|indent(2, true, false) }}')145+ assert t.render(foo=text) == ' \n foo bar\n'146+ t = env.from_string('{{ foo|indent(2, true, true) }}')147+ assert t.render(foo=text) == ' \n foo bar\n '148 149+ t = env.from_string('{{ "jinja"|indent }}')150+ assert t.render() == 'jinja'151+ t = env.from_string('{{ "jinja"|indent(first=true) }}')152+ assert t.render() == ' jinja'153+ t = env.from_string('{{ "jinja"|indent(blank=true) }}')154+ assert t.render() == 'jinja'155+156+ def test_indentfirst_deprecated(self, env):157+ with pytest.warns(DeprecationWarning):158+ env.from_string('{{ "jinja"|indent(indentfirst=true) }}').render()159+160 def test_int(self, env):161 class IntIsh(object):162 def __int__(self):163 return 42488 unmodified linesmodified:CHANGES+2 added
27 unmodified lines28 - Add ``min`` and ``max`` filters. (`#475`_)29 - Add tests for all comparison operators: ``eq``, ``ne``, ``lt``, ``le``,30 ``gt``, ``ge``. (`#665`_)31 - ``import`` statement cannot end with a trailing comma. (`#617`_, `#618`_)32+- ``indent`` filter will not indent blank lines by default. (`#685`_)33 34 .. _#469: https://github.com/pallets/jinja/pull/46935 .. _#475: https://github.com/pallets/jinja/pull/47536 .. _#478: https://github.com/pallets/jinja/pull/47837 .. _#617: https://github.com/pallets/jinja/pull/61738 .. _#618: https://github.com/pallets/jinja/pull/61839 .. _#665: https://github.com/pallets/jinja/pull/66540+.. _#685: https://github.com/pallets/jinja/pull/68541 42 Version 2.9.643 -------------44 (bugfix release, released on April 3rd 2017)504 unmodified lines