import re

from django import template

register = template.Library()


@register.filter
def humanize_route(value):
    text = str(value or "").strip()
    if not text:
        return ""
    text = text.strip("/")
    text = re.sub(r"[/_-]+", " ", text)
    text = re.sub(r"\s+", " ", text).strip()
    if not text:
        return ""
    return text.title()
