Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

The converter factory should returns a CompositeConverter #4

Closed
ggrossetie opened this issue Oct 1, 2016 · 7 comments
Closed

The converter factory should returns a CompositeConverter #4

ggrossetie opened this issue Oct 1, 2016 · 7 comments

Comments

@ggrossetie
Copy link
Member

To have a consistent experience between Asciidoctor Ruby and Asciidoctor.js, the converter factory should returns a CompositeConverter:

template_converter = TemplateConverter.new backend, opts[:template_dirs], opts
CompositeConverter.new backend, template_converter, base_converter

@mojavelinux During my tests I've tried to remove the embedded template from the Reveal.js backend expecting a fallback on the HTML5 backend but instead I got:

Could not find a converter to handle transform: embedded

Do I have to configure something special in template.rb ?
I did implement handles? method in template.rb but apparently that's not enough...

@mojavelinux
Copy link
Member

I did implement handles? method in template.rb but apparently that's not enough...

That should be enough. That's how the composite template decides which converter should handle the node.

    def find_converter transform
      @converters.each do |candidate|
        return candidate if candidate.handles? transform
      end
      raise %(Could not find a converter to handle transform: #{transform})
    end

Keep in mind, though, the handles? method should only return true if the template is found.

@ggrossetie
Copy link
Member Author

ggrossetie commented Oct 2, 2016

That's what I did but "find_converter" does not fallback on html5 converter.
I will do some testing on Asciidoctor Ruby to understand how this is working.

Le 2 oct. 2016 1:16 AM, "Dan Allen" notifications@github.com a écrit :

I did implement handles? method in template.rb but apparently that's not
enough...

That should be enough. That's how the composite template decides which
converter should handle the node.

def find_converter transform
  @converters.each do |candidate|
    return candidate if candidate.handles? transform
  end
  raise %(Could not find a converter to handle transform: #{transform})
end

Keep in mind, though, the handles? method should only return true if the
template is found.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAUV3EBXkxHY7dM_PwBIBfrbu3I4hFA2ks5qvunUgaJpZM4KLuH9
.

@mojavelinux
Copy link
Member

Aha. That's because the base converter is selected according to the backend, which you've changed to revealjs. That's why I explicitly create the Html5Converter in the Bespoke converter. See https://github.com/asciidoctor/asciidoctor-bespoke/blob/master/lib/asciidoctor-bespoke/converter.rb#L30

@mojavelinux
Copy link
Member

In other words, we have a bit of a chicken-egg problem. The backend determines the base converter, but then you can't use the backend to select the composite converter. I haven't really figured that out yet. One solution would be to use the basebackend instead of the backend to select the base converter. The only problem is that we don't pass that information.

@mojavelinux
Copy link
Member

That's why right now, when you are using the template converter (and not your own composite converter), you should always set the backend to what you want the base converter to be. But we need a better solution.

@ggrossetie
Copy link
Member Author

@mojavelinux Ok I think I now understand why this was not working. I was using the attribute :backend: revealjs because I thought the CompositeConverter was using a "fallback" mechanism. In effect the CompositeConverter is using an "overload" mechanism. So what I need to do is to use the default backend (ie. html5) with a template directory. With this configuration, if the template converter handles the "node" then we are using the template converter otherwise we are using the default html5 converter.

The only drawback is that the following code will not work anymore: https://github.com/asciidoctor/asciidoctor-template.js/blob/master/lib/asciidoctor/core_ext/factory.rb#L38-L42

if backend == 'revealjs' && (JAVASCRIPT_PLATFORM == 'node' || JAVASCRIPT_PLATFORM == 'node-electron')
  if ::File.exist?(revealjs_templates_path = 'node_modules/asciidoctor-reveal.js/templates')
    opts[:template_dirs] = revealjs_templates_path unless opts.key? :template_dirs
  end
end

But this was an ugly hack anyway 😉
I think this is another good reason to create a "proper" Asciidoctor backend for Reveal.js: asciidoctor/asciidoctor-reveal.js#93

@mojavelinux
Copy link
Member

Agreed.

I do think that the factory should have access to both the backend and the basebackend. Then we could actually do this sort of layering. I've added a node to look at this in core. Until then, the custom composite converter setup the way you describe is the way to go.

ggrossetie added a commit that referenced this issue Oct 2, 2016
Resolves #4, Reintroduce the CompositeConverter
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants