File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ sub build_chunked {
8585 ' -d' => ' book' ,
8686 ' -a' => ' showcomments=1' ,
8787 ' -a' => " lang=$lang " ,
88- ' -a' => ' root_dir =' . $root_dir ,
88+ ' -a' => ' repo_root =' . $root_dir ,
8989 # Use ` to delimit monospaced literals because our docs
9090 # expect that
9191 ' -a' => ' compat-mode=legacy' ,
@@ -124,7 +124,7 @@ sub build_chunked {
124124 ' -a' => ' showcomments=1' ,
125125 ' -a' => " lang=$lang " ,
126126 ' -a' => ' base_edit_url=' . $edit_url ,
127- ' -a' => ' root_dir =' . $root_dir ,
127+ ' -a' => ' repo_root =' . $root_dir ,
128128 # Use ` to delimit monospaced literals because our docs
129129 # expect that
130130 ' -a' => ' compat-mode=legacy' ,
Original file line number Diff line number Diff line change 1+ require 'pathname'
12require_relative '../scaffold.rb'
23
34include Asciidoctor
@@ -18,9 +19,16 @@ def process document
1819 def process_block block
1920 if [ :preamble , :section , :floating_title ] . include? block . context
2021 def block . title
22+ path = source_path
2123 url = @document . attributes [ 'edit_url' ]
2224 url += '/' unless url . end_with? ( '/' )
23- url += source_path
25+ repo_root = @document . attributes [ 'repo_root' ]
26+ if repo_root
27+ repo_root = Pathname . new repo_root
28+ base_dir = Pathname . new @document . base_dir
29+ url += "#{ base_dir . relative_path_from ( repo_root ) } /"
30+ end
31+ url += path
2432 "#{ super } <ulink role=\" edit_me\" url=\" #{ url } \" >Edit me</ulink>"
2533 end
2634 if :preamble == block . context
Original file line number Diff line number Diff line change 6464 expect ( convert input , attributes ) . to eq ( expected . strip )
6565 end
6666
67+ it "respects the repo_root attribute" do
68+ attributes = {
69+ 'edit_url' => 'www.example.com/docs/' ,
70+ 'repo_root' => File . dirname ( File . dirname ( __FILE__ ) ) ,
71+ }
72+ input = <<~ASCIIDOC
73+ include::resources/edit_me/chapter1.adoc[]
74+
75+ include::resources/edit_me/chapter2.adoc[]
76+ ASCIIDOC
77+ expected = <<~DOCBOOK
78+ <chapter id="_chapter_1">
79+ <title>Chapter 1<ulink role="edit_me" url="www.example.com/docs/spec/resources/edit_me/chapter1.adoc">Edit me</ulink></title>
80+ <simpara>Words.</simpara>
81+ </chapter>
82+ <chapter id="_chapter_2">
83+ <title>Chapter 2<ulink role="edit_me" url="www.example.com/docs/spec/resources/edit_me/chapter2.adoc">Edit me</ulink></title>
84+ <simpara>Words.</simpara>
85+ </chapter>
86+ DOCBOOK
87+ expect ( convert input , attributes ) . to eq ( expected . strip )
88+ end
89+
6790 it "does not add a link to each chapter title if edit_link is not set" do
6891 input = <<~ASCIIDOC
6992 include::resources/edit_me/chapter1.adoc[]
You can’t perform that action at this time.
0 commit comments