Backends as Stream

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

Backends as Stream

asotobu
Hi,
last night I was talking with Aslak and we found an improvement on backends. Nowdays backends are set as directory using templateDir .

Then in that directory you should create  a directory like:

block_admonition.html.slim and then you add the content in slim format in this case.

We think that it would be useful that we can add backends definition programmatically as stream. Something like:

{:block_amonition.html.slim => stream}

The stream could be in case of Java any instance of InputStream so for example you could store your backends to a site and refer it directly without having to download locally.

This can be done in AsciidoctorJ by intercepting streams and populate into temp directory, but f it could be implemented in Ruby all Asciidoctor users could use it.

WDYT?
Reply | Threaded
Open this post in threaded view
|

Re: Backends as Stream

Aslak Knutsen
Stream's are a bit difficult to read multiple times of course..

But {:block_amonition.html.slim => content_string} would work as a charm :)
Reply | Threaded
Open this post in threaded view
|

Re: Backends as Stream

asotobu
Good point then as string, this would require some changes on public API, and for example a way to give a template a name so it can be loaded on demand, or for example decide that if you register a template programmatically then it is loaded by default for all invocations. But I think it would be more flexible (and I am thinking of a Java EE application) to be able to enable or disable or create them dynamically.

Reply | Threaded
Open this post in threaded view
|

Re: Backends as Stream

mojavelinux
Administrator
In reply to this post by Aslak Knutsen
In fact, it's possible to pass a custom template as a string in 1.5.0. One way to do it is to load the document, register a string-based template for a given context, then convert.

[source,ruby]
----
require 'asciidoctor'
require 'asciidoctor/extensions'
require 'tilt'

paragraph_template = Tilt.new 'paragraph.html.slim' do |t|
  <<-EOS
p=content
  EOS
end

doc = Asciidoctor.load 'paragraph', template_dirs: []
doc.converter.converters.first.register 'paragraph', paragraph_template
puts doc.convert
----

Another way is to use the converter factory directly to create a composite converter with the string-based template preregistered, then pass the converter as an option to the Asciidoctor API:

[source,ruby]
----
converter = Asciidoctor::Converter::Factory.default.create 'html5', template_dirs: []
converter.converters.first.register 'paragraph', paragraph_template
puts Asciidoctor.convert 'paragraph', converter: converter
----

I agree the register method should be easier to call. That's going to need to be filed as a request for enhancement. We might be able to use some Ruby metaprogramming to delegate methods intelligently from the composite to the underlying converter.


Btw, I still have plans to integrate the convert API into the extension APIs so that they can be registered globally like extensions.

Cheers,

-Dan


On Sun, Mar 9, 2014 at 11:54 AM, Aslak Knutsen [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Stream's are a bit difficult to read multiple times of course..

But {:block_amonition.html.slim => content_string} would work as a charm :)


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



--