Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #359. Explicit unregistration of extensions. #564

Conversation

robertpanzer
Copy link
Member

A second approach to unregistering extensions.
Now it is completely explicit.
Instead of getting a registration handle from the registration, a registration name has to be passed to the registration methods explicitly.

Basically all registration methods are overloaded with an additional version that takes a string as the registration name.

Note that this PR is for master.

@mojavelinux
Copy link
Member

Great work!

I saw the problem you reported in core regarding the type coercion of the group name, which I'll address in the 1.5.6.1 release.

My one suggestion is to use the term "group name" instead of "registration name". That would mean changing the unregisterExtension method to:

void unregisterExtensionGroup(String name);

Although right now each group has one extension (when using this API), in the future we may merge subsequent registrations against the same group so the group holds multiple extensions.

That reads a bit better to me. Aside from that, I think this looks great.

@mojavelinux
Copy link
Member

There's one possible alternative to consider (or add). We may want to introduce the concept of an extension group, to which you'd assign a name, then register one or more extensions. This could be an alternative to adding the group name to each registration method. Instead, you'd only get to use a group name if you create a group, register extensions on that group, then register the group. That's really what is happening under the covers anyway.

In other words, group registration would be a separate chain in the API, started by initiating a group.

@mojavelinux
Copy link
Member

mojavelinux commented Jul 20, 2017

Actually, I really like this idea of starting with the group API. We'd use a createGroup method to create a group. That method would accept an optional group name argument. If a name is not specified, one is generated. Either way, the group name is accessible via the ExtensionGroup#getName. When you're done adding extensions to the group, you'd pass it to the register method (or perhaps registration is implicit by creating the group).

We could then add the "a la carte" groups like you've done in this pull request later (or, if you really want them, we can leave them too).

wdyt?

@robertpanzer
Copy link
Member Author

Sounds good.
With a Java 6 codebase I'd prefer to register eagerly ;), but lazy registration should still be feasible.
I'll try to go for it as soon as i find the time, shouldn't be too much.
Your idea is sth like this, right?

ExtensionGroup g = asciidoctor.createGroup().block("yell").preprocessor(...);
g.register();
asciidoctor.convert(...);
g.unregister();

(On a small screen, please excuse any typos)

@robertpanzer
Copy link
Member Author

^^ The call to .block() certainly also has to take a class or instance.

@mojavelinux
Copy link
Member

Precisely.

I'm okay with registering eagerly. That's up to you. But the typed ExtensionGroup for register/unregister certainly has a nice feel to it.

@robertpanzer
Copy link
Member Author

@mojavelinux I updated the PR with the ExtensionGroup.
The extensions are now registered lazily.

It certainly needs more test cases.

* Unregisters the extension represented by the given registration name.
* @param registrationName
*/
void unregisterExtension(String registrationName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be groupName?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this method should go away completely.
Unregistration should only be possible for extension registered via the ExtensionGroup mechanism.
Otherwise I would also need to add the "named" registration methods to JavaExtensionRegistry and RubyExtensionRegistry and I wanted to avoid that and keep everything in the ExtensionGroup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -4,7 +4,9 @@ module Extensions
include_package 'org.asciidoctor.extension'
# Treeprocessor was renamed in to TreeProcessor in https://github.com/asciidoctor/asciidoctor/commit/f1dd816ade9db457b899581841e4cf7b788aa26d
# This is necessary to run against both Asciidoctor 1.5.5 and 1.5.6
TreeProcessor = Treeprocessor
if !defined? TreeProcessor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better written as:

TreeProcessor = Treeprocessor unless defined? TreeProcessor

end

def docinfo_processor(extensionName, groupName = nil)
Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't put a space before the opening bracket. That causes a warning in some versions of Ruby.

You no longer need to coerce to a symbol as Asciidoctor 1.5.6.1 does that for you. Just pass the groupName as is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks!
I put the space in there not for the method argument, but to wrap the conditional expression.
I will try to get around without it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, you can write it as:

Asciidoctor::Extensions.register(groupName && groupName.to_sym)

or

Asciidoctor::Extensions.register(groupName ? groupName.to_sym : nil)

A method argument list is an implicit grouping expression.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely overseen that I can remove the coercion. Will remove it, then I don't need the brackets anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does require 1.5.6.1 though. To be clear, the coercion was fixed internally in 1.5.6.1.

build.gradle Outdated
@@ -45,7 +45,7 @@ ext {
xmlMatchersVersion = '1.0-RC1'

// gem versions
asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.5'
asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.6'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use 1.5.6.1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's part of the other PR, that's why I sticked with 1.5.6 here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mojavelinux
Copy link
Member

This is looking really nice!

I made some comments inline.

@robertpanzer
Copy link
Member Author

Updated the PR implementing the review comments.

@robertpanzer
Copy link
Member Author

Bumped to Asciidoctor 1.5.6.1 and removed the coercion.

@robertpanzer
Copy link
Member Author

I think it would make sense to squash this PR and put it on top of #563
Otherwise I'll never get a green build without pulling the changes from that PR in here.

@mojavelinux
Copy link
Member

Seems reasonable to me!

@robertpanzer
Copy link
Member Author

Integrated into #563
Therefore closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants