Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5 posts
|
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 ) |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
354 posts
|
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: ... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5 posts
|
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> |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5 posts
|
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/) |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
354 posts
|
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. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
354 posts
|
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:
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5 posts
|
In reply to this post by mcasperson
With these changes I managed to get the docbook conversion working in preview4
https://github.com/mcasperson/asciidoctor/commit/c88abe451c87c814be87a966521df023d991eb0f#diff-9f476fe67d53af1b92adf5d43d06183e |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
5 posts
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
354 posts
|
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: |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
2681 posts
|
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:
... [show rest of quote] Dan Allen | http://google.com/profiles/dan.j.allen |
Free forum by Nabble | Edit this page |