pnbp

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit c9049b37bb0e0763f3c74d8fc1f78d30b3d0959d
parent bcfc664caf431a87303e6c86447af3081c882a7f
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Thu May 22 12:51:09 2014

addex inline scripts

Diffstat:
 compile.py            | 36 +++++++++++++++++++++++++++++++++++-
 data/styles/style.css |  4 ++++
 includes/header.html  |  1 -
 templates/std.html    | 11 +++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/compile.py b/compile.py @@ -31,6 +31,9 @@ def generateTemplate(t,var,page): page = "" t = t.replace("%page%",page) + + t = runInlineScript(t,page) + for search,replace in var.items(): if search[0] == ":": try: @@ -59,6 +62,24 @@ def runMod(t,var,page): return subpage +def runInlineScript(template,page): + try: + index = template.index("{:")+2 + exists = True + except: + exists = False + + if exists: + script = "" + while template[index:index+2] != ":}": + script = script + template[index] + index += 1 + returns = "" + exec script + template = template.replace(template[template.index("{:"):template.index(":}")+2],returns) + + return template + # Builds the site off of a filestructure dictionary. def buildSite(site): @@ -86,7 +107,20 @@ def buildSite(site): open(currentDir+"/"+subdir+"/"+page+"/index.html","w").write(content) else: open(currentDir+"/"+subdir+"/index.html", "w").write(data['default']) - + copytree("data/styles","site/styles") + copytree("data/images","site/images") + +def copytree(src, dst, symlinks=False, ignore=None): + if not os.path.exists(dst): + os.makedirs(dst) + for item in os.listdir(src): + s = os.path.join(src, item) + d = os.path.join(dst, item) + if os.path.isdir(s): + copytree(s, d, symlinks, ignore) + else: + if not os.path.exists(d) or os.stat(src).st_mtime - os.stat(dst).st_mtime > 1: + shutil.copy2(s, d) if __name__ == "__main__": print("Going through pages...") diff --git a/data/styles/style.css b/data/styles/style.css @@ -0,0 +1,4 @@ +body, div { + width:900px; + margin:0 auto; +}+ \ No newline at end of file diff --git a/includes/header.html b/includes/header.html @@ -1,5 +1,4 @@ <div> <h1>This is in fact not a blog. %page%</h1> - <a href="/">Home</a>&nbsp;<a href="/test/">Test</a><br/> <a href="/%page%/all">all</a> </div> diff --git a/templates/std.html b/templates/std.html @@ -1,9 +1,20 @@ +<!DOCTYPE html> <html> <head> <title>%title%</title> + <link rel="stylesheet" type="text/css" href="/styles/style.css" /> </head> <body> %:header% + {: +for i,x in pagedata.items(): + l = i + if i == "index": + i = "" + i = "/"+i + + returns = returns + "<a href=\"{}\">{}</a>&nbsp;".format(i, l) + :} <div> %content% </div>