Skip to content

Commit

Permalink
Asciidoctor: Log absolute path when copying (#565)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nik9000 authored Feb 4, 2019
1 parent dbbb79f commit bfe80f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion resources/asciidoctor/lib/copy_images/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def process_block block
return unless @copied.add? uri # Skip images we've copied before
source = find_source block, uri
return unless source # Skip images we can't find
logger.info message_with_context "copying #{uri}", :source_location => block.source_location
logger.info message_with_context "copying #{source}", :source_location => block.source_location
copy_image_proc = block.document.attr 'copy_image'
if copy_image_proc
# Delegate to a proc for copying if one is defined. Used for testing.
Expand Down
25 changes: 16 additions & 9 deletions resources/asciidoctor/spec/copy_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def copy_attributes copied
== Example
image::resources/copy_images/example1.png[]
ASCIIDOC
convert input, attributes, match(/INFO: <stdin>: line 2: copying resources\/copy_images\/example1.png/)
convert input, attributes,
eq("INFO: <stdin>: line 2: copying #{spec_dir}\/resources\/copy_images\/example1.png")
expect(copied).to eq([
["resources/copy_images/example1.png", "#{spec_dir}/resources/copy_images/example1.png"]
])
Expand All @@ -46,7 +47,8 @@ def copy_attributes copied
== Example
image::example1.png[]
ASCIIDOC
convert input, attributes, match(/INFO: <stdin>: line 2: copying example1.png/)
convert input, attributes,
eq("INFO: <stdin>: line 2: copying #{spec_dir}/resources/copy_images/example1.png")
expect(copied).to eq([
["example1.png", "#{spec_dir}/resources/copy_images/example1.png"]
])
Expand All @@ -59,7 +61,8 @@ def copy_attributes copied
== Example
image::copy_images/example1.png[]
ASCIIDOC
convert input, attributes, match(/INFO: <stdin>: line 2: copying copy_images\/example1.png/)
convert input, attributes,
eq("INFO: <stdin>: line 2: copying #{spec_dir}/resources/copy_images/example1.png")
expect(copied).to eq([
["copy_images/example1.png", "#{spec_dir}/resources/copy_images/example1.png"]
])
Expand Down Expand Up @@ -93,9 +96,12 @@ def copy_attributes copied
image::resources/copy_images/example2.png[]
image::resources/copy_images/example1.png[]
image::resources/copy_images/example2.png[]
ASCIIDOC
convert input, attributes, match(/INFO: <stdin>: line 2: copying resources\/copy_images\/example1.png/).and(
match(/INFO: <stdin>: line 4: copying resources\/copy_images\/example2.png/))
ASCIIDOC
expected_warnings = <<~LOG
INFO: <stdin>: line 2: copying #{spec_dir}/resources/copy_images/example1.png
INFO: <stdin>: line 4: copying #{spec_dir}/resources/copy_images/example2.png
LOG
convert input, attributes, eq(expected_warnings.strip)
expect(copied).to eq([
["resources/copy_images/example1.png", "#{spec_dir}/resources/copy_images/example1.png"],
["resources/copy_images/example2.png", "#{spec_dir}/resources/copy_images/example2.png"],
Expand Down Expand Up @@ -127,8 +133,8 @@ def copy_attributes copied
== Example
image::tmp_example1.png[]
ASCIIDOC
# NOCOMMIT full paths in logs too, I think
convert input, attributes, match(/INFO: <stdin>: line 2: copying tmp_example1.png/)
convert input, attributes,
eq("INFO: <stdin>: line 2: copying #{tmp}/tmp_example1.png")
expect(copied).to eq([
["tmp_example1.png", "#{tmp}/tmp_example1.png"]
])
Expand All @@ -149,7 +155,8 @@ def copy_attributes copied
== Example
image::tmp_example1.png[]
ASCIIDOC
convert input, attributes, match(/INFO: <stdin>: line 2: copying tmp_example1.png/)
convert input, attributes,
eq("INFO: <stdin>: line 2: copying #{tmp}/tmp_example1.png")
expect(copied).to eq([
["tmp_example1.png", "#{tmp}/tmp_example1.png"]
])
Expand Down
2 changes: 1 addition & 1 deletion resources/asciidoctor/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def convert input, extra_attributes = {}, warnings_matcher = eq('')
}
warnings_string = logger.messages
.map { |l| "#{l[:severity]}: #{l[:message].inspect}" }
.join('\n')
.join("\n")
expect(warnings_string).to warnings_matcher
result
end

0 comments on commit bfe80f6

Please sign in to comment.