Search code examples
rubyhtmlgradleasciidoctor

Asciidoctor::HTML5::DocumentTemplate replacement


I have no experience with Asciidoctor, Ruby or gradle. I've been put in charge of a project developed by someone else which uses all 3 of this. In the code is the function Asciidoctor::HTML5::DocumentTemplate which throws an error

We recently upgraded to Asciidoctor 1.5.0 and when trying to compile this project it throws the following error messages:

16:25:53.429 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.jruby.exceptions.RaiseException: (NameError) uninitialized constant Asciidoctor::HTML5
16:25:53.429 [ERROR] [org.gradle.BuildExceptionReporter] at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:2689)
16:25:53.430 [ERROR] [org.gradle.BuildExceptionReporter] at RUBY.__singleton__(/tmp/document.html.erb:108)

Line 108 is : <%= ::Asciidoctor::HTML5::DocumentTemplate.outline(self, (attr :toclevels, 2).to_i) %>

From what I can see, it populates the table of content from a file with titles with a ## tag in front of them.

What do I do from here?


Solution

  • Your document.html.erb is probably based on asciidoctor-v0.1.4/erb/html5/document.html.erb. That one works for asciidoctor 0.1.4, but not for 1.5. A version that works with 1.5 can be found here: master/erb/html5/document.html.erb.

    Between these two versions, the line

    <%= ::Asciidoctor::HTML5::DocumentTemplate.outline(self, (attr :toclevels, 2).to_i) %>
    

    is replaced with

    <%= converter.convert self, 'outline' %>
    

    Changing that line in my copy of document.html.erb resolved the error for me.