Enabling/Disabling extensions

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

Enabling/Disabling extensions

asotobu
We have been talking about in Twitter about a new way to enable and disable extensions. Basically the idea that has been discussed it has been to add some label when extension is registered so we can enable by setting as attribute.

So for example:

[source, pseudocode]
----
asciidoctor.register("securedocument", new DecryptPreProcessor());
----

and in the document:

[source, asciidoc]
----
:extension: securedocument
----

Of course this is an example to show the meaning of what has been discussed but not how it would be implemented.

But I think we can even do something more complete and the label instead of being a simple label it can be a regexp somthing like PathParam in Jax-Rs. So for example:

`asciidoctor.register("secure.*", new DecryptPreProcessor());`

may be fit:

[source, asciidoc]
----
:extension: securebook
:extension: securedocument
----

but also we may introduce some kind of metaexpressions, separated by colon:

`asciidoctor.register("filename:a.*\.adoc", new PreProcessor());`

which means that all files to be rendered which its name starts with _a_ and finishing with _.adoc_ will enable the extension.

Or for example:

`asciidoctor.register("attribute:preprocessor", ...);

will activate given extension when attribute preprocessor is present on document:

[source, asciidoc]
----
:preprocessor:
----

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

Re: Enabling/Disabling extensions

Robert.Panzer
I like the idea of the expressions.
From a groovy and possibly also ruby point of view I would prefer to even go a step further and use a predicate that decides whether an extension should be used or not.
While making the code a little more ugly with Java<8 it looks very elegant in these two languages (at least in my opinion)

So could be sth like
`asciidoctor.register({it.filename ==~ /a.*\.adoc/}, new PreProcessor());`
in Groovy or
`asciidoctor.register(doc -> {doc.getFilename().matches("a.*\.adoc")}, new PreProcessor());`
in Java 8

Reply | Threaded
Open this post in threaded view
|

Re: Enabling/Disabling extensions

mojavelinux
Administrator
+1 This was certainly the idea when I added the name to an extension in 1.5.0. We haven't yet done anything with the name, but what I envisioned was something like:

 $ asciidoctor -a extensions=ui,social,diagram sample.adoc

Of course, the API can take a more sophisticated approach, but once passed to the core we should end up with a simple list of names to enable.

I filed an issue to track this feature in core here:


-Dan

On Tue, Sep 2, 2014 at 1:40 AM, Robert.Panzer [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I like the idea of the expressions.
From a groovy and possibly also ruby point of view I would prefer to even go a step further and use a predicate that decides whether an extension should be used or not.
While making the code a little more ugly with Java<8 it looks very elegant in these two languages (at least in my opinion)

So could be sth like
`asciidoctor.register({it.filename ==~ /a.*\.adoc/}, new PreProcessor());`
in Groovy or
`asciidoctor.register(doc -> {doc.getFilename().matches("a.*\.adoc")}, new PreProcessor());`
in Java 8




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



--