Further work on making JMustache work in GWT.

I've ironed out most of the kinks, but the GWT unit test still fails because
we're forced to do some sneaky things with java.io.Reader/Writer. I think it
will all work when compiled to JavaScript, so I need to check it in a real
project.
This commit is contained in:
Michael Bayne
2011-10-29 15:31:27 -07:00
parent f9319ce911
commit 407d999836
9 changed files with 143 additions and 3 deletions
@@ -0,0 +1,5 @@
<!-- defines our GWT module -->
<module>
<source path="mustache"/>
<super-source path="gwt"/>
</module>
@@ -17,8 +17,10 @@ public class DefaultCollector extends BasicCollector
if (iter != null) return iter;
if (value.getClass().isArray()) {
return Arrays.asList((Object[])value);
return Arrays.asList((Object[])value).iterator();
}
return null;
}
// TODO: override createFetcher and do some magic for JavaScript/JSON objects
}
@@ -0,0 +1,12 @@
//
// $Id$
package java.io;
/**
* A minimal version of {@code Reader} to satisfy GWT.
*/
public interface Reader
{
int read () throws IOException;
}
@@ -0,0 +1,21 @@
//
// $Id$
package java.io;
/**
* A basic implementation of {@code StringReader} for use in GWT.
*/
public class StringReader implements Reader
{
public StringReader (String data) {
_data = data;
}
public int read () throws IOException {
return (_pos >= _data.length()) ? -1 : _data.charAt(_pos++);
}
protected final String _data;
protected int _pos;
}
@@ -0,0 +1,20 @@
//
// $Id$
package java.io;
/**
* A basic implementation of {@code StringReader} for use in GWT.
*/
public class StringWriter implements Writer
{
public void write (String text) throws IOException {
_buf.append(text);
}
@Override public String toString () {
return _buf.toString();
}
protected final StringBuilder _buf = new StringBuilder();
}
@@ -0,0 +1,12 @@
//
// $Id$
package java.io;
/**
* A minimal version of {@code Writer} to satisfy GWT.
*/
public interface Writer
{
void write (String text) throws IOException;
}