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: Fix edit url for nested roots #546

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ES/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 9 additions & 1 deletion resources/asciidoctor/lib/edit_me/extension.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'pathname'
require_relative '../scaffold.rb'

include Asciidoctor
Expand All @@ -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}<ulink role=\"edit_me\" url=\"#{url}\">Edit me</ulink>"
end
if :preamble == block.context
Expand Down
23 changes: 23 additions & 0 deletions resources/asciidoctor/spec/edit_me_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 id="_chapter_1">
<title>Chapter 1<ulink role="edit_me" url="www.example.com/docs/spec/resources/edit_me/chapter1.adoc">Edit me</ulink></title>
<simpara>Words.</simpara>
</chapter>
<chapter id="_chapter_2">
<title>Chapter 2<ulink role="edit_me" url="www.example.com/docs/spec/resources/edit_me/chapter2.adoc">Edit me</ulink></title>
<simpara>Words.</simpara>
</chapter>
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[]
Expand Down