Permalink
Browse files

add GithubLinkRenderer and rename package util to helper

  • Loading branch information...
1 parent 3e9e285 commit 1f71c55db66d56deda82657c3ced66cc24ed9062 @garbagetown garbagetown committed Jun 3, 2012
@@ -1,21 +1,19 @@
package controllers;
import static org.apache.commons.lang.StringUtils.isEmpty;
+import helper.*;
import java.io.*;
import java.util.*;
-import java.util.regex.*;
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
import org.pegdown.*;
-import org.pegdown.ast.*;
import play.*;
import play.libs.*;
import play.mvc.*;
-import util.*;
/**
* Documentation controller.
@@ -69,26 +67,9 @@ public static void page(String version, String id) {
} else {
String docroot = String.format("documentation/%s/", version);
String parent = page.getParent();
- final String path = page.getParent().substring(parent.indexOf(docroot) + docroot.length());
+ String path = parent.substring(parent.indexOf(docroot) + docroot.length());
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL);
- html = processor.markdownToHtml(content, new LinkRenderer() {
- @Override
- public Rendering render(WikiLinkNode node) {
- String text = node.getText();
- String href = "";
- if (text.contains("|")) {
- String[] parts = text.split(Pattern.quote("|"));
- text = parts[0].trim();
- href = parts[1].trim();
- } else if (text.endsWith(".png")) {
- href = String.format("resources/%s/%s", path, text);
- text = String.format("<img src=%s>", href);
- } else {
- href = text;
- }
- return new LinkRenderer.Rendering(href, text);
- }
- });
+ html = processor.markdownToHtml(content, new GithubLinkRenderer(path));
}
Document doc = Jsoup.parse(html);
@@ -1,5 +1,7 @@
package controllers;
+import helper.*;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -17,7 +19,6 @@
import play.libs.IO;
import play.mvc.Controller;
import play.utils.Properties;
-import util.Textile;
public class Modules extends Controller {
@@ -0,0 +1,41 @@
+package helper;
+
+import java.util.regex.*;
+
+import org.pegdown.*;
+import org.pegdown.ast.*;
+
+/**
+ *
+ * @author garbagetown
+ *
+ */
+public class GithubLinkRenderer extends LinkRenderer {
+
+ private String path;
+
+ /**
+ *
+ * @param path
+ */
+ public GithubLinkRenderer(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public Rendering render(WikiLinkNode node) {
+ String text = node.getText();
+ String href = "";
+ if (text.contains("|")) {
+ String[] parts = text.split(Pattern.quote("|"));
+ text = parts[0].trim();
+ href = parts[1].trim();
+ } else if (text.endsWith(".png")) {
+ href = String.format("resources/%s/%s", path, text);
+ text = String.format("<img src=%s>", href);
+ } else {
+ href = text;
+ }
+ return new LinkRenderer.Rendering(href, text);
+ }
+}
@@ -1,4 +1,4 @@
-package util;
+package helper;
public class StringUtils {
@@ -1,14 +1,14 @@
-package util;
-
-import jj.play.org.eclipse.mylyn.wikitext.core.parser.*;
-import jj.play.org.eclipse.mylyn.wikitext.textile.core.*;
-
-public class Textile {
-
- public static String toHTML(String textile) {
- String html = new MarkupParser(new TextileLanguage()).parseToHtml(textile);
- html = html.substring(html.indexOf("<body>") + 6, html.lastIndexOf("</body>"));
- return html;
- }
-
-}
+package helper;
+
+import jj.play.org.eclipse.mylyn.wikitext.core.parser.*;
+import jj.play.org.eclipse.mylyn.wikitext.textile.core.*;
+
+public class Textile {
+
+ public static String toHTML(String textile) {
+ String html = new MarkupParser(new TextileLanguage()).parseToHtml(textile);
+ html = html.substring(html.indexOf("<body>") + 6, html.lastIndexOf("</body>"));
+ return html;
+ }
+
+}
View
@@ -1,8 +1,9 @@
package models;
+import helper.*;
+
import java.util.*;
-import util.*;
public class Module implements Comparable<Module> {
@@ -1,8 +1,9 @@
-package util;
+package helper;
+
+import helper.*;
import org.junit.Test;
import play.test.UnitTest;
-import util.*;
public class StringUtilsTest extends UnitTest {

0 comments on commit 1f71c55

Please sign in to comment.