Mercurial > hg-website
changeset 144:4a8b12498bdf
Added the tag "mercurial_tricks_advanced", so we can distinguish between basic tricks (no extensions required) and advanced tricks (including history rewriting, mq and similar).
author | Arne Babenhauserheide <bab@draketo.de> |
---|---|
date | Tue, 12 May 2009 06:30:18 +0200 |
parents | fc5a9f3e5479 |
children | fa0ed1574400 |
files | hgscm/apps/www/templatetags/extras.py hgscm/settings.py |
diffstat | 2 files changed, 23 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/hgscm/apps/www/templatetags/extras.py Tue May 12 06:20:17 2009 +0200 +++ b/hgscm/apps/www/templatetags/extras.py Tue May 12 06:30:18 2009 +0200 @@ -11,12 +11,26 @@ self._filename = self._random() def _random(self): - file = random.choice(os.listdir(settings.MERCURIAL_TRICKS)) - return os.path.join(settings.MERCURIAL_TRICKS, file) + p = random.choice(os.listdir(settings.MERCURIAL_TRICKS)) + return os.path.join(settings.MERCURIAL_TRICKS, p) def render(self, context): f = open(self._filename) - result = "<p><h3>Tricks</h3>" + f.read() + "</p>" + result = "<p><h3>Basic Tricks</h3>" + f.read() + "</p>" + f.close() + return result + +class MercurialTricksAdvancedNode(template.Node): + def __init__(self): + self._filename = self._random() + + def _random(self): + p = random.choice(os.listdir(settings.MERCURIAL_TRICKS_ADVANCED)) + return os.path.join(settings.MERCURIAL_TRICKS_ADVANCED, p) + + def render(self, context): + f = open(self._filename) + result = "<p><h3>Advanced Tricks</h3>" + f.read() + "</p>" f.close() return result @@ -40,9 +54,13 @@ def do_mercurial_tricks (parser, token): return MercurialTricksNode() +def do_mercurial_tricks_advanced (parser, token): + return MercurialTricksAdvancedNode() + def do_download_button(parser, token): extended = len(token.split_contents()) > 1 return DownloadButtonNode(extended) register.tag('mercurial_tricks', do_mercurial_tricks) +register.tag('mercurial_tricks_advanced', do_mercurial_tricks_advanced) register.tag('download_button', do_download_button)
--- a/hgscm/settings.py Tue May 12 06:20:17 2009 +0200 +++ b/hgscm/settings.py Tue May 12 06:30:18 2009 +0200 @@ -69,6 +69,8 @@ MERCURIAL_TRICKS = os.path.join(BASE_DIR, "templates/tricks") +MERCURIAL_TRICKS_ADVANCED = os.path.join(BASE_DIR, "templates/tricks_advanced") + TEMPLATE_DIRS = ( os.path.join(BASE_DIR, "templates"), )