-
Notifications
You must be signed in to change notification settings - Fork 172
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
Fixes #359. Explicit unregistration of extensions. #564
Conversation
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. |
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. |
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? |
Sounds good. ExtensionGroup g = asciidoctor.createGroup().block("yell").preprocessor(...);
g.register();
asciidoctor.convert(...);
g.unregister(); (On a small screen, please excuse any typos) |
^^ The call to .block() certainly also has to take a class or instance. |
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. |
@mojavelinux I updated the PR with the ExtensionGroup. It certainly needs more test cases. |
* Unregisters the extension represented by the given registration name. | ||
* @param registrationName | ||
*/ | ||
void unregisterExtension(String registrationName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be groupName?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This is looking really nice! I made some comments inline. |
Updated the PR implementing the review comments. |
Bumped to Asciidoctor 1.5.6.1 and removed the coercion. |
I think it would make sense to squash this PR and put it on top of #563 |
Seems reasonable to me! |
Integrated into #563 |
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.