from django import template

register = template.Library()

'''
Used to format titles in the front slider boxes

>>>format_title("Script Bank")
>>>SCRIPT <b>BANK</b>

>>>format_title("Script-Bank")
>>>SCRIPT-<b>BANK</b>
'''

def format_title(value):
    v = value.strip()
    if v.find('-') != -1:
        splitter = "-"
    else:
        splitter = " "
    words = v.split(splitter)
    l = len(words)
    if l > 1:
        boldWord = "<span>" + words[l - 1] + "</span>"
        return (splitter.join(words[:l-1]) + splitter + boldWord).upper()
    else:
        return words[0].upper()

register.filter("format_title", format_title)
