Skip to content
Myr

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

3 files+48 added−23 removed

modified:jinja2/filters.py+27 added-15 removed
524 unmodified lines
525 rv = Markup(rv)526 return rv527528529def 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:529def 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.534535 .. 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.538537 {{ 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.541542 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 = indentfirst549550 s += u'\n' # this quirk is necessary for splitlines method551 indention = u' ' * width546 if indent_blank_lines:552553 if blank:554 rv = (u'\n' + indention).join(s.splitlines())555 else:556 lines = s.splitlines()557 rv = lines.pop(0)558559 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 )563564 if first:565 rv = indention + rv566567 return rv568569570@environmentfilter
613 unmodified lines
modified:tests/test_filters.py+19 added-8 removed
135 unmodified lines
136 assert out == 'a|b'137138 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 '148149 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'155156 def test_indentfirst_deprecated(self, env):157 with pytest.warns(DeprecationWarning):158 env.from_string('{{ "jinja"|indent(indentfirst=true) }}').render()159160 def test_int(self, env):161 class IntIsh(object):162 def __int__(self):163 return 42
488 unmodified lines
modified:CHANGES+2 added
27 unmodified lines
28- 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`_)3334.. _#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/6854142Version 2.9.643-------------44(bugfix release, released on April 3rd 2017)
504 unmodified lines