]> source.dussan.org Git - gitblit.git/commitdiff
Mostly complete blob view line links feature, DOM offset bug remains (issue 130)
authorJames Moger <james.moger@gitblit.com>
Fri, 14 Sep 2012 21:51:04 +0000 (17:51 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 14 Sep 2012 21:51:04 +0000 (17:51 -0400)
docs/04_releases.mkd
resources/gitblit.css
src/com/gitblit/wicket/pages/BlobPage.java

index 2ea0e23d18b60e12973b59c1bdeaf6260130a094..07a1fb31423a48fd5eb7fc54e08c7af5c5a7d793 100644 (file)
@@ -16,6 +16,7 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 #### additions\r
 \r
+- added line links to blob view at the expense of zebra striping (issue 130)\r
 - added RedmineUserService (github/mallowlabs)\r
 \r
 #### changes\r
index 7a73a24cf16b0646b7f0da77ccddec8a80e34281..861fc41170922631932ce1f71e8424722e123684 100644 (file)
@@ -145,6 +145,7 @@ pre, code, pre.prettyprint, pre.plainprint {
        border:0px;\r
        padding: 0;\r
        line-height: 1.35em;\r
+       vertical-align:top;\r
 }\r
 \r
 table {\r
@@ -161,10 +162,32 @@ th {
        text-align: left;       \r
 }\r
 \r
+div.sourceview {\r
+       overflow: auto;\r
+}\r
 pre.prettyprint ol {\r
        padding-left:25px;\r
 }\r
 \r
+#nums {\r
+    text-align: right;\r
+    padding-right:10px;\r
+    border-right:1px solid #ddd;\r
+    font-family: monospace;\r
+    line-height: 1.35em;\r
+    vertical-align:top;\r
+}\r
+\r
+#nums pre {\r
+    white-space: pre;\r
+}\r
+\r
+#lines pre {\r
+       padding: 0px 5px !important;\r
+       border: 0px !important;\r
+       white-space: nowrap;\r
+}\r
+\r
 h1 small, h2 small, h3 small, h4 small, h5 small, h6 small {\r
     color: #888;\r
 }\r
index e2683ae14f4a3b7511126bde1f67ccb71e2b8029..f1d802d4ee6b3a8fd66819dc5cef90a79d353365 100644 (file)
@@ -15,6 +15,7 @@
  */\r
 package com.gitblit.wicket.pages;\r
 \r
+import java.text.MessageFormat;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
@@ -109,45 +110,118 @@ public class BlobPage extends RepositoryPage {
                                if (map.containsKey(extension)) {\r
                                        type = map.get(extension);\r
                                }\r
-                               Component c = null;\r
-                               Component i = null;\r
                                switch (type) {\r
-                               case 1:\r
-                                       // PrettyPrint blob text\r
-                                       c = new Label("blobText", JGitUtils.getStringContent(r, commit.getTree(),\r
-                                                       blobPath, encodings));\r
-                                       WicketUtils.setCssClass(c, "prettyprint linenums");\r
-                                       i = new Image("blobImage").setVisible(false);\r
-                                       break;\r
                                case 2:\r
                                        // image blobs\r
-                                       c = new Label("blobText").setVisible(false);\r
-                                       i = new ExternalImage("blobImage", urlFor(RawPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)).toString());\r
+                                       add(new Label("blobText").setVisible(false));\r
+                                       add(new ExternalImage("blobImage", urlFor(RawPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)).toString()));\r
                                        break;\r
                                case 3:\r
                                        // binary blobs\r
-                                       c = new Label("blobText", "Binary File");\r
-                                       i = new Image("blobImage").setVisible(false);\r
+                                       add(new Label("blobText", "Binary File"));\r
+                                       add(new Image("blobImage").setVisible(false));\r
                                        break;\r
                                default:\r
                                        // plain text\r
-                                       c = new Label("blobText", JGitUtils.getStringContent(r, commit.getTree(),\r
-                                                       blobPath, encodings));\r
-                                       WicketUtils.setCssClass(c, "plainprint");\r
-                                       i = new Image("blobImage").setVisible(false);\r
+                                       String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings);\r
+                                       String table = generateSourceView(source, type == 1);\r
+                                       add(new Label("blobText", table).setEscapeModelStrings(false));\r
+                                       add(new Image("blobImage").setVisible(false));\r
                                }\r
-                               add(c);\r
-                               add(i);\r
                        } else {\r
                                // plain text\r
-                               Label blobLabel = new Label("blobText", JGitUtils.getStringContent(r,\r
-                                               commit.getTree(), blobPath, encodings));\r
-                               WicketUtils.setCssClass(blobLabel, "plainprint");\r
-                               add(blobLabel);\r
+                               String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings);\r
+                               String table = generateSourceTable(source, false);\r
+                               add(new Label("blobText", table).setEscapeModelStrings(false));\r
                                add(new Image("blobImage").setVisible(false));\r
                        }\r
                }\r
        }\r
+       \r
+       protected String generateSourceView(String source, boolean prettyPrint) {\r
+               String [] lines = source.split("\n");\r
+               \r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("<!-- start blob table -->");\r
+               sb.append("<table width=\"100%\"><tbody><tr>");\r
+               \r
+               // nums column\r
+               sb.append("<!-- start nums column -->");\r
+               sb.append("<td id=\"nums\">");\r
+               sb.append("<pre>");\r
+               String numPattern = "<a id=\"L{0}\" href=\"#L{0}\">{0}</a>\n";\r
+               for (int i = 0; i < lines.length; i++) {\r
+                       sb.append(MessageFormat.format(numPattern, "" + (i + 1)));\r
+               }\r
+               sb.append("</pre>");\r
+               sb.append("<!-- end nums column -->");\r
+               sb.append("</td>");\r
+               \r
+               sb.append("<!-- start lines column -->");\r
+               sb.append("<td id=\"lines\">");\r
+               sb.append("<div class=\"sourceview\">");\r
+               if (prettyPrint) {\r
+                       sb.append("<pre class=\"prettyprint\">");\r
+               } else {\r
+                       sb.append("<pre class=\"plainprint\">");\r
+               }\r
+               sb.append(StringUtils.escapeForHtml(source, true));\r
+               sb.append("</pre>");\r
+               sb.append("</div>");\r
+               sb.append("</td>");\r
+               sb.append("<!-- end lines column -->");\r
+               \r
+               sb.append("</tr></tbody></table>");\r
+               sb.append("<!-- end blob table -->");\r
+               \r
+               return sb.toString();\r
+       }\r
+       \r
+       protected String generateSourceTable(String source, boolean prettyPrint) {\r
+               String [] lines = source.split("\n");\r
+               \r
+               // be careful adding line breaks to this method\r
+               // GoogleCode Prettify is sensitive\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("<!-- start blob table -->");\r
+               sb.append("<table width=\"100%\"><tbody><tr>");\r
+               \r
+               // nums column\r
+               sb.append("<!-- start nums column -->");\r
+               sb.append("<td id=\"nums\">");\r
+               sb.append("<pre><table width=\"100%\"><tbody>");\r
+               String numPattern = "<tr><td id=\"L{0}\"><a href=\"#L{0}\">{0}</a></td></tr>";\r
+               for (int i = 0; i < lines.length; i++) {\r
+                       sb.append(MessageFormat.format(numPattern, "" + (i + 1)));\r
+               }\r
+               sb.append("<!-- end nums column -->");\r
+               sb.append("</tbody></table></pre>");\r
+               sb.append("</td>");\r
+               \r
+               sb.append("<!-- start lines column -->");\r
+               sb.append("<td id=\"lines\">");\r
+               if (prettyPrint) {\r
+                       sb.append("<pre style=\"border: 0px;\" class=\"prettyprint\">");\r
+               } else {\r
+                       sb.append("<pre class=\"plainprint\">");\r
+               }\r
+               sb.append("<table width=\"100%\"><tbody>");\r
+               \r
+               String linePattern = "<tr class=\"{0}\"><td>{1}</tr>";\r
+               for (int i = 0; i < lines.length; i++) {\r
+                       String l = StringUtils.escapeForHtml(lines[i], true);\r
+                       String cssClass = (i % 2 == 0) ? "even" : "odd";\r
+                       sb.append(MessageFormat.format(linePattern, cssClass, l));\r
+               }\r
+               sb.append("</tbody></table></pre>");\r
+               sb.append("</td>");\r
+               sb.append("<!-- end lines column -->");\r
+               \r
+               sb.append("</tr></tbody></table>");\r
+               sb.append("<!-- end blob table -->");\r
+               \r
+               return sb.toString();\r
+       }\r
 \r
        @Override\r
        protected String getPageName() {\r