factored out write overview into writeoverview()
diff --git a/static.py b/static.py
--- a/static.py
+++ b/static.py
@@ -14,7 +14,7 @@ without the interactivity).
__plan__ = """
* Create the static-dir in the repo:
- - Overview: Readme + commits + template
+ - Overview: Readme + commits + template ✔
- Changes: Commit-Log + each commit as changeset/<hex>
- source: a filetree, shown as sourcecode: src/<path> and raw/<path>
- if b is used: a bugtracker: issue/<id>/<name>
@@ -65,6 +65,36 @@ def parsereadme(filepath):
return "<pre>" + r.read() + "</pre>"
+def writeoverview(ui, repo, target, name):
+ """Create the overview page"""
+ overview = open(join(target, "index.html"), "w")
+ overview.write(templates["head"].replace("REPO_NAME", name))
+ # add a short identifier from the first line of the readme, if it
+ # exists # TODO: Parse different types of readme files
+ readme = name
+ for f in os.listdir(repo.root):
+ if f.lower().startswith("readme"):
+ readme = parsereadme(f)
+ overview.write( "\n".join(readme.splitlines()[:3]))
+ break
+ # now add the 5 most recent log entries
+ # divert all following ui output to a string, so we can just use standard functions
+ overview.write("<h2>Changes</h2>")
+ ui.pushbuffer()
+ t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False)
+ t.use_template("""<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='commits/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags}</span><p>{desc|escape}</p>""")
+ for c in range(1, min(len(repo.changelog), 5)):
+ ctx = repo.changectx(str(-c))
+ t.show(ctx)
+ overview.write(ui.popbuffer())
+
+ # add the full readme
+ overview.write("<h2>Readme</h2>")
+ overview.write(readme)
+
+ # finish the overview
+ overview.write(templates["foot"])
+
def parsesite(ui, repo, target, **opts):
"""Create the static folder."""
idfile = join(target, _staticidentifier)
@@ -98,33 +128,7 @@ def parsesite(ui, repo, target, **opts):
f.write(templates["printstyle"])
# then the overview
- overview = open(join(target, "index.html"), "w")
- overview.write(templates["head"].replace("REPO_NAME", name))
- # add a short identifier from the first line of the readme, if it
- # exists # TODO: Parse different types of readme files
- readme = name
- for f in os.listdir(repo.root):
- if f.lower().startswith("readme"):
- readme = parsereadme(f)
- overview.write( "\n".join(readme.splitlines()[:3]))
- break
- # now add the 5 most recent log entries
- # divert all following ui output to a string, so we can just use standard functions
- overview.write("<h2>Changes</h2>")
- ui.pushbuffer()
- t = cmdutil.changeset_templater(ui, repo, False, None, None, False)
- t.use_template("""<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='commits/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags}</span><p>{desc|escape}</p>""")
- for c in range(1, max(len(repo.changelog), 5)):
- ctx = repo.changectx(str(-c))
- t.show(ctx)
- overview.write(ui.popbuffer())
-
- # add the full readme
- overview.write("<h2>Readme</h2>")
- overview.write(readme)
-
- # finish the overview
- overview.write(templates["foot"])
+ writeoverview(ui, repo, target, name)
def addrepo(ui, repo, target):
"""Add the repo to the target and make sure it is up to date."""
@@ -133,7 +137,9 @@ def addrepo(ui, repo, target):
except mercurial.error.RepoError, e:
# already exists
pass
+ ui.pushbuffer()
commands.push(ui, repo, dest=target)
+ ui.popbuffer()
def static(ui, repo, target=None, **opts):