org.fusesource.scalate.jruby.JRuby.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalate-jruby_2.10 Show documentation
Show all versions of scalate-jruby_2.10 Show documentation
Scalate integration with JRuby to access Ruby based filters such as sass
The newest version!
package org.fusesource.scalate.jruby
import org.fusesource.scalate.util.Log
import java.io.{StringWriter, File}
import scala.collection
import org.jruby.RubyInstanceConfig
import org.jruby.embed.{LocalContextScope, ScriptingContainer}
import collection.JavaConverters._
/**
* A simple interface to the jruby interpreter
*/
class JRuby(loadPaths:List[File]) extends Log {
var container = new ScriptingContainer(LocalContextScope.SINGLETON)
container.getProvider.setLoadPaths(loadPaths.asJava)
container.setCompileMode(RubyInstanceConfig.CompileMode.JIT)
RubyInstanceConfig.FASTEST_COMPILE_ENABLED = true
RubyInstanceConfig.FASTSEND_COMPILE_ENABLED = true
RubyInstanceConfig.INLINE_DYNCALL_ENABLED = true
def run(scriptlet:String*):Either[(Throwable, String), AnyRef] = this.synchronized {
var errors: StringWriter = new StringWriter
try {
container.setErrorWriter(errors)
Right(container.runScriptlet(scriptlet.mkString("\n")))
} catch {
case e: Throwable =>
Left((e, errors.toString))
}
}
def put(name:String, value:AnyRef) = container.put(name, value)
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy