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

Retrieve all images in catalog during conversion #1171

Conversation

abelsromero
Copy link
Member

Kind of change

  • Bug fix
  • New non-breaking feature
  • New breaking feature
  • Documentation update
  • Build improvement

Description

What is the goal of this pull request?
DRAFT PR, WIP

Offer users the option to obtain images from the assets catalog.
However, it only works when calling load()+getContent(), and unlike in Asciidoctor Ruby, we cannot call convert because it fails (see comment).

How does it achieve that?

Exposes the images properties from the catalog.
However, this PR is not done yet untill:

  • Fix using convert to obtain the Document instance
  • Fix catalog not being available when using custom converters (see failing test WhenReadingImagesFromCatalogAssetFromConverter) 👉 I think that fixing the first issue should fix this.
  • Docs

Are there any alternative ways to implement this?

WIP

Are there any implications of this pull request? Anything a user must know?

Not

Issue

If this PR fixes an open issue, please add a line of the form:

Fixes #1166

Release notes

Please add a corresponding entry to the file CHANGELOG.adoc

@robertpanzer
Copy link
Member

Thanks for starting the work on enhancing the catalogAssets feature!

we cannot call convert because it fails (see #1166 (comment)).

Can you shed some light on what is failing?
Asciidoctor::convert documents that it returns a Document when converting to a file, and the string otherwise:

https://github.com/asciidoctor/asciidoctor/blob/b1d2f7101b513414ade941d0f3c8cebc913c8452/lib/asciidoctor/convert.rb#L33-L35

I see that we're not returning the Document object when converting to a file, just returning null instead.
Is that what you mean with "it fails"?

@abelsromero
Copy link
Member Author

Is that what you mean with "it fails"?

Yes, haven't had time to check yet. I assume there's some error in the bindings that should not be very complicated 🤞

@abelsromero abelsromero force-pushed the issue-1166-retrieve-all-images-in-catalog-during-conversion branch 2 times, most recently from 78efe30 to 4a6ed03 Compare April 10, 2023 17:25
@abelsromero
Copy link
Member Author

abelsromero commented Apr 10, 2023

I see we explicitly check the return type and just insert null

if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
.
And going back into the git history I could not find a real reason for it, seems to come from initial versions and it has been preserved. Could be that we considered returning Document odd when the Java AST was not well defined.
I think the best is to align with Asciidoctor Ruby and we should not take actions that limit functionality.
Unless we want to create new methods to distinguish "conversion" from "conversion + return AST", but given the combinations of methods and options are already not simple (eg. convert + toFile == convert_file), I would not add more layers.

So I changed the check that returned null to actually return Document, and furthermore seeing the code now I see why convert returns the dynamic Interface seeing in the comment instead of a proper String. I'll open a separate issue for that.

@abelsromero abelsromero force-pushed the issue-1166-retrieve-all-images-in-catalog-during-conversion branch 2 times, most recently from 78e0a63 to 4b49877 Compare April 10, 2023 21:23
@abelsromero abelsromero marked this pull request as ready for review April 10, 2023 21:23
@abelsromero abelsromero force-pushed the issue-1166-retrieve-all-images-in-catalog-during-conversion branch from 4b49877 to 0395c8a Compare April 10, 2023 21:47
@robertpanzer
Copy link
Member

I can't recall if this has always been the case, or whether I changed it to this to avoid the problems with the wrappers generated by JRuby.
At least for AsciidoctorJ 3.0 we could check if the expected class is an AST class, and in that case try to apply the NodeConverter.

@abelsromero abelsromero force-pushed the issue-1166-retrieve-all-images-in-catalog-during-conversion branch from 0395c8a to d547961 Compare April 11, 2023 16:44
@abelsromero
Copy link
Member Author

At least for AsciidoctorJ 3.0 we could check if the expected class is an AST class, and in that case try to apply the NodeConverter.

That's my idea, adaptReturn takes care of it for now in a simple way. In another PR we can improve and create some fancy Java class ReturnTypeAdapterVisitorPattern.
But for now, it gets the job done.

I just updated the changelog, nothing else to add or change from me.

private <T> T adaptReturn(IRubyObject object, Class<T> expectedResult) {
if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
if (Document.class.isAssignableFrom(expectedResult)) {
return (T) new DocumentImpl(object);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to use NodeConverter.createNode() if expectedResult is Document.class?
Then we would keep NodeConverter as the only class that creates AST nodes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely!

@abelsromero abelsromero force-pushed the issue-1166-retrieve-all-images-in-catalog-during-conversion branch from d547961 to 5086248 Compare April 11, 2023 19:35
* Current implementation works correctly when using load+getContent,
convert and convertFile.
* Fix 'convert' & 'convertFile' to correctly return Document type when applies
* Fix WhenTwoAsciidoctorInstancesAreCreated test, not being run and having invalid code
* Format RubyGemsPreloader.java and use immutable Map for options
* Remove unused method JRubyAsciidoctor.scanForAsciiDocFiles
@abelsromero
Copy link
Member Author

Unless objected, this being a new feature I am not considering porting to v2.5.x

@abelsromero
Copy link
Member Author

anything else to improve? 👀

@robertpanzer
Copy link
Member

Sorry for being behind a bit, I'll check it over the weekend.

@robertpanzer
Copy link
Member

Thanks! Looks good to me.

@robertpanzer robertpanzer merged commit 52881e6 into asciidoctor:main Apr 15, 2023
@abelsromero
Copy link
Member Author

Thanks!

abelsromero added a commit to abelsromero/asciidoctorj that referenced this pull request Apr 15, 2023
Remove unnecessary 'gem' packaging during upstream gem installation.

* Bump 'com.github.jruby-gradle.base' to v2.0.1
* Bump 'gem-maven-plugin' to v2.0.1
* Remove some unnecessary test files and configurations

Fixes asciidoctor#1171
abelsromero added a commit to abelsromero/asciidoctorj that referenced this pull request Apr 15, 2023
Remove unnecessary 'gem' packaging during upstream gem installation.

* Bump 'com.github.jruby-gradle.base' to v2.0.1
* Bump 'gem-maven-plugin' to v2.0.1
* Remove some unnecessary test files and configurations

Fixes asciidoctor#1171
@abelsromero abelsromero deleted the issue-1166-retrieve-all-images-in-catalog-during-conversion branch April 21, 2023 08:25
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.

Asset catalog does not include inlined images
2 participants