Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload specified Ruby libraries #32

Closed
lordofthejars opened this issue May 9, 2013 · 6 comments
Closed

Preload specified Ruby libraries #32

lordofthejars opened this issue May 9, 2013 · 6 comments
Milestone

Comments

@lordofthejars
Copy link
Member

the Asciidoctor Java integration could preload specified libraries when it boots JRuby, removing the possibility of any problems or warnings.

Related with Issue

@LightGuard
Copy link
Member

That sounds like a great idea!

On Thu, May 9, 2013 at 4:20 AM, Alex Soto notifications@github.com wrote:

the Asciidoctor Java integration could preload specified libraries when it
boots JRuby, removing the possibility of any problems or warnings.

Related with Issue rmannibucau/JeBlog#1


Reply to this email directly or view it on GitHubhttps://github.com//issues/32
.

Jason Porter
http://en.gravatar.com/lightguardjp

@lordofthejars
Copy link
Member Author

Yes I think so, another thing to research, briefly with @ajuckel we will have OSGI integration (Which maybe also fixes the problem with AS 7). Also I am working with copycss problem, and then it will be the time for preloading libraries. Of course if you have any idea feel free to write it here.

@mojavelinux
Copy link
Member

I think that preloading libraries should work perhaps like the ruby cli. If you run ruby -h, you'll see:

-rlibrary       require the library before executing your script

This option can be passed multiple times. Therefore, it's reasonable for the Asciidoctor Factory method (or something similar) accept an array of library names to load. For now, we can assume these libraries are available on the Ruby LOAD_PATH and thus a simple string name will do.

We could do some smart preloading:

  • if the source-highlighter option is set to coderay, we could automatically add 'coderay' to the preload list
  • If the eruby option is set to erubis, we could automatically add erubis to the preload list
  • If the template_dir option is specified, we could automatically add tilt to the preload list (and maybe 'slim' and 'haml')
  • If the data-uri attribute is specified, we could automatically add base64 to the preload list

These should take care of most of the use cases for needing to preload a library at the moment.

@lordofthejars
Copy link
Member Author

I have been thinking about this issue and it comes to possible implementations:

  • give the opportunity to users to pass as array of strings the libraries to preload from create method. The problem is that every time you change something you would require a new Asciidoctor instance. But we could provide a set method but you are passing the knowledge of which libraries should be loaded to users.
  • a dynamic way, which asciidoctor-java-integration itself reads the options and execute a require operation for the required library.

something like:

if(libraryIsNotPreloadedYet("libraryName")) {
    evaler.eval(runtime, "require 'libraryName'");
}

Of course if you render two files if the second one does not require libraryName, that library would be already preloaded, but I think this is not a problem. Note that runtime instance is always the same so once the libraries are preloaded, they will be there until Ruby instance become eligible for GC.

What you think?

@lordofthejars
Copy link
Member Author

I have been researching something more about how to preload libraries, it seems that defineModule method can do that work too instead of calling a Ruby script like:

if(libraryIsNotPreloadedYet("libraryName")) {
    evaler.eval(runtime, "require 'libraryName'");
}

The problem is that I am not pretty sure that defineModule approach would support defining them dynamically, because at construction time I create a RubyObject (Asciidoctor) from an script and this object is reused for all future executions. So I guess it is not possible to preload libraries for that object dynamically because it is already instantiated. Maybe as first version we can give the option to user to create Asciidoctor class with static preloaded libraries, and in future we can create a refreshable method which re-instantiates a new Asciidcotor instance with the new libraries. The good news is that I think it won't affect the performance because Ruby environment will be the same so it is already initialized.

What you think?

@lordofthejars
Copy link
Member Author

sorry defineModule cannot be used for preloading libraries because it is used for defining the module structure, not for loading them, you still need to call require anyway, defineMethod is used for calling Java from JRuby. So maybe the first approach is the best one.

aalmiray added a commit to hackergarten/asciidoctorj that referenced this issue Feb 26, 2015
resolves asciidoctor#31 support attributes as String, List and Array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants