From 4e25cb5278566c99ce8a25bd7865d3bd1cb23adf Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 01 2015 07:29:18 +0000 Subject: Define the jinja filter and URL endpoints required to re-use the templates In order to re-use the same template as pagure, the docs server must re-define a number of endpoints, used in these templates, except that they are all just redirects to pagure itself. --- diff --git a/pagure/docs_server.py b/pagure/docs_server.py index 21f7798..7f6b180 100644 --- a/pagure/docs_server.py +++ b/pagure/docs_server.py @@ -94,8 +94,129 @@ def __get_tree_and_content(repo_obj, commit, path): return (tree, content, safe, extended) -# URLs +# Jinja filter required +@APP.template_filter('markdown') +def markdown_filter(text): + """ Template filter converting a string into html content using the + markdown library. + """ + return pagure.lib.text2markdown(text, extended=False) + + +# Placeholder to allow re-using pagure's templates +@APP.route('/') +def index(): + return flask.redirect(APP.config['APP_URL']) + + +@APP.route('/users/') +def view_users(): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect(root_url + '/users/') + + +@APP.route('/groups/') +def group_lists(): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect(root_url + '/groups/') + + +@APP.route('/new/') +def new_project(): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect(root_url + '/new/') + + +@APP.route('/repo//') +@APP.route('/repo/fork///') +def view_repo(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + flask.url_for('.view_docs', repo=repo, username=username)) + + +@APP.route('//issues/') +@APP.route('/fork///issues/') +def view_issues(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + + flask.url_for('.view_docs', repo=repo, username=username) + + 'issues/') + + +@APP.route('//commits/') +@APP.route('/fork///commits/') +def view_commits(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + + flask.url_for('.view_docs', repo=repo, username=username) + + 'commits/') + + +@APP.route('//tree/') +@APP.route('/fork///tree/') +def view_tree(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + + flask.url_for('.view_docs', repo=repo, username=username) + + 'tree/') + + +@APP.route('//tags/') +@APP.route('/fork///tags/') +def view_tags(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + + flask.url_for('.view_docs', repo=repo, username=username) + + 'tags/') + + +@APP.route('//pull-requests/') +@APP.route('/fork///pull-requests/') +def request_pulls(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + + flask.url_for('.view_docs', repo=repo, username=username) + + 'pull-requests/') + + +@APP.route('//forks/') +@APP.route('/fork///forks/') +def view_forks(repo, username=None): + root_url = APP.config['APP_URL'] + if root_url.endswith('/'): + root_url = root_url[:-1] + return flask.redirect( + root_url + + flask.url_for('.view_docs', repo=repo, username=username) + + 'forks/') + + +# The actual logic of the doc server @APP.route('//') @APP.route('/')