Skip to content

Commit

Permalink
Merge 8161e1f into cc3009e
Browse files Browse the repository at this point in the history
  • Loading branch information
wanshot committed Jan 28, 2018
2 parents cc3009e + 8161e1f commit 975732f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modelsdoc/templates/modelsdoc/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

{% for model in models %}
{{ model.name }}({{ model.class_fullname }})
-----------------------------------------------------------------------------------------
+{% bytes_count_section '-' model.name model.class_fullname '()' %}


::

Expand Down
21 changes: 21 additions & 0 deletions modelsdoc/templatetags/modelsdoc_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
from __future__ import division, print_function, absolute_import, unicode_literals # NOQA

from wcwidth import wcswidth
from django.template import Library, Node

register = Library()
Expand Down Expand Up @@ -57,3 +58,23 @@ def emptylineless(parser, token):
@register.filter
def get_attr(obj, attr):
return getattr(obj, attr, '')


@register.simple_tag
def bytes_count_section(charactor, *args):
"""
Get string length line
Example usage::
{% bytes_count_section '-' 'test' 'テスト' %}
This example would return this HTML::
----------
"""
counter = 0
for v in args:
length = wcswidth(v)
counter += length
return counter * charactor
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def run_tests(self):

install_requires = [
'Django',
'Sphinx'
'Sphinx',
'wcwidth'
]

tests_require = [
Expand Down
16 changes: 16 additions & 0 deletions tests/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,19 @@ class Dummy(object):

self.assertEqual('test', self._callFUT(Dummy(), 'test'))
self.assertEqual('', self._callFUT(Dummy(), 'non_exists_attr'))


class TestBytesCountSection(TestCase):

def _getTargetTags(self):
return """
{% load modelsdoc_tags %}
{% bytes_count_section '-' 'test' 'テスト' %}
"""

def _callFUT(self, *args):
t = Template(self._getTargetTags())
return t.render(Context())

def test_bytes_count_section_length(self):
self.assertEqual('\n\n----------\n', self._callFUT())
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ deps =
coverage
mock
pbr<1.4
wcwidth
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8
Expand Down

0 comments on commit 975732f

Please sign in to comment.