Skip to content

Commit

Permalink
Merge pull request #262 from lordofthejars/issue-258
Browse files Browse the repository at this point in the history
Add create method with classloader and gempath
  • Loading branch information
lordofthejars committed Dec 29, 2014
2 parents b55c273 + 89dde90 commit df764b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java
Expand Up @@ -708,7 +708,17 @@ public static Asciidoctor create(List<String> loadPaths) {
public static Asciidoctor create(ClassLoader classloader) {
return JRubyAsciidoctor.create(classloader);
}


/**
* Cerates a new instance of Asciidoctor and sets a specific classloader and gempath for the JRuby runtime to use.
* @param classloader
* @param gemPath
* @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
*/
public static Asciidoctor create(ClassLoader classloader, String gemPath) {
return JRubyAsciidoctor.create(classloader, gemPath);
}

}

/**
Expand Down
Expand Up @@ -99,7 +99,13 @@ public static Asciidoctor create(List<String> loadPaths) {
}

public static Asciidoctor create(ClassLoader classloader) {
Asciidoctor asciidoctor = createJRubyAsciidoctorInstance(classloader);
Asciidoctor asciidoctor = createJRubyAsciidoctorInstance(classloader, null);
registerExtensions(asciidoctor);

return asciidoctor;
}
public static Asciidoctor create(ClassLoader classloader, String gemPath) {
Asciidoctor asciidoctor = createJRubyAsciidoctorInstance(classloader, gemPath);
registerExtensions(asciidoctor);

return asciidoctor;
Expand Down Expand Up @@ -141,9 +147,13 @@ private static Asciidoctor createJRubyAsciidoctorInstance(Map<String, Object> en
return jRubyAsciidoctor;
}

private static Asciidoctor createJRubyAsciidoctorInstance(ClassLoader classloader) {
private static Asciidoctor createJRubyAsciidoctorInstance(ClassLoader classloader, String gemPath) {

Map<String, Object> env = new HashMap<String, Object>();
env.put(GEM_PATH, gemPath);

ScriptingContainer container = new ScriptingContainer();
injectEnvironmentVariables(container.getProvider().getRubyInstanceConfig(), env);
container.setClassLoader(classloader);
Ruby rubyRuntime = container.getProvider().getRuntime();

Expand Down

0 comments on commit df764b5

Please sign in to comment.