Skip to content

Commit

Permalink
Remove custom container classname
Browse files Browse the repository at this point in the history
  • Loading branch information
plocket committed Jul 6, 2023
1 parent bdc8886 commit dc2e512
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ subquestion: |
Don't you have a favorite fruit?
${ collapse_template(favorite_explanation, container_classname="favorites_container") }
${ collapse_template(favorite_explanation) }
You must have a favorite.
fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ subquestion: |
- This feature applies the **copy_button_html()** function to template content. See [copy button demo](${interview_url(i=user_info().package + ":copy_button_demo.yml")}).
1. **classname** (default="bg-light")
- To style your template content, include a `classname` keyword argument when you call the function and add your css rules either on the screen or to a .css file.
1. **container_classname** (default=None)
- To style the whole container of your subject and content, include a `content_classname` keyword argument when you call the function and add your css rules either on the screen or to a .css file.
You can mix and match these features. The following screens will show you how.
Expand All @@ -46,7 +44,7 @@ question: |
Scrollable examples
subquestion: |
##### Srollable only
${ display_template(my_template1, container_classname="my_class") }
${ display_template(my_template1) }
##### Style only
${ display_template(my_template2, scrollable=False, classname="my_color") }
Expand Down
13 changes: 5 additions & 8 deletions docassemble/ALToolbox/display_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def display_template(
collapse=False,
copy=False,
classname="bg-light",
container_classname=None,
class_name=None # depricated
) -> str:
# 1. Initialize
Expand All @@ -27,9 +26,7 @@ def display_template(
class_name = classname
class_name = class_name.strip()

container_classname_plus = "al_display_template"
if container_classname:
container_classname_plus += f" { container_classname }"
container_classname = "al_display_template"

container_id = b64encode(str(template.instanceName).encode()).decode().replace('=', '')
contents_id = f"{ container_id }_contents"
Expand All @@ -50,12 +47,12 @@ def display_template(

# 2.1 If collapsible, add collapsible elements to the output
if collapse:
return f'<div id="{container_id}" class="{container_classname_plus}"><a class="collapsed" data-bs-toggle="collapse" href="#{contents_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="toggle-icon pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="toggle-icon pdcaretclosed"><i class="fas fa-caret-right"></i></span><span class="subject">{template.subject_as_html(trim=True)}</span></a><div class="collapse" id="{contents_id}">{contents}</div></div>'
return f'<div id="{container_id}" class="{container_classname}"><a class="collapsed" data-bs-toggle="collapse" href="#{contents_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="toggle-icon pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="toggle-icon pdcaretclosed"><i class="fas fa-caret-right"></i></span><span class="subject">{template.subject_as_html(trim=True)}</span></a><div class="collapse" id="{contents_id}">{contents}</div></div>'

# 2.2 If not collapsible, simply return output from copy_button_html()
else:
return f"""
<div id="{container_id}" class="{container_classname_plus}">
<div id="{container_id}" class="{container_classname}">
{subject_html}
{contents}
</div>
Expand All @@ -64,7 +61,7 @@ def display_template(
# 3. If not copiable, generate the whole output
else:
if collapse:
return f'<div id="{container_id}" class="{container_classname_plus}"><a class="collapsed" data-bs-toggle="collapse" href="#{contents_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="toggle-icon pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="toggle-icon pdcaretclosed"><i class="fas fa-caret-right"></i></span><span class="subject">{template.subject_as_html(trim=True)}</span></a><div class="collapse" id="{contents_id}"><div class="{scroll_class} card card-body {class_name} pb-1">{template.content_as_html()}</div></div></div>'
return f'<div id="{container_id}" class="{container_classname}"><a class="collapsed" data-bs-toggle="collapse" href="#{contents_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="toggle-icon pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="toggle-icon pdcaretclosed"><i class="fas fa-caret-right"></i></span><span class="subject">{template.subject_as_html(trim=True)}</span></a><div class="collapse" id="{contents_id}"><div class="{scroll_class} card card-body {class_name} pb-1">{template.content_as_html()}</div></div></div>'

else:
return f'<div id="{container_id}" class="{container_classname_plus} {scroll_class} card card-body {class_name} pb-1" id="{contents_id}">{subject_html}<div>{template.content_as_html()}</div></div>'
return f'<div id="{container_id}" class="{container_classname} {scroll_class} card card-body {class_name} pb-1" id="{contents_id}">{subject_html}<div>{template.content_as_html()}</div></div>'
7 changes: 2 additions & 5 deletions docassemble/ALToolbox/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def number_to_letter(n: Optional[int]) -> str:
def collapse_template(
template,
classname=None,
container_classname=None,
closed_icon="caret-right",
open_icon="caret-down",
):
Expand All @@ -181,15 +180,13 @@ def collapse_template(
classname = " bg-light"
else:
classname = " " + classname.strip()
container_classes_plus = "al_collapse_template"
if container_classname:
container_classes_plus += f" { container_classname }"
container_classnames = "al_collapse_template"

container_id = b64encode(str(template.instanceName).encode()).decode().replace('=', '')
contents_id = f'{ container_id }_contents'

return f"""\
<div id="{ container_id }" class="{ container_classes_plus }">
<div id="{ container_id }" class="{ container_classnames }">
<a class="collapsed al_toggle" data-bs-toggle="collapse" href="#{ contents_id }" role="button" aria-expanded="false" aria-controls="{ contents_id }"><span class="toggle-icon pdcaretopen">{ fa_icon(open_icon) }</span><span class="toggle-icon pdcaretclosed">{ fa_icon(closed_icon) }</span>
<span class="subject">{ template.subject_as_html(trim=True) }</span></a>
<div class="collapse" id="{ contents_id }">
Expand Down

0 comments on commit dc2e512

Please sign in to comment.