コード例 #1
0
ファイル: Processor.java プロジェクト: nawroth/asciidoctorj
 private Block createBlock(AbstractBlock parent, String context, Map<String, Object> options) {
   IRubyObject rubyClass = rubyRuntime.evalScriptlet("Asciidoctor::Block");
   RubyHash convertMapToRubyHashWithSymbols =
       RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
   Object[] parameters = {
     parent.delegate(), RubyUtils.toSymbol(rubyRuntime, context), convertMapToRubyHashWithSymbols
   };
   return (Block)
       JavaEmbedUtils.invokeMethod(rubyRuntime, rubyClass, "new", parameters, Block.class);
 }
コード例 #2
0
  @Test
  public void shouldWrapJavaIOExceptions() throws Exception {
    Ruby ruby = Ruby.newInstance();
    RackInput rackInput = mock(RackInput.class);
    when(rackInput.read(null)).thenThrow(new IOException("fake"));

    JRubyRackInput subject = new JRubyRackInput(ruby, rackInput);
    GlobalVariables globalVariables = ruby.getGlobalVariables();
    globalVariables.set("$rack_input", subject);

    IRubyObject result =
        ruby.evalScriptlet(
            "begin; $rack_input.read; rescue IOError => e; \"rescued #{e.message}\"; end");
    assertThat(result.asJavaString()).isEqualTo("rescued fake");
  }
コード例 #3
0
  public static Ruby createRuby() throws Exception {
    RubyRuntimeFactoryImpl factory = new RubyRuntimeFactoryImpl();

    if (System.getProperty("gem.path") != null) {
      factory.setGemPath(System.getProperty("gem.path"));
    } else {
      factory.setGemPath("target/rubygems");
    }
    System.err.println("gem.path is " + factory.getGemPath());
    factory.setUseJRubyHomeEnvVar(false);

    Ruby ruby = factory.create();

    ruby.evalScriptlet("require %q(rubygems)");
    return ruby;
  }
コード例 #4
0
ファイル: ErbScriptEngine.java プロジェクト: JEBailey/sling
  public ErbScriptEngine(ErbScriptEngineFactory factory) {
    super(factory);

    final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
      runtime = Ruby.newInstance();
      runtime.evalScriptlet(
          "require 'java';require 'erb';self.send :include, ERB::Util;class ERB;def get_binding;binding;end;attr_reader :props;def set_props(p);@props = p;"
              + "for name,v in @props;instance_eval \"def #{name}; @props['#{name}'];end\";end;end;end;");

      erbModule = runtime.getClassFromPath("ERB");
      bindingSym = RubySymbol.newSymbol(runtime, "get_binding");
    } finally {
      Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
  }
コード例 #5
0
ファイル: Processor.java プロジェクト: nawroth/asciidoctorj
  public Inline createInline(
      AbstractBlock parent,
      String context,
      String text,
      Map<String, Object> attributes,
      Map<String, Object> options) {

    options.put(Options.ATTRIBUTES, attributes);

    IRubyObject rubyClass = rubyRuntime.evalScriptlet("Asciidoctor::Inline");
    RubyHash convertMapToRubyHashWithSymbols =
        RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
    Object[] parameters = {
      parent.delegate(),
      RubyUtils.toSymbol(rubyRuntime, context),
      text,
      convertMapToRubyHashWithSymbols
    };
    return (Inline)
        JavaEmbedUtils.invokeMethod(rubyRuntime, rubyClass, "new", parameters, Inline.class);
  }
コード例 #6
0
 private void javaImport(Ruby ruby, String className) {
   ruby.evalScriptlet(String.format("java_import '%s'", className));
 }
コード例 #7
0
 private void javaImport(Ruby ruby, Class<?> clazz) {
   ruby.evalScriptlet(String.format("java_import '%s'", getImportLine(clazz)));
 }