summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-06-01 20:19:51 -0400
committerJames Moger <james.moger@gitblit.com>2011-06-01 20:19:51 -0400
commita1ea877042b93949ef244b96e8affd65cc3f89c1 (patch)
treecb0fd2c37b4d4415ba1bdf74e134243bc4280fc8
parent424fe1b372d225d65eb42e6125b24cbb982c5969 (diff)
downloadgitblit-a1ea877042b93949ef244b96e8affd65cc3f89c1.tar.gz
gitblit-a1ea877042b93949ef244b96e8affd65cc3f89c1.zip
Readme markdown on summary page per-repository.
-rw-r--r--docs/00_setup.mkd1
-rw-r--r--src/com/gitblit/GitBlit.java2
-rw-r--r--src/com/gitblit/models/RepositoryModel.java1
-rw-r--r--src/com/gitblit/wicket/GitBlitWebApp.properties4
-rw-r--r--src/com/gitblit/wicket/pages/EditRepositoryPage.html7
-rw-r--r--src/com/gitblit/wicket/pages/EditRepositoryPage.java1
-rw-r--r--src/com/gitblit/wicket/pages/MarkdownPage.html2
-rw-r--r--src/com/gitblit/wicket/pages/SummaryPage.html8
-rw-r--r--src/com/gitblit/wicket/pages/SummaryPage.java43
9 files changed, 63 insertions, 6 deletions
diff --git a/docs/00_setup.mkd b/docs/00_setup.mkd
index 99fd05fc..2eddd44f 100644
--- a/docs/00_setup.mkd
+++ b/docs/00_setup.mkd
@@ -29,6 +29,7 @@ All repository settings are stored within the repository `.git/config` file unde
showRemoteBranches = false
accessRestriction = clone
isFrozen = false
+ showReadme = false
#### Repository Names
Repository names must be unique and are case-insensitive. The name must be composed of letters, digits, or `/ _ - .`<br/>
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index 52dd9dbb..c6eb613d 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -203,6 +203,7 @@ public class GitBlit implements ServletContextListener {
"accessRestriction", null));
model.showRemoteBranches = getConfig(config, "showRemoteBranches", false);
model.isFrozen = getConfig(config, "isFrozen", false);
+ model.showReadme = getConfig(config, "showReadme", false);
}
r.close();
return model;
@@ -278,6 +279,7 @@ public class GitBlit implements ServletContextListener {
repository.accessRestriction.name());
config.setBoolean("gitblit", null, "showRemoteBranches", repository.showRemoteBranches);
config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen);
+ config.setBoolean("gitblit", null, "showReadme", repository.showReadme);
try {
config.save();
} catch (IOException e) {
diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java
index afe1b5a2..97ae5184 100644
--- a/src/com/gitblit/models/RepositoryModel.java
+++ b/src/com/gitblit/models/RepositoryModel.java
@@ -35,6 +35,7 @@ public class RepositoryModel implements Serializable {
public boolean useDocs;
public AccessRestrictionType accessRestriction;
public boolean isFrozen;
+ public boolean showReadme;
public RepositoryModel() {
this("", "", "", new Date(0));
diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties
index ac45a257..16f2aa0a 100644
--- a/src/com/gitblit/wicket/GitBlitWebApp.properties
+++ b/src/com/gitblit/wicket/GitBlitWebApp.properties
@@ -89,4 +89,6 @@ gb.canAdminDescription = can administer Git:Blit server
gb.permittedUsers = permitted users
gb.isFrozen = is frozen
gb.isFrozenDescription = deny push operations
-gb.zip = zip \ No newline at end of file
+gb.zip = zip
+gb.showReadme = show readme
+gb.showReadmeDescription = show a \"readme\" markdown file on the summary page \ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/com/gitblit/wicket/pages/EditRepositoryPage.html
index 763d46fb..775a5d22 100644
--- a/src/com/gitblit/wicket/pages/EditRepositoryPage.html
+++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.html
@@ -21,10 +21,11 @@
<tr><th><wicket:message key="gb.enableTickets"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="useTickets" tabindex="4" /> &nbsp;<i><wicket:message key="gb.useTicketsDescription"></wicket:message></i></td></tr>
<tr><th><wicket:message key="gb.enableDocs"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="useDocs" tabindex="5" /> &nbsp;<i><wicket:message key="gb.useDocsDescription"></wicket:message></i></td></tr>
<tr><th><wicket:message key="gb.showRemoteBranches"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="showRemoteBranches" tabindex="6" /> &nbsp;<i><wicket:message key="gb.showRemoteBranchesDescription"></wicket:message></i></td></tr>
- <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select wicket:id="accessRestriction" tabindex="7" /></td></tr>
- <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="isFrozen" tabindex="8" /> &nbsp;<i><wicket:message key="gb.isFrozenDescription"></wicket:message></i></td></tr>
+ <tr><th><wicket:message key="gb.showReadme"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="showReadme" tabindex="7" /> &nbsp;<i><wicket:message key="gb.showReadmeDescription"></wicket:message></i></td></tr>
+ <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select wicket:id="accessRestriction" tabindex="8" /></td></tr>
+ <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="isFrozen" tabindex="9" /> &nbsp;<i><wicket:message key="gb.isFrozenDescription"></wicket:message></i></td></tr>
<tr><th style="vertical-align: top;"><wicket:message key="gb.permittedUsers"></wicket:message></th><td style="padding:2px;"><span wicket:id="users"></span></td></tr>
- <tr><th></th><td class="editButton"><input type="submit" value="Save" wicket:message="value:gb.save" tabindex="9" /></td></tr>
+ <tr><th></th><td class="editButton"><input type="submit" value="Save" wicket:message="value:gb.save" tabindex="10" /></td></tr>
</tbody>
</table>
</form>
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
index a1a42d00..eb2a8e64 100644
--- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -164,6 +164,7 @@ public class EditRepositoryPage extends BasePage {
form.add(new CheckBox("useTickets"));
form.add(new CheckBox("useDocs"));
form.add(new CheckBox("showRemoteBranches"));
+ form.add(new CheckBox("showReadme"));
form.add(usersPalette);
add(form);
diff --git a/src/com/gitblit/wicket/pages/MarkdownPage.html b/src/com/gitblit/wicket/pages/MarkdownPage.html
index b8c9cfba..a0f60904 100644
--- a/src/com/gitblit/wicket/pages/MarkdownPage.html
+++ b/src/com/gitblit/wicket/pages/MarkdownPage.html
@@ -19,7 +19,7 @@
</div>
<!-- markdown content -->
- <div class="markdown" wicket:id="markdownText">[markdown content]</div>
+ <div class="markdown" style="padding-bottom:5px;" wicket:id="markdownText">[markdown content]</div>
</wicket:extend>
</body>
</html> \ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/SummaryPage.html b/src/com/gitblit/wicket/pages/SummaryPage.html
index ed94192a..7d5629b6 100644
--- a/src/com/gitblit/wicket/pages/SummaryPage.html
+++ b/src/com/gitblit/wicket/pages/SummaryPage.html
@@ -4,6 +4,12 @@
xml:lang="en"
lang="en">
+<wicket:head>
+ <wicket:link>
+ <link href="/com/gitblit/wicket/resources/markdown.css" type="text/css" rel="stylesheet" />
+ </wicket:link>
+</wicket:head>
+
<body>
<wicket:extend>
@@ -38,6 +44,8 @@
<div wicket:id="tagsPanel">[tags panel]</div>
</div>
+ <!-- markdown readme -->
+ <div wicket:id="readme" class="markdown" style="clear:both;padding-bottom:5px;"></div>
</wicket:extend>
</body>
</html> \ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java
index f8206941..c054fcca 100644
--- a/src/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/com/gitblit/wicket/pages/SummaryPage.java
@@ -18,6 +18,7 @@ package com.gitblit.wicket.pages;
import java.awt.Color;
import java.awt.Dimension;
import java.text.MessageFormat;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@@ -27,6 +28,7 @@ import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.protocol.http.WebRequest;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.wicketstuff.googlecharts.Chart;
import org.wicketstuff.googlecharts.ChartAxis;
import org.wicketstuff.googlecharts.ChartAxisType;
@@ -42,7 +44,9 @@ import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
import com.gitblit.models.Metric;
+import com.gitblit.models.PathModel;
import com.gitblit.utils.JGitUtils;
+import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.MetricUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
@@ -140,6 +144,42 @@ public class SummaryPage extends RepositoryPage {
add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs));
add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs));
+ if (getRepositoryModel().showReadme) {
+ String htmlText = null;
+ try {
+ RevCommit head = JGitUtils.getCommit(r, null);
+ List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
+ List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
+ String readme = null;
+ for (PathModel path : paths) {
+ if (!path.isTree()) {
+ String name = path.name.toLowerCase();
+
+ if (name.startsWith("readme")) {
+ if (name.indexOf('.') > -1) {
+ String ext = name.substring(name.lastIndexOf('.') + 1);
+ if (markdownExtensions.contains(ext)) {
+ readme = path.name;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (!StringUtils.isEmpty(readme)) {
+ String markdownText = JGitUtils.getRawContentAsString(r, head, readme);
+ htmlText = MarkdownUtils.transformMarkdown(markdownText);
+ }
+ } catch (ParseException p) {
+ error(p.getMessage());
+ }
+ // Add the html to the page
+ add(new Label("readme", htmlText).setEscapeModelStrings(false).setVisible(
+ !StringUtils.isEmpty(htmlText)));
+ } else {
+ add(new Label("readme").setVisible(false));
+ }
+
// Display an activity line graph
insertActivityGraph(metrics);
}
@@ -162,7 +202,8 @@ public class SummaryPage extends RepositoryPage {
provider.addAxis(dateAxis);
ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
- commitAxis.setLabels(new String[] { "", String.valueOf((int) WicketUtils.maxValue(metrics)) });
+ commitAxis.setLabels(new String[] { "",
+ String.valueOf((int) WicketUtils.maxValue(metrics)) });
provider.addAxis(commitAxis);
provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) });