pnbp

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

commit f153a48ea678fde8034b48f788a6d0280e883426
parent a93d2bc2807be390d878f4bb6fbe65622c838fb3
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Fri Aug 15 16:04:20 2014

added --init option

Diffstat:
 example/pages.yml          | 49 +++++++++++++++++++++++------------------------
 example/templates/std.html |  1 +-
 src/build.py               | 27 +++++++++++++++++++-------
 src/initbasic.py           |  8 ++++++++-
 4 files changed, 53 insertions(+), 32 deletions(-)

diff --git a/example/pages.yml b/example/pages.yml @@ -1,25 +1,24 @@ ---- - index: - template: "templates/std.html" - pagevar: - :header: "./includes/header.html" - title: "pnbp- Home" - pagemod: - content: - mod: "blog" - settings: - defaultPostCount: "1" - data: "./data/index.json" - postTemplate: "./templates/homepost.html" - docs: - template: "templates/std.html" - pagevar: - :header: "./includes/header.html" - title: "pnbp- Documentation" - pagemod: - content: - mod: "blog" - settings: - description: 1 - defaultPostCount: "0" - data: "./data/docs.json" +index: + template: "templates/std.html" + pagevar: + :header: "./includes/header.html" + title: "pnbp- Home" + pagemod: + content: + mod: "blog" + settings: + defaultPostCount: "1" + data: "./data/index.json" + postTemplate: "./templates/homepost.html" +docs: + template: "templates/std.html" + pagevar: + :header: "./includes/header.html" + title: "pnbp- Documentation" + pagemod: + content: + mod: "blog" + settings: + description: 1 + defaultPostCount: "0" + data: "./data/docs.json" diff --git a/example/templates/std.html b/example/templates/std.html @@ -10,6 +10,7 @@ %content% </div> <div> + <hr /> This site was last generated on {:returns = now("%D"):} </div> </body> diff --git a/src/build.py b/src/build.py @@ -9,7 +9,7 @@ #Core imports import os, sys, shutil,json, yaml, time, traceback #Helper imports -import module +import module, initbasic from functions import * # Adds in variables defined in pages.json @@ -207,6 +207,7 @@ def main(): except: print("{}: Can't open file '{}'".format(name,v['template'])) sys.exit() + if 'pagevar' in v: template = generateTemplate(template,v['pagevar'],name) else: @@ -214,13 +215,25 @@ def main(): site[name] = runMod(template,v,name) + buildSite(site,buildDir) + +if __name__ == "__main__": + buildDir = "site/" + init = False + if len(sys.argv) > 1: - buildSite(site,sys.argv[1]) - else: - buildSite(site,"site/") + for i in sys.argv: + if i[0] != "-" and i != sys.argv[0]: + buildDir = i + elif i == "--init": + init = True + else: + print("Unknown option: {}".format(i)) + + if init: + initbasic.init() -if __name__ == "__main__": print("Going through pages...") start = time.time() try: @@ -237,12 +250,12 @@ if __name__ == "__main__": except Exception,e: if type(e) == KeyError: print("Missing or mistyped value: {}".format(e)) - traceback.print_exc(file=sys.stdout) else: print("Something went wrong...") print(e) - + + traceback.print_exc(file=sys.stdout) sys.exit() print("Finished in {} ms.".format((time.time()-start)*1000)) diff --git a/src/initbasic.py b/src/initbasic.py @@ -0,0 +1,8 @@ +basicConfig = "index:\n template: \"template.html\"\n pagevar:\n title: \"I'm basic\"\n pagemod:\n page:\n mod: \"page\"" +basicTemplate = "<html>\n <body>\n <h1>%title%</h1>\n </body>\n</html>" + +def init(): + file("pages.yml","w").write(basicConfig) + file("template.html","w").write(basicTemplate) + +