Skip to content

Commit

Permalink
Track highest versions of algorithms encountered
Browse files Browse the repository at this point in the history
Redirect pages are created that point from a page using the plain name to the highest version page
Refs #9521
  • Loading branch information
martyngigg committed May 27, 2014
1 parent 72808a0 commit a082fb2
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions Code/Mantid/docs/sphinxext/mantiddoc/directives/algorithm.py
Expand Up @@ -17,6 +17,7 @@ def run(self):
Called by Sphinx when the ..algorithm:: directive is encountered
"""
algorithm_name, version = self._algorithm_name_and_version()
self._track_algorithm(algorithm_name, version)

# Seperate methods for each unique piece of functionality.
reference = self._make_reference_link(algorithm_name)
Expand All @@ -27,6 +28,26 @@ def run(self):

return self._insert_rest(reference + title + screenshot + toc)

def _track_algorithm(self, name, version):
"""
Keep a track of the highest versions of algorithms encountered
Arguments:
name (str): Name of the algorithm
version (int): Integer version number
"""
env = self.state.document.settings.env
if not hasattr(env, "algorithm"):
env.algorithms = {}
#endif
algorithms = env.algorithms
if name in algorithms:
prev_version = algorithms[name][1]
if version > prev_version:
algorithms[name][1] = version
else:
algorithms[name] = (name, version)

def _make_reference_link(self, algorithm_name):
"""
Outputs a reference to the top of the algorithm's rst
Expand Down Expand Up @@ -118,11 +139,18 @@ def html_collect_pages(app):
"""
Write out unversioned algorithm pages that redirect to the highest version of the algorithm
"""
name = "algorithms/Rebin"
context = {"name" : "Rebin", "target" : "Rebin-v1.html"}
env = app.builder.env
if not hasattr(env, "algorithms"):
return # nothing to do

template = REDIRECT_TEMPLATE

return [(name, context, template)]
algorithms = env.algorithms
for name, highest_version in algorithms.itervalues():
redirect_pagename = "algorithms/%s" % name
target = "%s-v%d.html" % (name, highest_version)
context = {"name" : name, "target" : target}
yield (redirect_pagename, context, template)

############################################################################################################

Expand Down

0 comments on commit a082fb2

Please sign in to comment.