Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Commit 36b91a8

Browse files
committed
Implemented basic variants of list group as includable template
1 parent 76ba08d commit 36b91a8

File tree

9 files changed

+171
-12
lines changed

9 files changed

+171
-12
lines changed

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Features
3232

3333
* Full-featured Bootstrap 3 template (3.3.5)
3434
* Latest Font Awesome integration (4.3.0)
35+
* Ready-to-use Bootstrap component templates
3536
* Intuitive template tag API for generating valid Bootstrap markup
3637
* Extensive and up-to-date documentation
3738
* Mainstream Python (2.7, 3.3, 3.4) and Django (1.7, 1.8) support
@@ -79,6 +80,19 @@ Prepare your page for Bootstrap and provide your content:
7980
<h1>Hello, I'm using django-bootstrap-ui!</h1>
8081
{% endblock %}
8182
83+
Bootstrap component templates
84+
*****************************
85+
86+
Render complete Bootstrap components by including our default implementations. Example:
87+
88+
#. Provide a list of strings ``['alpha', 'beta', 'gamma']`` as template variable ``items``
89+
90+
#. Include ``listgroup.html`` parameterized with ``type='list'`` and ``items=items``:
91+
92+
.. code:: Django
93+
94+
{% include 'bootstrap_ui/listgroup.html' with type='list' items=items only %}
95+
8296
Template tag API
8397
****************
8498

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% load bootstrap_ui_tags %}
2+
3+
{% if type == 'list' %}
4+
{% listgroup %}
5+
{% for text in items %}
6+
{% listgroupitem %}
7+
{{ text }}
8+
{% endlistgroupitem %}
9+
{% endfor %}
10+
{% endlistgroup %}
11+
{% elif type == 'linklist' %}
12+
{% listgroup use_tag='div' %}
13+
{% for text, url in items %}
14+
{% with link=url|default:'#' %}
15+
{% listgroupitem use_tag='a' link=link %}
16+
{{ text }}
17+
{% endlistgroupitem %}
18+
{% endwith %}
19+
{% endfor %}
20+
{% endlistgroup %}
21+
{% endif %}

docs/getting_started/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ Prepare your page for Bootstrap and provide your content:
4242
<h1>Hello, I'm using django-bootstrap-ui!</h1>
4343
{% endblock %}
4444
45+
Bootstrap component templates
46+
*****************************
47+
48+
Render complete Bootstrap components by including our default implementations. Example:
49+
50+
#. Provide a list of strings ``['alpha', 'beta', 'gamma']`` as template variable ``items``
51+
52+
#. Include ``listgroup.html`` parameterized with ``type='list'`` and ``items=items``:
53+
54+
.. code:: Django
55+
56+
{% include 'bootstrap_ui/listgroup.html' with type='list' items=items only %}
57+
4558
Template tag API
4659
****************
4760

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Features
3232

3333
* Full-featured Bootstrap 3 template (3.3.5)
3434
* Latest Font Awesome integration (4.3.0)
35+
* Ready-to-use Bootstrap component templates
3536
* Intuitive template tag API for generating valid Bootstrap markup
3637
* Extensive and up-to-date documentation
3738
* Mainstream Python (2.7, 3.3, 3.4) and Django (1.7, 1.8) support
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Bootstrap component templates
2+
=============================
3+
4+
Render complete Bootstrap components by including our default implementations.
5+
6+
List group
7+
----------
8+
9+
This template (``listgroup.html``) renders a list group. Two parameters are required:
10+
11+
* type
12+
* items
13+
14+
Basic example
15+
*************
16+
17+
Given a list of strings ``['alpha', 'beta', 'gamma']`` as template variable ``items``:
18+
19+
.. code:: Django
20+
21+
{% include 'bootstrap_ui/listgroup.html' with type='list' items=items only %}
22+
23+
This renders the following html code:
24+
25+
.. code:: HTML
26+
27+
<ul class="list-group">
28+
<li class="list-group-item">
29+
alpha
30+
</li>
31+
<li class="list-group-item">
32+
beta
33+
</li>
34+
<li class="list-group-item">
35+
gamma
36+
</li>
37+
</ul>
38+
39+
Linked items
40+
************
41+
42+
Given a list of 2-tuples containing ``[('alpha', 'http://example.org'), ('beta', 'local.html'), ('gamma', '#')]`` as template variable ``items``:
43+
44+
.. code:: Django
45+
46+
{% include 'bootstrap_ui/listgroup.html' with type='linklist' items=items only %}
47+
48+
This renders the following html code:
49+
50+
.. code:: HTML
51+
52+
<div class="list-group">
53+
<a class="list-group-item" href="http://example.org">
54+
alpha
55+
</a>
56+
<a class="list-group-item" href="local.html">
57+
beta
58+
</a>
59+
<a class="list-group-item" href="#">
60+
gamma
61+
</a>
62+
</div>

docs/templates/index.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
Templates
22
=========
33

4-
django-bootstrap-ui enables you to quickly get started through a set of predefined templates.
4+
django-bootstrap-ui enables you to quickly get started through a set of predefined templates. There are two sort of templates:
55

66
#. :doc:`skeletons/index`
77

88
These templates render entire html pages. They are meant to serve as base templates to be extended and provide HTML5 and Bootstrap skeletons.
99

10+
#. :doc:`components/index`
11+
12+
These templates encapsulate Bootstrap components. Included and parameterized as a one-liner within your page templates they will return completely rendered UI components.
13+
1014
.. toctree::
1115
:maxdepth: 2
1216

1317
skeletons/index
18+
components/index

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name='django-bootstrap-ui',
12-
version='0.1.0b2',
12+
version='0.1.0rc1',
1313
packages=find_packages(exclude=['tests', 'docs']),
1414
include_package_data=True,
1515
license='ISC License (ISCL)',

tests/templates/listgrouptags.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{% load bootstrap_ui_tags %}
22

3-
{% listgroup %}
4-
{% listgroupitem %}
5-
{{ content }}
6-
{% endlistgroupitem %}
7-
{% endlistgroup %}
3+
{% if not items %}
4+
{% listgroup %}
5+
{% listgroupitem %}
6+
{{ content }}
7+
{% endlistgroupitem %}
8+
{% endlistgroup %}
89

9-
{% if use_tag == 'a' %}
10-
{% listgroupitem use_tag=use_tag link=link %}
11-
{{ label }}
12-
{% endlistgroupitem %}
13-
{% endif %}
10+
{% if use_tag == 'a' %}
11+
{% listgroupitem use_tag=use_tag link=link %}
12+
{{ label }}
13+
{% endlistgroupitem %}
14+
{% endif %}
15+
{% endif %}
16+
17+
{% include 'bootstrap_ui/listgroup.html' with type=type items=items only %}

tests/tests.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,26 @@ def test_column_custom_grid_with_defaults_is_rendered(self):
123123
class ListGroupTagsTest(SimpleTestCase):
124124
SAMPLE_LINK = 'http://example.org'
125125
SAMPLE_LABEL = 'Linklabel'
126+
SAMPLE_LIST = [
127+
'alpha',
128+
'beta',
129+
'gamma',
130+
]
131+
SAMPLE_LINKLIST = [
132+
('alpha', SAMPLE_LINK),
133+
('beta', SAMPLE_LINK),
134+
('gamma', SAMPLE_LINK),
135+
]
126136

127137
LIST_GROUP_START = mark_safe('<ul class="list-group">')
128138
LIST_GROUP_END = mark_safe('</ul>')
129139

130140
LIST_GROUP_ITEM_START = mark_safe('<li class="list-group-item">')
131141
LIST_GROUP_ITEM_END = mark_safe('</li>')
132142

143+
LIST_GROUP_LINK_START = mark_safe('<div class="list-group">')
144+
LIST_GROUP_LINK_END = mark_safe('</div>')
145+
133146
LIST_GROUP_ITEM_LINK_START = mark_safe('<a class="list-group-item" href="' + SAMPLE_LINK + '">')
134147
LIST_GROUP_ITEM_LINK_END = mark_safe('</a>')
135148

@@ -162,6 +175,32 @@ def test_list_group_item_link_without_destination_raises_exception(self):
162175
with self.assertRaises(TemplateSyntaxError):
163176
self.template.render(Context({'use_tag': 'a'}))
164177

178+
def test_listgroup_list_is_rendered(self):
179+
rendered = self.template.render(Context({'type': 'list', 'items': self.SAMPLE_LIST}))
180+
self.assertInHTML(
181+
self.LIST_GROUP_START
182+
+ ''.join(self.LIST_GROUP_ITEM_START + item + self.LIST_GROUP_ITEM_END for item in self.SAMPLE_LIST)
183+
+ self.LIST_GROUP_END,
184+
rendered
185+
)
186+
187+
def test_listgroup_without_type_is_empty(self):
188+
rendered = self.template.render(Context({'items': self.SAMPLE_LIST}))
189+
self.assertHTMLEqual('', rendered)
190+
191+
def test_listgroup_linklist_is_rendered(self):
192+
rendered = self.template.render(Context({'type': 'linklist', 'items': self.SAMPLE_LINKLIST}))
193+
self.assertInHTML(
194+
self.LIST_GROUP_LINK_START
195+
+ ''.join(
196+
self.LIST_GROUP_ITEM_LINK_START
197+
+ item[0]
198+
+ self.LIST_GROUP_ITEM_LINK_END for item in self.SAMPLE_LINKLIST
199+
)
200+
+ self.LIST_GROUP_LINK_END,
201+
rendered
202+
)
203+
165204

166205
class PanelTagsTest(SimpleTestCase):
167206
SAMPLE_HEADING = 'Lorem ipsum heading'

0 commit comments

Comments
 (0)