|
From: <caw...@us...> - 2007-05-29 13:14:40
|
Revision: 2544
http://svn.sourceforge.net/rubyeclipse/?rev=2544&view=rev
Author: cawilliams
Date: 2007-05-29 06:14:39 -0700 (Tue, 29 May 2007)
Log Message:
-----------
call out to JRuby to format the comments into RDoc HTML using the actual RDoc library. Now we can provide accurate HTML versions of comments/docs inside the editor hovers and proposals
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java 2007-05-29 13:13:35 UTC (rev 2543)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java 2007-05-29 13:14:39 UTC (rev 2544)
@@ -1,15 +1,27 @@
package org.rubypeople.rdt.core.util;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
import java.util.Collection;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.jruby.Ruby;
import org.jruby.ast.CommentNode;
+import org.jruby.exceptions.RaiseException;
import org.jruby.lexer.yacc.ISourcePosition;
+import org.jruby.runtime.builtin.IRubyObject;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
public class RDocUtil {
+ private static Ruby fgRuby;
+ private static String fgRdocScriptPath;
+
private RDocUtil() {}
public static String getDocumentation(IRubyElement element) {
@@ -19,6 +31,10 @@
return "";
}
+ public static String getHTMLDocumentation(IRubyElement element) {
+ return getHTMLDocumentation(getDocumentation(element));
+ }
+
private static String getContents(IMember member) {
String src = "";
int elementOffset = -1;
@@ -90,4 +106,41 @@
private static String removePrecedingHashes(String comment) {
return comment.trim().substring(1);
}
+
+ public static String getHTMLDocumentation(String docs) {
+ if (docs == null) return null;
+ String script = "require 'rdoc/markup/simple_markup'\n" +
+ "require 'rdoc/markup/simple_markup/to_html'\n" +
+ "p = SM::SimpleMarkup.new\n" +
+ "h = SM::ToHtml.new\n" +
+ "input_string =<<EOF\n" + docs + "\nEOF\n" +
+ "p.convert(input_string, h)\n";
+ Ruby ruby = getJRubyInstance();
+ try {
+ ruby.setCurrentDirectory(getRDocScriptPath());
+ IRubyObject object = ruby.evalScript(script);
+ docs = object.toString();
+ } catch (IOException e) {
+ // ignore
+ } catch (RaiseException e) {
+ e.printStackTrace();
+ }
+ return docs;
+ }
+
+ private static Ruby getJRubyInstance() {
+ if (fgRuby == null)
+ fgRuby = Ruby.getDefaultInstance();
+ return fgRuby;
+ }
+
+ private static String getRDocScriptPath() throws IOException {
+ if (fgRdocScriptPath == null) {
+ URL installURL = new URL(RubyCore.getPlugin().getBundle().getEntry("/"),new Path("ruby").toString()); //$NON-NLS-1$
+ URL localURL = FileLocator.toFileURL(installURL);
+ File file = new File(localURL.getFile());
+ fgRdocScriptPath = file.getAbsolutePath();
+ }
+ return fgRdocScriptPath;
+ }
}
Added: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java (rev 0)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java 2007-05-29 13:14:39 UTC (rev 2544)
@@ -0,0 +1,33 @@
+package org.rubypeople.rdt.core.tests.util;
+
+import org.rubypeople.rdt.core.util.RDocUtil;
+
+import junit.framework.TestCase;
+
+public class RDocUtiltest extends TestCase {
+
+ public void testHTML() throws Exception {
+ String input = " List entries look like:\n" +
+ " * text\n" +
+ " 1. text\n" +
+ " [label] text\n" +
+ " label:: text\n" +
+ "\n" +
+ " Flag it as a list entry, and\n" +
+ " work out the indent for subsequent lines";
+ String html = RDocUtil.getHTMLDocumentation(input);
+ String expected = "<p>\n" +
+ "List entries look like:\n" +
+ "</p>\n" +
+ "<pre>\n" +
+ " * text\n" +
+ " 1. text\n" +
+ " [label] text\n" +
+ " label:: text\n" +
+ "</pre>\n" +
+ "<p>\n" +
+ "Flag it as a list entry, and work out the indent for subsequent lines\n" +
+ "</p>\n";
+ assertEquals(expected, html);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|