Asciidoctor.js and Docbook?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Asciidoctor.js and Docbook?

mcasperson
Does Asciidoctor.js support output to DocBook? I tried this, but it doesn't work:

        var asciidocOpts = Opal.hash2(['attributes'], {'backend': ['docbook']});
       
        document.body.innerHTML = Opal.Asciidoctor.$render(
          "http://asciidoctor.org[*Asciidoctor*] " +
          "running on http://opalrb.org[_Opal_] " +
          "brings AsciiDoc to the browser!",
          asciidocOpts
        )
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

LightGuardjp
I think it should, unless it's been stripped out. It's in core and all of core, to my understanding, is part of the cross compilation to javascript.


On Thu, Apr 24, 2014 at 7:42 PM, mcasperson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Does Asciidoctor.js support output to DocBook? I tried this, but it doesn't work:

        var asciidocOpts = Opal.hash2(['attributes'], {'backend': ['docbook']});
       
        document.body.innerHTML = Opal.Asciidoctor.$render(
          "http://asciidoctor.org[*Asciidoctor*] " +
          "running on http://opalrb.org[_Opal_] " +
          "brings AsciiDoc to the browser!",
          asciidocOpts
        )


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Docbook-tp1698.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

mcasperson
I managed to get it working. I am not familiar with Ruby, Opal or AsciiDoctor, but I'll post the changes here in case they help anyone else. The code here is referencing asciidoctor 1.5.0.preview.1.

This code needs to go at the end of asciidoctor.rb. This works around the fact that dynamic requires are not supported by Opal.

  # backends
  if ::RUBY_ENGINE_OPAL
    require 'asciidoctor/backends/html5-erb'
    require 'asciidoctor/backends/docbook45'
    require 'asciidoctor/backends/docbook5'
  end

In renderer.rb, replace the code in initialize() with this. It removes the early return which prevents the docbook views from being processed.

backend = options[:backend]
    if ::RUBY_ENGINE_OPAL && backend == 'html5'
      ::Template.instance_variable_get('@_cache').each do |path, tmpl|
        @views[(File.basename path)] = tmpl
      end
    else
      case backend
      when 'html5', 'docbook45', 'docbook5'
        eruby = load_eruby options[:eruby]
        require 'asciidoctor/backends/base_template'
        #require "asciidoctor/backends/#{backend}"
        # Load up all the template classes that we know how to render for this backend
        BaseTemplate.template_classes.each do |tc|
          if tc.to_s.downcase.include?('::' + backend + '::') # optimization
            view_name, view_backend = self.class.extract_view_mapping(tc)
            if view_backend == backend
              @views[view_name] = tc.new(view_name, backend, eruby)
            end
          end
        end
      else
        Debug.debug { "No built-in templates for backend: #{backend}" }
      end
    end

Also in renderer.rb,  replace the render() method with this. I don't really know why converting to Docbook uses views without underscores in the name, but this hack works.

# Public: Render an Asciidoc object with a specified view template.
  #
  # view   - the String view template name.
  # object - the Object to be used as an evaluation scope.
  # locals - the optional Hash of locals to be passed to Tilt (default {}) (also ignored, really)
  def render(view, object, locals = {})
   
  fixed_view = view.sub("_", "");
 
  if !@views.has_key? view
      if !@views.has_key? fixed_view
      raise "Couldn't find a view in @views for #{view}"
      else
      view = fixed_view
      end
    end
   
    if @chomp_result
      @views[view].render(object, locals).chomp
    else
      @views[view].render(object, locals)
    end
  end

With these changes, the following script will convert Asciidoc to Docbook and print the result to the console.

<html>
  <head>
    <script src="opal.js"></script>    <script src="asciidoctor.js"></script>    <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>    <script> jQuery(document).ready(function() { var asciidocOpts = Opal.hash2(['attributes'], {'backend': 'docbook5'}); console.log(Opal.Asciidoctor.$render( "http://asciidoctor.org[*Asciidoctor*] " + "running on http://opalrb.org[_Opal_] " + "brings AsciiDoc to the browser!", asciidocOpts )); }); </script>  </head>
  <body>
   
  </body>
</html>
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

mcasperson
I've uploaded the two files that were modified.

https://www.dropbox.com/s/zop8ilwuouvku3x/asciidoctor.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/)
https://www.dropbox.com/s/e2w32pgx518dud3/renderer.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/asciidoctor/)
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

LightGuardjp
Would you mind forking Asciidoctorjs, updating the Gemfile to 1.5.0.preview4, and opal 0.6.2 (which should both be the latest) and see if your change is still needed?


On Fri, Apr 25, 2014 at 12:27 AM, mcasperson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I've uploaded the two files that were modified.

https://www.dropbox.com/s/zop8ilwuouvku3x/asciidoctor.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/)
https://www.dropbox.com/s/e2w32pgx518dud3/renderer.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/asciidoctor/)


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Docbook-tp1698p1703.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

LightGuardjp
In reply to this post by mcasperson
I just tried, looks like the current asciidoctor 1.5.0.preview4 requires some tweaking to be able to convert to js:

```
Cannot handle dynamic require :asciidoctor:51
Cannot handle dynamic require :asciidoctor:52
Cannot handle dynamic require :asciidoctor:53
Cannot handle dynamic require :asciidoctor:55
Cannot handle dynamic require :asciidoctor/core_ext:6
Cannot handle dynamic require :asciidoctor/helpers:19
Cannot handle dynamic require :asciidoctor/converter/factory:47
Cannot handle dynamic require :asciidoctor/converter/factory:178
Cannot handle dynamic require :asciidoctor/converter/factory:183
Cannot handle dynamic require :asciidoctor/converter/factory:188
Cannot handle dynamic require :asciidoctor/converter/factory:196
Cannot handle dynamic require :asciidoctor/converter/factory:199
```

Dan, Guillaume, any thoughts?


On Fri, Apr 25, 2014 at 12:39 AM, Jason Porter <[hidden email]> wrote:
Would you mind forking Asciidoctorjs, updating the Gemfile to 1.5.0.preview4, and opal 0.6.2 (which should both be the latest) and see if your change is still needed?


On Fri, Apr 25, 2014 at 12:27 AM, mcasperson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I've uploaded the two files that were modified.

https://www.dropbox.com/s/zop8ilwuouvku3x/asciidoctor.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/)
https://www.dropbox.com/s/e2w32pgx518dud3/renderer.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/asciidoctor/)


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Docbook-tp1698p1703.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML






--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

mcasperson
In reply to this post by mcasperson
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

mcasperson
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

LightGuardjp
Nice, very cool.


On Fri, Apr 25, 2014 at 4:39 PM, mcasperson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Here is a demo using preview 4:

https://googledrive.com/host/0B6cpJDiEKC62cndwWkNmNmVqbE0/test.html


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Docbook-tp1698p1707.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Docbook?

mojavelinux
Administrator
In reply to this post by LightGuardjp
Asciidoctor.js 1.5.0 supports DocBook output by default now. See the README for more info:


-Dan

On Fri, Apr 25, 2014 at 1:50 AM, LightGuardjp [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I just tried, looks like the current asciidoctor 1.5.0.preview4 requires some tweaking to be able to convert to js:

```
Cannot handle dynamic require :asciidoctor:51
Cannot handle dynamic require :asciidoctor:52
Cannot handle dynamic require :asciidoctor:53
Cannot handle dynamic require :asciidoctor:55
Cannot handle dynamic require :asciidoctor/core_ext:6
Cannot handle dynamic require :asciidoctor/helpers:19
Cannot handle dynamic require :asciidoctor/converter/factory:47
Cannot handle dynamic require :asciidoctor/converter/factory:178
Cannot handle dynamic require :asciidoctor/converter/factory:183
Cannot handle dynamic require :asciidoctor/converter/factory:188
Cannot handle dynamic require :asciidoctor/converter/factory:196
Cannot handle dynamic require :asciidoctor/converter/factory:199
```

Dan, Guillaume, any thoughts?


On Fri, Apr 25, 2014 at 12:39 AM, Jason Porter <[hidden email]> wrote:
Would you mind forking Asciidoctorjs, updating the Gemfile to 1.5.0.preview4, and opal 0.6.2 (which should both be the latest) and see if your change is still needed?


On Fri, Apr 25, 2014 at 12:27 AM, mcasperson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I've uploaded the two files that were modified.

https://www.dropbox.com/s/zop8ilwuouvku3x/asciidoctor.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/)
https://www.dropbox.com/s/e2w32pgx518dud3/renderer.rb (goes in ~/.gem/ruby/gems/asciidoctor-1.5.0.preview.1/lib/asciidoctor/)


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Docbook-tp1698p1703.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML






--



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Docbook-tp1698p1706.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--