Skip to content

Instantly share code, notes, and snippets.

@spullara
Created January 16, 2011 00:37
Show Gist options
  • Save spullara/781418 to your computer and use it in GitHub Desktop.
Save spullara/781418 to your computer and use it in GitHub Desktop.
package mustachelet;
import com.google.common.base.Function;
import com.sampullara.mustache.Mustache;
import com.sampullara.mustache.Scope;
import scala.collection.JavaConversions;
import scala.runtime.AbstractFunction1;
/**
* Scala iterables and functions in mustache.
* <p/>
* User: sam
* Date: 1/15/11
* Time: 4:14 PM
*/
public abstract class ScalaMustache extends Mustache {
@Override
protected Object getValue(Scope s, String name) {
final Object value = super.getValue(s, name);
if (value instanceof scala.collection.Iterable) {
return JavaConversions.asJavaIterable((scala.collection.Iterable<Object>) value);
} else if (value instanceof AbstractFunction1) {
return new Function<Object, Object>() {
public Object apply(Object input) {
return ((AbstractFunction1) value).apply(input);
}
};
}
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment