-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplace.py
36 lines (24 loc) · 809 Bytes
/
replace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import unicode_literals
import re
ALPHA_NUM = 'alphanumeric'
TITLIFY = 'title'
SLUGIFY = 'slugify'
WRAP = 'wrap'
CLASSIFY = 'class'
def alpha_num(text):
"""Remove non alphanumeric characters from the text."""
return re.sub(r'[^a-zA-Z0-9]', '', text)
def slugify(text):
"""Prepare string for use as a URL."""
slug = re.sub(r'[^a-z0-9]', '-', text.lower())
return re.sub(r'[-]+', '-', slug).strip('-')
def title(text):
"""Convert to title case."""
return text.title()
def classify(text):
"""Convert string to classname style."""
class_name = text.title()
return re.sub(r'[^a-zA-Z0-9]', '', class_name)
def wrap(text, open_tag, close_tag):
"""Wrap the text in tags... or anything really."""
return ''.join((open_tag, text, close_tag, ))