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

feat: asciidoctor plugin #183

Merged
merged 2 commits into from
Apr 27, 2017

Conversation

nicorikken
Copy link
Contributor

A basic tasks for processing asciidoc files using AsciidoctorJ. This implementation is bare-bones, it does not cover Asciidoctor extensions and does not relate asciidoc attributes with Perun meta.
The page title is not rendered by the Asciidoctor task, to mimic the behavior of the markdown extension.

A basic tasks for processing asciidoc files using AsciidoctorJ. This
implementation is bare-bones, it does not cover Asciidoctor extensions and does
not relate asciidoc attributes with Perun meta.
The page title is not rendered by the Asciidoctor task, to mimic the behavior of
the markdown extension.
@nicorikken
Copy link
Contributor Author

For the backstory of this PR, please read #100

@nicorikken
Copy link
Contributor Author

Any feedback?

@bhagany
Copy link
Contributor

bhagany commented Apr 12, 2017

Hi Nico! I'm so glad you've found time to work on this. I apologize - you've caught me in the middle of a job transition (today is my second day) and I haven't had time to do a proper review. I should be able to do so this weekend, though. Sorry for the delay!

@nicorikken
Copy link
Contributor Author

@bhagany Thanks for letting me know. I'm excited to have something mergeable, so I'm eager to get it reviewed, that's all. But certainly it can wait some more, no problem.

Copy link
Member

@podviaznikov podviaznikov left a comment

Choose a reason for hiding this comment

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

code looks good to me. Waiting for @bhagany review before merging

e extensions EXTENSIONS [str] "extensions of files to process"
m meta META edn "metadata to set on each entry"]
(let [{:keys [out-dir filterer extensions meta]} (merge +asciidoctor-defaults+ *opts*)]
(comp (yaml-metadata :filterer filterer :extensions extensions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since Asciidoc can use YAML front-matter itself, you might consider passing :keep-yaml true to yaml-metadata. That way, the YAML will still be present in the file when the asciidoctor* task sees it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but the issue arises that the default meta keys used in Perun and !{Asciidoctor](http://asciidoctor.org/docs/user-manual/#attribute-catalog) are different. I was thinking of introducing a translation layer in a next version which contains the necessary translation layer, as I stated in the currently last comment on #100 For now I could indeed also just pass it through. What do you think, considering my comments? Both are fine to me.

(:import [org.asciidoctor Asciidoctor Asciidoctor$Factory]))

(defn asciidoctor-to-html [file-content]
(.convert (Asciidoctor$Factory/create "") file-content {}))
Copy link
Contributor

Choose a reason for hiding this comment

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

This might not make much difference, but rather than creating the Asciidoctor interface on each call to asciidoctor-to-html, would it be more efficient to say, (def asciidcotor (Asciidoctor$Factory/create "")) as a top-level form, and then reuse the same object?

Copy link
Contributor Author

@nicorikken nicorikken Apr 17, 2017

Choose a reason for hiding this comment

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

Yes, but this fails the moment that environment-specific parameters are introduced like libraries. The issue of creating new containers came up on #100 and does hurt performance for large number of conversions.
I guess not creating new containers does limit the conversion process to a single core?
Probably the converter-specific settings have to be raised to the task level, so that a different container setting requires a different task to be created. Then inside the task the same converter (factory) can be used.
I will refactor this.

@@ -400,6 +425,26 @@ This --- be ___markdown___.")
:msg "`pandoc` should parse HTML to markdown"))

(add-txt-file :path "test.md" :content (nth input-strings 0))
(p/asciidoctor :out-dir nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that you're testing different parsing modes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then again I couldn't get the tests to fail based on content, so perhaps I'm using the framework incorrectly.

@bhagany
Copy link
Contributor

bhagany commented Apr 16, 2017

I'm very pleased with how clean this implementation is. I think it's a good base on which more Asciidoctor features can be added over time. Thanks!

@nicorikken
Copy link
Contributor Author

nicorikken commented Apr 17, 2017

@bhagany Let me know what you think about the options for dealing with YAML, and if I'm missing out om some testing features in the testing framework. I'll refactor the initiation of new JRuby containers.

Copy link
Contributor

@MartyGentillon MartyGentillon left a comment

Choose a reason for hiding this comment

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

Nice work. A few thoughts.

@@ -0,0 +1,13 @@
(ns io.perun.asciidoctor
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

(.convert (Asciidoctor$Factory/create "") file-content {}))

(defn process-asciidoctor [{:keys [entry]}]
(perun/report-debug "asciidoctor" "processing asciidoctor" (:filename entry))
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

:rm-originals true
:pod pod})))

(deftask asciidoctor
Copy link
Contributor

Choose a reason for hiding this comment

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

By naming the task after the library you are using, you bind the implementation to the interface. A better task name would be ascidoc.

@nicorikken
Copy link
Contributor Author

@MartyGentillon I see your point of view, but then again, there is also an outdated Python reference implementation of Asciidoc which is quite outdated Small parts of syntax in Asciidoctor are still improving, to end up at the end-goal of an 'unidoc' syntax. Also Asciidoctor has some Markdown support, and has the ability to load some plugins, like the terrific asciidoctor-diagram. So while I see where you are coming from, I'd rather leave it at the tool, for clarity.

@MartyGentillon
Copy link
Contributor

MartyGentillon commented Apr 21, 2017 via email

Based on comments raised at hashobject#183 the
asciidoctor container is now bound to the namespace and shared between
processing calls.
@nicorikken
Copy link
Contributor Author

  • The change to share the Asciidoctor JRuby container is committed.
  • I tried to handle the YAML in Asciidoc, but could not manage to. So the only option would be to skip it altogether. Also I think keeping the same pattern as the Markdown task benefits the project structure. I consider exposing YAML metadata to the Asciidoctor tasks a desirable next step.
  • I asked about the tests, which do not seem to test on content. Perhaps this can be improved at a later stage.

To me the code is ready to merge in it's current state. Metadata would be the focus for the next iteration.

@bhagany
Copy link
Contributor

bhagany commented Apr 22, 2017

Seems to already be decided, but because this task can parse different types of content, it seems to be closer to pandoc (which is named after the tool), than it is to markdown. So, I agree that asciidoctor is a more appropriate name for the task.

I do want to take a look at the tests, and I should have time tonight or tomorrow, but otherwise I agree this is ready to merge. I'm waiting for the legal team at my new job to sign off on my work on Perun, so I don't want to merge before that happens. If one of the other committers wants to after we figure out what's up with the tests though, I approve.

@bhagany
Copy link
Contributor

bhagany commented Apr 22, 2017

Using aliases based on the type of content to be parsed is an interesting idea, and I think it deserves more thought. There would be quite a few aliases for pandoc, but we'd probably be able to at least do the most popular ones.

@nicorikken
Copy link
Contributor Author

@bhagany Thanks for the update. If somebody can verify I implemented the tests correctly, that would be great.

@bhagany
Copy link
Contributor

bhagany commented Apr 24, 2017

@nicorikken I think the tests are implemented correctly. I was able to get them to fail by changing the parsed-asciidoc-md and parsed-asciidoc-adoc vars to something else. I might be missing something though, could you explain in more detail how you got them to behave in a way you didn't expect?

@nicorikken
Copy link
Contributor Author

I was expecting a summary of the test results, as I know from my Leiningen usage. But indeed I get error output if the testresults are incorrect:

[asciidoctor] - rendered new or changed file test.html

FAIL in clojure.lang.PersistentList$EmptyList@1 (perun_test.clj:59)
io.perun-test/with-arguments-test
`asciidoctor` should populate HTML with parsed markdown content
expected: (f (.contains (slurp (boot/tmp-file (boot/tmp-get fileset path))) content))
  actual: false

So in hindsight it was just my expectation, not the actual code.

@bhagany
Copy link
Contributor

bhagany commented Apr 25, 2017

Okay, then I think this is ready to merge. Still haven't heard back from my legal department, but if another committer wants to merge before that happens, I'm good with that.

@nicorikken
Copy link
Contributor Author

Considering that all participants on this PR approved, can this be merged?

@bhagany bhagany merged commit f8a5d89 into hashobject:master Apr 27, 2017
@bhagany
Copy link
Contributor

bhagany commented Apr 27, 2017

I got permission from the legal department :)

@nicorikken
Copy link
Contributor Author

Nice!
Finally getting Asciidoctor is a relief. Thanks!

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.

4 participants