Giter VIP home page Giter VIP logo

Comments (6)

LightGuard avatar LightGuard commented on June 8, 2024

That sounds like a great idea!

On Thu, May 9, 2013 at 4:20 AM, Alex Soto [email protected] 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

from asciidoctorj.

lordofthejars avatar lordofthejars commented on June 8, 2024

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.

from asciidoctorj.

mojavelinux avatar mojavelinux commented on June 8, 2024

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.

from asciidoctorj.

lordofthejars avatar lordofthejars commented on June 8, 2024

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?

from asciidoctorj.

lordofthejars avatar lordofthejars commented on June 8, 2024

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?

from asciidoctorj.

lordofthejars avatar lordofthejars commented on June 8, 2024

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.

from asciidoctorj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.