/ Published in: Java
Almost the same as my snippet for groovy, but for jruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
buffer.setMode("ruby"); buffers = jEdit.getBuffers(); for(i = 0; i < buffers.length; i++) { jrc = buffers[i].getProperty("JRubyContainer"); if(jrc != null) { break; } } if(jrc == null) { return name.endsWith(".jar"); } }; cl = this.getClass().getClassLoader(); for(i = 0; i < libfiles.length; i++) jrc = new org.jruby.embed.ScriptingContainer(); jrc.setClassLoader(cl); } for(i = 0; i < buffers.length; i++) { buffers[i].setProperty("JRubyContainer", jrc); } outbuffer = buffer.getProperty("outbuffer"); if((outbuffer == null) || outbuffer.isClosed()) { outbuffer = jEdit.newFile(view); buffer.setProperty("outbuffer", outbuffer); } jrc.setWriter(out); view.showBuffer(buffer); res = textArea.getSelectedText(); if(res == null || res.length() == 0) { res = buffer.getText(); } return res; } text = text(); jrc.remove("DATA"); ma = java.util.regex.Pattern.compile("(?sm)\\A(.+)^__END__$(.*)\\z").matcher(text); if(ma.matches()) { text = ma.group(1); jrc.put("DATA", ma.group(2)); } result = jrc.runScriptlet(new java.io.ByteArrayInputStream(("# -*- encoding : utf-8 -*-\n\n" + text).getBytes("UTF-8")), "(eval)"); outbuffer.remove(0, outbuffer.getLength()); outbuffer.insert(0, out.toString()); if(result != null) { outbuffer.insert(outbuffer.getLength(),"\n\tResult: " + result); view.showBuffer(outbuffer); }