pnbp

a terrible but reliable site builder
Log | Files | Refs | README

functions.py (1161B)


      1 '''
      2 '  pnbp - pnbp is not a blogging platform
      3 '  functions.py
      4 '  Paul Longtine - paullongtine@gmail.com
      5 '
      6 '  For documentation, please visit http://static.nanner.co/pnbp
      7 '''
      8 # Functions file, used for inline scripts
      9 import time, yaml
     10 
     11 
     12 #Return the current date in the format sepecified in config
     13 def now(config):
     14 	return time.strftime(config)
     15 
     16 #Return an HTML list. example format: 
     17 # {'root':"<ul class=\"special\">%li%</ul>",'li':"<li class=\"list\">%content%</li>"}
     18 def list(things,formats={}):
     19 	formats['root'] = formats.get("root","<ul>%li%</ul>")
     20 	formats['li'] = formats.get("li","<li>%content%</li>")
     21 	li = ""
     22 	for thing in things:
     23 		li = li + formats['li'].replace("%content%",thing)
     24 
     25 	return formats['root'].replace("%li%",li)
     26 
     27 # slug(string -> "hi's") -> his- removes all "unwanted" characters and creates a URL-friendly slug
     28 def slug(string):
     29 	invalidChars = [
     30 		"<",">","#","%","{","}",
     31 		"|","\\","^","[","]","`",
     32 		"'",";","/","?",":","@",
     33 		"&","+",",","."
     34 		]
     35 	for x in invalidChars:
     36 		string = string.replace(x, "")
     37 
     38 	string = string.replace(" ","_")
     39 	return string.lower()
     40 
     41 #Returns config
     42 def getConf():
     43 	return yaml.load(file("pages.yml"))