-
Notifications
You must be signed in to change notification settings - Fork 335
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
Asciidoctor: Make Edit Me links know about repos #661
Conversation
The "Edit Me" link generation in Asciidoctor was basically a copy of the asciidoc implementation which was simple because it *had* to be simple. The asciidoctor implementation had trouble dealing with books built from multiple repositories because the asciidoc implementation does. The asciidoc implementation works around it by allowing files to set their `edit_url` whenever they include a book from a different repo. We had a bug the asciidoctor implementation that led to cross repo links not working that was unrelated, but it led me to notice how silly this whole thing was. This change replaces way that asciidoctor finds the edit url. We now pass in an attribute with the root of each repo and the edit me url for that root. When we want to generate the a link we pick the first repo that contains the path of the asciidoctor file and use it's associated url. This is nice because it dosen't need anything like `repo_root` and it can automatically handle the edit me links, allowing us to remove the overridden links when we shift books to asciidoctor.
I'd love to steal some of the infrastructure in #659 for an integration test for this. |
logger.error message_with_context "invalid edit_urls, no url" | ||
next | ||
end | ||
url = url[0..-2] if url.end_with? '/' |
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.
Since you are mutating url
anyway, you could:
url.chomp!('/')
Not a change request, just a "fun fact".
edit_url = edit_urls.find { |e| path.start_with? e[:toplevel] } | ||
unless edit_url | ||
logger.warn message_with_context "couldn't find edit url for #{path}", :source_location => source_location | ||
return super |
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.
Really happy to see all these new log messages.
@@ -13,17 +14,41 @@ | |||
Asciidoctor::Extensions.unregister_all | |||
end | |||
|
|||
spec_dir = File.dirname(__FILE__) | |||
|
|||
it "has a nice error message if you are missing the edit url" 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.
I love test names like this. 👍
Totally slays test_error_message
.
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.
I like this about rspec a lot! "Ruby as a DSL" can have all kinds of problems with error reporting and stuff, but here it is super nice!
Thanks for reviewing @jarpy! |
The "Edit Me" link generation in Asciidoctor was basically a copy of the
asciidoc implementation which was simple because it had to be simple.
The asciidoctor implementation had trouble dealing with books built from
multiple repositories because the asciidoc implementation does. The
asciidoc implementation works around it by allowing files to set their
edit_url
whenever they include a book from a different repo. We had abug the asciidoctor implementation that led to cross repo links not
working that was unrelated, but it led me to notice how silly this whole
thing was.
This change replaces way that asciidoctor finds the edit url. We now
pass in an attribute with the root of each repo and the edit me url for
that root. When we want to generate the a link we pick the first repo
that contains the path of the asciidoctor file and use it's associated
url. This is nice because it dosen't need anything like
repo_root
andit can automatically handle the edit me links, allowing us to remove the
overridden links when we shift books to asciidoctor.