29 lines
551 B
Python
29 lines
551 B
Python
import random
|
|
from typing import Any
|
|
|
|
from jinja2 import Environment
|
|
|
|
|
|
def conditional_cls(conditions: dict[str, Any]) -> str:
|
|
result = []
|
|
for cls, condition in conditions.items():
|
|
if condition:
|
|
result.append(cls)
|
|
return " ".join(result)
|
|
|
|
|
|
def random_id() -> str:
|
|
return f"_{random.randint(0, 10**8)}"
|
|
|
|
|
|
def environment(**options):
|
|
env = Environment(**options)
|
|
|
|
env.globals.update(
|
|
{
|
|
"conditional_cls": conditional_cls,
|
|
"random_id": random_id,
|
|
}
|
|
)
|
|
return env
|