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

Expose Document's source and source_lines properties #1145

Conversation

abelsromero
Copy link
Member

Thank you for opening a pull request and contributing to AsciidoctorJ!

Please take a bit of time giving some details about your pull request:

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?
Expose Document's source and source_lines properties.
This is required to be able to use other asciidoctor components like asciidoctor-reducer.

How does it achieve that?
Using already present AsciidoctorJ APIs and practices, nothing special.

Are there any alternative ways to implement this?
Not that I know.

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

Issue

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

Fixes #1143

Release notes

Please add a corresponding entry to the file CHANGELOG.adoc

@abelsromero abelsromero force-pushed the issue-1143-expose-document-source-and-source_lines branch from 5e99631 to 4d64810 Compare March 19, 2023 10:29

@Test
public void should_return_empty_when_document_is_null() {
assertEmptySources(loadDocument(null));
Copy link
Member

Choose a reason for hiding this comment

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

This test seems to fail for me with a NullPointerException.
It seems like this could be fixed by changing JRubyAsciidoctor.load() like so:

    @Override
    public Document load(String content, Options options) {
        RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options.map());
        return (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load",
                Optional.ofNullable(content).map(rubyRuntime::newString).orElse(null), rubyHash));
    }

Copy link
Member Author

@abelsromero abelsromero Mar 19, 2023

Choose a reason for hiding this comment

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

I don't know how I run it locally, but I'd rather remove the test and deal with supporting null consistently in all cases (String, File, etc.) in a separate PR. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Being purist, if null was an error case, changing it now would be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

Since main is supposed to be the next 3.0.0 it would be allowed to introduce breaking changes :D
But of course we could keep it like this and change the test case.

Copy link
Member Author

@abelsromero abelsromero Mar 19, 2023

Choose a reason for hiding this comment

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

Created a story #1146 and looked into the required changes. If it's OK, I can spend time tomorrow.

@abelsromero abelsromero force-pushed the issue-1143-expose-document-source-and-source_lines branch from 4d64810 to c33af8f Compare March 19, 2023 18:43
@abelsromero
Copy link
Member Author

abelsromero commented Mar 19, 2023

Btw, I assume this is fine going to 3.0.0? Or a 2.5.8 is planned? No issue at all backporting it if necessary.

@robertpanzer
Copy link
Member

Yes, main would be 3.0.0.
We can also do a 2.5.8, that contains this change.

@abelsromero
Copy link
Member Author

We can also do a 2.5.8, that contains this change.

If people do not ask for it, I would not do it.

@abelsromero
Copy link
Member Author

Changes done, anything else needs improving? 👀

@robertpanzer
Copy link
Member

Thank you! Looks good!

@robertpanzer robertpanzer merged commit c8daaab into asciidoctor:main Mar 21, 2023
@abelsromero abelsromero deleted the issue-1143-expose-document-source-and-source_lines 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.

Expose Document::source and Document::source_lines in Document interface
2 participants