Skip to content

Commit bfe80f6

Browse files
authored
Asciidoctor: Log absolute path when copying (#565)
Switch the `copy_images` Asciidoctor plugin to log the absolute path when copying images and clean up some rough spots in the tests around `copy_images` that I bumped into when making this change.
1 parent dbbb79f commit bfe80f6

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

resources/asciidoctor/lib/copy_images/extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def process_block block
2323
return unless @copied.add? uri # Skip images we've copied before
2424
source = find_source block, uri
2525
return unless source # Skip images we can't find
26-
logger.info message_with_context "copying #{uri}", :source_location => block.source_location
26+
logger.info message_with_context "copying #{source}", :source_location => block.source_location
2727
copy_image_proc = block.document.attr 'copy_image'
2828
if copy_image_proc
2929
# Delegate to a proc for copying if one is defined. Used for testing.

resources/asciidoctor/spec/copy_images_spec.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def copy_attributes copied
3333
== Example
3434
image::resources/copy_images/example1.png[]
3535
ASCIIDOC
36-
convert input, attributes, match(/INFO: <stdin>: line 2: copying resources\/copy_images\/example1.png/)
36+
convert input, attributes,
37+
eq("INFO: <stdin>: line 2: copying #{spec_dir}\/resources\/copy_images\/example1.png")
3738
expect(copied).to eq([
3839
["resources/copy_images/example1.png", "#{spec_dir}/resources/copy_images/example1.png"]
3940
])
@@ -46,7 +47,8 @@ def copy_attributes copied
4647
== Example
4748
image::example1.png[]
4849
ASCIIDOC
49-
convert input, attributes, match(/INFO: <stdin>: line 2: copying example1.png/)
50+
convert input, attributes,
51+
eq("INFO: <stdin>: line 2: copying #{spec_dir}/resources/copy_images/example1.png")
5052
expect(copied).to eq([
5153
["example1.png", "#{spec_dir}/resources/copy_images/example1.png"]
5254
])
@@ -59,7 +61,8 @@ def copy_attributes copied
5961
== Example
6062
image::copy_images/example1.png[]
6163
ASCIIDOC
62-
convert input, attributes, match(/INFO: <stdin>: line 2: copying copy_images\/example1.png/)
64+
convert input, attributes,
65+
eq("INFO: <stdin>: line 2: copying #{spec_dir}/resources/copy_images/example1.png")
6366
expect(copied).to eq([
6467
["copy_images/example1.png", "#{spec_dir}/resources/copy_images/example1.png"]
6568
])
@@ -93,9 +96,12 @@ def copy_attributes copied
9396
image::resources/copy_images/example2.png[]
9497
image::resources/copy_images/example1.png[]
9598
image::resources/copy_images/example2.png[]
96-
ASCIIDOC
97-
convert input, attributes, match(/INFO: <stdin>: line 2: copying resources\/copy_images\/example1.png/).and(
98-
match(/INFO: <stdin>: line 4: copying resources\/copy_images\/example2.png/))
99+
ASCIIDOC
100+
expected_warnings = <<~LOG
101+
INFO: <stdin>: line 2: copying #{spec_dir}/resources/copy_images/example1.png
102+
INFO: <stdin>: line 4: copying #{spec_dir}/resources/copy_images/example2.png
103+
LOG
104+
convert input, attributes, eq(expected_warnings.strip)
99105
expect(copied).to eq([
100106
["resources/copy_images/example1.png", "#{spec_dir}/resources/copy_images/example1.png"],
101107
["resources/copy_images/example2.png", "#{spec_dir}/resources/copy_images/example2.png"],
@@ -127,8 +133,8 @@ def copy_attributes copied
127133
== Example
128134
image::tmp_example1.png[]
129135
ASCIIDOC
130-
# NOCOMMIT full paths in logs too, I think
131-
convert input, attributes, match(/INFO: <stdin>: line 2: copying tmp_example1.png/)
136+
convert input, attributes,
137+
eq("INFO: <stdin>: line 2: copying #{tmp}/tmp_example1.png")
132138
expect(copied).to eq([
133139
["tmp_example1.png", "#{tmp}/tmp_example1.png"]
134140
])
@@ -149,7 +155,8 @@ def copy_attributes copied
149155
== Example
150156
image::tmp_example1.png[]
151157
ASCIIDOC
152-
convert input, attributes, match(/INFO: <stdin>: line 2: copying tmp_example1.png/)
158+
convert input, attributes,
159+
eq("INFO: <stdin>: line 2: copying #{tmp}/tmp_example1.png")
153160
expect(copied).to eq([
154161
["tmp_example1.png", "#{tmp}/tmp_example1.png"]
155162
])

resources/asciidoctor/spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def convert input, extra_attributes = {}, warnings_matcher = eq('')
3333
}
3434
warnings_string = logger.messages
3535
.map { |l| "#{l[:severity]}: #{l[:message].inspect}" }
36-
.join('\n')
36+
.join("\n")
3737
expect(warnings_string).to warnings_matcher
3838
result
3939
end

0 commit comments

Comments
 (0)