From 4c1bc57511ac8544600db4f06b88ce283f2fc74d Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Jul 28 2016 05:37:04 +0000 Subject: Add padding to markup view and add readme display to treeview Add a bit of padding around markup type files when displaying them in the file view. Also, when viewing a directory in the tree view, if that directory has a README in it, show the readme under the file listing on the treeview page. This will work for both the root dir and any other directory. --- diff --git a/pagure/templates/file.html b/pagure/templates/file.html index ef559f3..9478de5 100644 --- a/pagure/templates/file.html +++ b/pagure/templates/file.html @@ -122,9 +122,11 @@ {{ content | format_loc }} {% endautoescape %} {% elif output_type == 'markup' %} +
{% autoescape false %} {{ content | noJS }} {% endautoescape %} +
{% elif output_type == 'image' %} +
+ README{{readme_ext}} +
+
+ {% if safe %} + {{ readme | noJS |safe }} + {% else %} + {{ readme | noJS }} + {% endif %} +
+ + {% endif %} + {% endblock %} {% block jscripts %} diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 929ffd7..19f98ae 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -492,6 +492,10 @@ def view_file(repo, identifier, filename, username=None): flask.abort(404, 'File not found') encoding = None + readme = None + safe = False + readme_ext = None + if isinstance(content, pygit2.Blob): rawtext = str(flask.request.args.get('text')).lower() in ['1', 'true'] ext = filename[filename.rfind('.'):] @@ -532,6 +536,16 @@ def view_file(repo, identifier, filename, username=None): output_type = 'binary' else: content = sorted(content, key=lambda x: x.filemode) + for i in content: + name, ext = os.path.splitext(i.name) + if name == 'README': + readme_file = __get_file_in_tree( + repo_obj, content, [i.name]).data + + readme, safe = pagure.doc_utils.convert_readme( + readme_file, ext) + + readme_ext = ext output_type = 'tree' headers = {} @@ -551,6 +565,9 @@ def view_file(repo, identifier, filename, username=None): content=content, output_type=output_type, repo_admin=is_repo_admin(repo), + readme=readme, + readme_ext=readme_ext, + safe=safe, ), 200, headers @@ -790,6 +807,19 @@ def view_tree(repo, identifier=None, username=None): if commit: content = sorted(commit.tree, key=lambda x: x.filemode) + readme = None + safe = False + readme_ext = None + for i in commit.tree: + name, ext = os.path.splitext(i.name) + if name == 'README': + readme_file = __get_file_in_tree( + repo_obj, commit.tree, [i.name]).data + + readme, safe = pagure.doc_utils.convert_readme( + readme_file, ext) + + readme_ext = ext output_type = 'tree' return flask.render_template( @@ -805,6 +835,9 @@ def view_tree(repo, identifier=None, username=None): content=content, output_type=output_type, repo_admin=is_repo_admin(repo), + readme=readme, + readme_ext=readme_ext, + safe=safe, )