Skip to content

Commit

Permalink
Support of relative image sources
Browse files Browse the repository at this point in the history
If an File-based image is not placed correctly, embedding the image will fail. This sanity check creates a relative path to the HTML IO object.

Pre-conditions:
- The image to be embedded must be file based
- The html IO object must be support an absolute_path method (http://www.ruby-doc.org/core-2.1.2/File.html#method-c-absolute_path)
  • Loading branch information
idstein committed Jun 25, 2014
1 parent 4035c42 commit b06740a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/cucumber/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'builder'
require 'cucumber/formatter/duration'
require 'cucumber/formatter/io'
require 'pathname'

module Cucumber
module Formatter
Expand Down Expand Up @@ -43,6 +44,9 @@ def embed(src, mime_type, label)
def embed_image(src, label)
id = "img_#{@img_id}"
@img_id += 1
if @io.respond_to?(:absolute_path) and File.exist?(src)
src = Pathname.new(File.absolute_path(src)).relative_path_from(@io.absolute_path)
end
@builder.span(:class => 'embed') do |pre|
pre << %{<a href="" onclick="img=document.getElementById('#{id}'); img.style.display = (img.style.display == 'none' ? 'block' : 'none');return false">#{label}</a><br>&nbsp;
<img id="#{id}" style="display: none" src="#{src}"/>}
Expand Down

0 comments on commit b06740a

Please sign in to comment.