Skip to content

Commit

Permalink
Add a "tabbed_templates_html" method (for use in EFSP interview for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
nonprofittechy committed Sep 18, 2021
1 parent 744c58e commit 30db333
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docassemble/ALToolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.2.0'
27 changes: 26 additions & 1 deletion docassemble/ALToolbox/misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import docassemble.base.functions
from docassemble.base.util import defined, value, showifdef
from docassemble.base.util import defined, value, showifdef, space_to_underscore
import re

class shortenMe:
Expand Down Expand Up @@ -85,3 +85,28 @@ def collapse_template(template, classname=None):
<div class="collapse" id="{}"><div class="card card-body{} pb-1">{}</div></div>\
""".format(the_id, template.subject_as_html(trim=True), the_id, classname, template.content_as_html())

def tabbed_templates_html(tab_group_name:str, *pargs)->str:
"""
Provided a list of templates, create Bootstrap v 4.5 tabs with the `subject` as the tab label.
"""
if isinstance(tab_group_name, str):
tab_group_name = space_to_underscore(tab_group_name)
else:
tab_group_name = "tabbed-group"
tabs = f'<ul class="nav nav-tabs" id="{tab_group_name}" role="tablist">\n'
tab_content = '<div class="tab-content" id="myTabContent">'
for index, templ in enumerate(pargs):
tab_id = space_to_underscore(str(templ.subject))
tabs += '<li class="nav-item" role="presentation">\n'
if index == 0:
tabs += f'<a class="nav-link active" id="{tab_group_name}-{tab_id}-tab" data-toggle="tab" href="#{tab_group_name}-{tab_id}" role="tab" aria-controls="{tab_id}" aria-selected="true">{templ.subject}</a>\n'
tab_content += f'<div class="tab-pane fade show active" id="{tab_group_name}-{tab_id}" role="tabpanel" aria-labelledby="{tab_group_name}-{tab_id}-tab">{templ.content}</div>\n'
else:
tabs += f'<a class="nav-link" id="{tab_group_name}-{tab_id}-tab" data-toggle="tab" href="#{tab_group_name}-{tab_id}" role="tab" aria-controls="{tab_id}" aria-selected="false">{templ.subject}</a>\n'
tab_content += f'<div class="tab-pane fade" id="{tab_group_name}-{tab_id}" role="tabpanel" aria-labelledby="{tab_group_name}-{tab_id}-tab">{templ.content}</div>\n'
tabs += '</li>'
tabs += '</ul>'
tab_content += '</div>'

return tabs + tab_content

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
return out

setup(name='docassemble.ALToolbox',
version='0.1.0',
version='0.2.0',
description=('A docassemble extension.'),
long_description='This project is used to host custom-built modules, js files etc. The purpose is to provide a toolbox so that other coders can call these code in their interview.\r\n\r\nIf you want to add a small fuction to this project, consider adding it to the existing misc.py to avoid creating too many module files.\r\n\r\n--------------------------\r\nContributors: \r\n* @plocket \r\n* @nonprofittechy\r\n* @purplesky2016\r\n',
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 30db333

Please sign in to comment.