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

Asciidoctor: Make Edit Me links know about repos #661

Merged
merged 1 commit into from
Mar 5, 2019

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Mar 4, 2019

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.

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.
@nik9000
Copy link
Member Author

nik9000 commented Mar 4, 2019

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? '/'
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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!

@nik9000
Copy link
Member Author

nik9000 commented Mar 5, 2019

Thanks for reviewing @jarpy!

@nik9000 nik9000 merged commit 6732289 into elastic:master Mar 5, 2019
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.

2 participants