Enable specifying column grid width

This commit is contained in:
Jeremy Stretch
2026-04-02 10:10:35 -04:00
parent 68bc97c24c
commit 1ccab930ef
2 changed files with 9 additions and 2 deletions

View File

@@ -58,12 +58,19 @@ class Column:
Parameters:
*panels: One or more Panel instances
width: Bootstrap grid column width (1-12). If unset, the column will expand to fill available space.
"""
def __init__(self, *panels):
def __init__(self, *panels, width=None):
for i, panel in enumerate(panels):
if not isinstance(panel, Panel):
raise TypeError(f"Panel {i} must be an instance of a Panel, not {type(panel)}.")
if width is not None:
if type(width) is not int:
raise ValueError(f"Column width must be an integer, not {type(width)}")
if width not in range(1, 13):
raise ValueError(f"Column width must be an integer between 1 and 12 (got {width}).")
self.panels = panels
self.width = width
def __iter__(self):
return iter(self.panels)

View File

@@ -127,7 +127,7 @@ Context:
{% for row in layout %}
<div class="row">
{% for column in row %}
<div class="col">
<div class="col{% if column.width %}-{{ column.width }}{% endif %}">
{% for panel in column %}
{% render panel %}
{% endfor %}