Skip to content

Asciidoctor: Make Edit Me links know about repos - #661

Merged
nik9000 merged 1 commit into
elastic:masterfrom
nik9000:edit_me_repo
Mar 5, 2019
Merged

Asciidoctor: Make Edit Me links know about repos#661
nik9000 merged 1 commit into
elastic:masterfrom
nik9000:edit_me_repo

Conversation

@nik9000

@nik9000 nik9000 commented Mar 4, 2019

Copy link
Copy Markdown
Member

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
nik9000 requested review from a user and ddillinger March 4, 2019 21:26
@nik9000

nik9000 commented Mar 4, 2019

Copy link
Copy Markdown
Member Author

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
Copy Markdown

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
Copy Markdown

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.


spec_dir = File.dirname(__FILE__)

it "has a nice error message if you are missing the edit url" do

Copy link
Copy Markdown

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
Copy Markdown
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

nik9000 commented Mar 5, 2019

Copy link
Copy Markdown
Member Author

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.

1 participant