Created
January 16, 2011 00:37
-
-
Save spullara/781418 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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