utils.py 1.05 KB
Newer Older
1
2
3
4
# -*- coding: utf-8 -*-
"""bootstrap html helpers

:organization: Logilab
5
:copyright: 2013-2022 LOGILAB S.A. (Paris, FRANCE), license is LGPL.
Nicola Spanti's avatar
Nicola Spanti committed
6
:contact: https://www.logilab.fr/ -- mailto:contact@logilab.fr
7
8
9
10
"""

__docformat__ = "restructuredtext en"

Nsukami Patrick's avatar
Nsukami Patrick committed
11

12
13
class DropDownBox(object):
    ul_template = u'''
14
    <a class="dropdown-toggle %(klass)s" data-toggle="dropdown" href="#">
15
16
17
18
19
    %(title)s<span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu">%(actions)s</ul>'''

    li_template = u'<li>%(link)s<li>'

20
    def __init__(self, title, actions, klass=''):
21
22
        self.title = title
        self.actions = actions
23
        self.klass = klass
24
25
26
27

    def render(self, w):
        if not len(self.actions):
            return u''
28
        w(self.ul_template % {'title': self.title, 'klass': self.klass,
29
30
31
32
33
34
35
36
                              'actions': u''.join(self.render_items())})

    def render_items(self):
        for item in self.actions:
            yield self.li_template % {'link': self._item_value(item)}

    def _item_value(self, item):
        return item