From e131717b489b5527e2b9853eaae8ad71ca6ea748 Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 14 Nov 2013 18:16:57 -0500 Subject: [PATCH] Display common repository documents as tabs on the docs page Change-Id: I6935fa45598da847936748b474a3da47e94efaac --- releases.moxie | 2 + .../com/gitblit/wicket/MarkupProcessor.java | 88 ++++++++++++--- .../com/gitblit/wicket/pages/DocPage.html | 4 +- .../com/gitblit/wicket/pages/DocPage.java | 5 +- .../com/gitblit/wicket/pages/DocsPage.html | 21 ++-- .../com/gitblit/wicket/pages/DocsPage.java | 103 ++++++++++++------ .../com/gitblit/wicket/pages/SummaryPage.java | 2 +- src/main/resources/gitblit.css | 69 ++++++++++-- 8 files changed, 220 insertions(+), 74 deletions(-) diff --git a/releases.moxie b/releases.moxie index 73a10a6f..75d3f1a5 100644 --- a/releases.moxie +++ b/releases.moxie @@ -43,6 +43,7 @@ r20: { - Added setting to globally disable anonymous pushes in the receive pack - Added a normalized diffstat display to the commit, commitdiff, and compare pages - Added GO setting to automatically redirect all http requests to the secure https connector + - Automatically display common repository root documents as tabs on the docs page dependencyChanges: - updated to Jetty 7.6.13 - updated to JGit 3.1.0 @@ -55,6 +56,7 @@ r20: { - { name: 'git.defaultAccessRestriction', defaultValue: 'PUSH' } - { name: 'git.mirrorPeriod', defaultValue: '30 mins' } - { name: 'web.commitMessageRenderer', defaultValue: 'plain' } + - { name: 'web.documents', defaultValue: 'readme home index changelog contributing submitting_patches copying license notice authors' } - { name: 'web.showBranchGraph', defaultValue: 'true' } - { name: 'web.summaryShowReadme', defaultValue: 'false' } - { name: 'server.redirectToHttpsPort', defaultValue: 'true' } diff --git a/src/main/java/com/gitblit/wicket/MarkupProcessor.java b/src/main/java/com/gitblit/wicket/MarkupProcessor.java index 4324f805..1a5f553f 100644 --- a/src/main/java/com/gitblit/wicket/MarkupProcessor.java +++ b/src/main/java/com/gitblit/wicket/MarkupProcessor.java @@ -21,7 +21,10 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.wicket.Page; import org.apache.wicket.RequestCycle; @@ -82,6 +85,21 @@ public class MarkupProcessor { return list; } + public List getAllExtensions() { + List list = getMarkupExtensions(); + list.add("txt"); + list.add("TXT"); + return list; + } + + private List getRoots() { + return settings.getStrings(Keys.web.documents); + } + + private String [] getEncodings() { + return settings.getStrings(Keys.web.blobEncodings).toArray(new String[0]); + } + private MarkupSyntax determineSyntax(String documentPath) { String ext = StringUtils.getFileExtension(documentPath).toLowerCase(); if (StringUtils.isEmpty(ext)) { @@ -105,33 +123,67 @@ public class MarkupProcessor { return MarkupSyntax.PLAIN; } - public MarkupDocument parseReadme(Repository r, String repositoryName, String commitId) { - String readme = null; - RevCommit commit = JGitUtils.getCommit(r, commitId); - List paths = JGitUtils.getFilesInPath(r, null, commit); + public boolean hasRootDocs(Repository r) { + List roots = getRoots(); + List extensions = getAllExtensions(); + List paths = JGitUtils.getFilesInPath(r, null, null); for (PathModel path : paths) { if (!path.isTree()) { - String name = path.name.toLowerCase(); - if (name.equals("readme") || name.equals("readme.txt")) { - readme = path.name; - break; - } else if (name.startsWith("readme.")) { - String ext = StringUtils.getFileExtension(name).toLowerCase(); - if (getMarkupExtensions().contains(ext)) { - readme = path.name; - break; + String ext = StringUtils.getFileExtension(path.name).toLowerCase(); + String name = StringUtils.stripFileExtension(path.name).toLowerCase(); + + if (roots.contains(name)) { + if (StringUtils.isEmpty(ext) || extensions.contains(ext)) { + return true; } } } } + return false; + } - if (!StringUtils.isEmpty(readme)) { - String [] encodings = settings.getStrings(Keys.web.blobEncodings).toArray(new String[0]); - String markup = JGitUtils.getStringContent(r, commit.getTree(), readme, encodings); - return parse(repositoryName, commitId, readme, markup); + public List getRootDocs(Repository r, String repositoryName, String commitId) { + List roots = getRoots(); + List list = getDocs(r, repositoryName, commitId, roots); + return list; + } + + public MarkupDocument getReadme(Repository r, String repositoryName, String commitId) { + List list = getDocs(r, repositoryName, commitId, Arrays.asList("readme")); + if (list.isEmpty()) { + return null; } + return list.get(0); + } - return null; + private List getDocs(Repository r, String repositoryName, String commitId, List names) { + List extensions = getAllExtensions(); + String [] encodings = getEncodings(); + Map map = new HashMap(); + RevCommit commit = JGitUtils.getCommit(r, commitId); + List paths = JGitUtils.getFilesInPath(r, null, commit); + for (PathModel path : paths) { + if (!path.isTree()) { + String ext = StringUtils.getFileExtension(path.name).toLowerCase(); + String name = StringUtils.stripFileExtension(path.name).toLowerCase(); + + if (names.contains(name)) { + if (StringUtils.isEmpty(ext) || extensions.contains(ext)) { + String markup = JGitUtils.getStringContent(r, commit.getTree(), path.name, encodings); + MarkupDocument doc = parse(repositoryName, commitId, path.name, markup); + map.put(name, doc); + } + } + } + } + // return document list in requested order + List list = new ArrayList(); + for (String name : names) { + if (map.containsKey(name)) { + list.add(map.get(name)); + } + } + return list; } public MarkupDocument parse(String repositoryName, String commitId, String documentPath, String markupText) { diff --git a/src/main/java/com/gitblit/wicket/pages/DocPage.html b/src/main/java/com/gitblit/wicket/pages/DocPage.html index beb8e4dc..a484a648 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocPage.html +++ b/src/main/java/com/gitblit/wicket/pages/DocPage.html @@ -7,8 +7,8 @@ -