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 and Extensions to the IncludeProcessor and Reader classes #537

Merged

Conversation

mmews-n4
Copy link

@mmews-n4 mmews-n4 commented Dec 7, 2016

This PR includes the following three changes:

Fix of IncludeProcessor#handles method

The handles(String) method in the IncludeProcessor is not called, because the annotation on the IncludeProcessorProxy#handles method lacks a question mark. Test case added.

Extended IncludeProcessor to accept positional attributes

Before, the IncludeProcessor ignored any positional attributes. Now they can be used separated by commas. Internally, they are key value pairs where the keys are numbered accordingly to their order in the squared macros. The fix is only that these key value pairs are also evaluated when constructing the attributes map. Test case added.

Extended Reader and ReaderImpl

The reader now provides the methods getFile and getDir which are delegated to 'file' and 'dir' of asciidoctor.

@robertpanzer
Copy link
Member

Awesome, thank you!
Great that you discovered that the handles() method wasn't actually called for IncludeProcessors.

I am personally ok with mapping the positional args to the strings "1", "2", ...

Could you please check why the tests are failing on Travis with Java 7?

Another – maybe pedantic – note: Could you please check the indentation of the source code? Looks like you're using Tabs instead of Spaces which makes the code look a bit weird on Github.

@mojavelinux
Copy link
Member

I am personally ok with mapping the positional args to the strings "1", "2", ...

I believe that will solve some other type issues we were having. I was using numbers here to avoid collision with attributes that have the same name, but we could just say that numeric keys (1=value) are reserved for another purpose and should not be declared explicitly.

Extended IncludeProcessor to accept anonymous attributes

Do you mean positional attributes (value only)? If so, could you update the terminology? (See http://asciidoctor.org/docs/user-manual/#setting-attributes-on-an-element)

If I try using an IncludeProcessor written in Ruby, I get these attributes:

include::other.adoc[foo,bar,a=b]

gives me:

{1=>"foo", 2=>"bar", "a"=>"b"}

So effectively this fix translates those numeric keys into string keys, correct?

@mojavelinux
Copy link
Member

Btw, thanks for this fix!

@mojavelinux
Copy link
Member

👍

@mmews-n4
Copy link
Author

mmews-n4 commented Dec 8, 2016

Thanks for your feedback!

  • I replaced the tabs by spaces, as you preferred, @robertpanzer.
  • @mojavelinux, you're right, this fix translates those numeric keys into string keys.
  • I also replaced the term 'anonymous' by 'positional' to fit in to the terminology.
  • I tried to reproduce the errors in the Java7 environment, but it seems to work with JDK7 on my machine. Do you have some advice on how I could reproduce the failure?

@robertpanzer
Copy link
Member

Sorry for responding so late!

I just tried out the failing test.
I guess this is due to the extension iterating over the attributes Map and concatenating the results.
The map is not ordered in any way and the order of the elements given by a HashMap definitely differs between Java 7 and 8. (Stumbled myself over this change a couple of times)
So for me the test fails with this error:

java.lang.AssertionError: 
Expected: a string starting with "My,Positional,Attribute List"
     but: was "Attribute List,Positional,My"
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.junit.Assert.assertThat(Assert.java:956)
	at org.junit.Assert.assertThat(Assert.java:923)
	at org.asciidoctor.extension.WhenJavaExtensionIsRegistered.a_include_processor_can_handle_positional_attrs(WhenJavaExtensionIsRegistered.java:430)

You might simply want to either sort the entries by key ("1", "2" and "3") or just test if the expected substrings are present.

*
* @return file name
*/
public String getFile();
Copy link
Member

Choose a reason for hiding this comment

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

Also, could you please change these tabs to spaces?
(Sorry, but I am pretty opinionated on this 😁

@Override
public String getFile() {
IRubyObject rObj = getRubyProperty("file");
return rObj.toString();
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@@ -395,6 +396,42 @@ public void a_include_instance_processor_should_be_executed_when_include_macro_i
}

@Test
public void a_include_processor_should_only_handle_its_handles() {
Copy link
Member

Choose a reason for hiding this comment

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

Here as well, tabs.

@mmews-n4
Copy link
Author

@robertpanzer thanks a lot for your advice! Hopefully the tests will be green now!

@mmews-n4
Copy link
Author

mmews-n4 commented Dec 12, 2016

@robertpanzer, I don't know the cause of the error. The message says, I should look at
file:///C:/projects/asciidoctorj/asciidoctorj-pdf/build/reports/tests/index.html (which I cannot access) to get information about the error. Do you know the cause of the error?

@robertpanzer robertpanzer merged commit 6544bf2 into asciidoctor:asciidoctorj-1.6.0 Dec 14, 2016
@robertpanzer
Copy link
Member

Awesome!
Thank you for this great contribution!

@abelsromero
Copy link
Member

Do you know the cause of the error?

@mmews-n4 The full report is not accessible now, but the output shows this SEVERE: (RuntimeError) asciidoctor: FAILED: required gem 'rouge' is not installed. Processing aborted.

Highly likely, to be related to this: https://github.com/robertpanzer/asciidoctorj-pdf/issues/3

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.

5 participants