diff --git a/lib/ES/Util.pm b/lib/ES/Util.pm index c5a0c2a6fd984..ea8331a62a9ff 100644 --- a/lib/ES/Util.pm +++ b/lib/ES/Util.pm @@ -85,7 +85,7 @@ sub build_chunked { '-d' => 'book', '-a' => 'showcomments=1', '-a' => "lang=$lang", - '-a' => 'root_dir=' . $root_dir, + '-a' => 'repo_root=' . $root_dir, # Use ` to delimit monospaced literals because our docs # expect that '-a' => 'compat-mode=legacy', @@ -124,7 +124,7 @@ sub build_chunked { '-a' => 'showcomments=1', '-a' => "lang=$lang", '-a' => 'base_edit_url=' . $edit_url, - '-a' => 'root_dir=' . $root_dir, + '-a' => 'repo_root=' . $root_dir, # Use ` to delimit monospaced literals because our docs # expect that '-a' => 'compat-mode=legacy', diff --git a/resources/asciidoctor/lib/edit_me/extension.rb b/resources/asciidoctor/lib/edit_me/extension.rb index 205d373d3367c..be7c9972d199b 100644 --- a/resources/asciidoctor/lib/edit_me/extension.rb +++ b/resources/asciidoctor/lib/edit_me/extension.rb @@ -1,3 +1,4 @@ +require 'pathname' require_relative '../scaffold.rb' include Asciidoctor @@ -18,9 +19,16 @@ def process document def process_block block if [:preamble, :section, :floating_title].include? block.context def block.title + path = source_path url = @document.attributes['edit_url'] url += '/' unless url.end_with?('/') - url += source_path + repo_root = @document.attributes['repo_root'] + if repo_root + repo_root = Pathname.new repo_root + base_dir = Pathname.new @document.base_dir + url += "#{base_dir.relative_path_from(repo_root)}/" + end + url += path "#{super}Edit me" end if :preamble == block.context diff --git a/resources/asciidoctor/spec/edit_me_spec.rb b/resources/asciidoctor/spec/edit_me_spec.rb index 35b3378596ff0..76cd2738e7c0d 100644 --- a/resources/asciidoctor/spec/edit_me_spec.rb +++ b/resources/asciidoctor/spec/edit_me_spec.rb @@ -64,6 +64,29 @@ expect(convert input, attributes).to eq(expected.strip) end + it "respects the repo_root attribute" do + attributes = { + 'edit_url' => 'www.example.com/docs/', + 'repo_root' => File.dirname(File.dirname(__FILE__)), + } + input = <<~ASCIIDOC + include::resources/edit_me/chapter1.adoc[] + + include::resources/edit_me/chapter2.adoc[] + ASCIIDOC + expected = <<~DOCBOOK + + Chapter 1<ulink role="edit_me" url="www.example.com/docs/spec/resources/edit_me/chapter1.adoc">Edit me</ulink> + Words. + + + Chapter 2<ulink role="edit_me" url="www.example.com/docs/spec/resources/edit_me/chapter2.adoc">Edit me</ulink> + Words. + + DOCBOOK + expect(convert input, attributes).to eq(expected.strip) + end + it "does not add a link to each chapter title if edit_link is not set" do input = <<~ASCIIDOC include::resources/edit_me/chapter1.adoc[]