Skip to content
Closed
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
9 changes: 7 additions & 2 deletions bin/review-epubmaker
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,14 @@ def copyImagesToDir(dirname, copybase)
if FileTest.directory?("#{dirname}/#{fname}")
copyImagesToDir("#{dirname}/#{fname}", "#{copybase}/#{fname}")
else
if fname =~ /\.(png|gif|jpg|jpeg|svg)$/i
if fname =~ /\.(png|gif|jpg|jpeg|svg|eps)$/i
Dir.mkdir(copybase) unless File.exist?(copybase)
FileUtils.cp "#{dirname}/#{fname}", copybase
if fname =~ /\.eps\Z/
system("convert #{dirname}/#{fname} #{File.expand_path(fname+'.png', copybase)}")
fname = fname + '.png'
else
FileUtils.cp "#{dirname}/#{fname}", copybase
end
figid = getFigId(dirname.gsub(%r|/|,'-')+"-"+fname)
mime = nil
case fname.downcase.match(/\.(png|gif|jpg|jpeg|svg)$/)[1]
Expand Down
4 changes: 3 additions & 1 deletion lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,10 @@ def result_metric(array)

def image_image(id, caption, metric)
metrics = parse_metric("html", metric)
img_path = @chapter.image(id).path.sub(/\A\.\//, "")
img_path = img_path + ".png" if img_path =~ /\.eps\Z/
puts %Q[<div class="image">]
puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
puts %Q[<img src="#{img_path}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
image_header id, caption
puts %Q[</div>]
end
Expand Down
29 changes: 29 additions & 0 deletions test/test_epubmaker_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
REVIEW_EPUBMAKER = File.expand_path('../bin/review-epubmaker', File.dirname(__FILE__))

load REVIEW_EPUBMAKER
alias :epubmaker_copyImagesToDir :copyImagesToDir

class EPUBMakerCmdTest < Test::Unit::TestCase
def setup
Expand All @@ -20,9 +21,31 @@ def setup
def teardown
FileUtils.rm_rf @tmpdir1
FileUtils.rm_rf @tmpdir2

ENV['RUBYLIB'] = @old_rubylib
end

def test_copyImagesToDir
types = %w{png gif jpg jpeg svg PNG GIF JPG JPEG SVG}
types.each do |type|
touch_file("#{@tmpdir1}/foo.#{type}")
end
@manifeststr = ""
epubmaker_copyImagesToDir(@tmpdir1, @tmpdir2)

types.each do |type|
assert File.exists?("#{@tmpdir2}/foo.#{type}"), "Copying #{type} file failed"
end
end

def test_copyImagesToDir_eps
FileUtils.cp(File.expand_path("tiger.eps", File.dirname(__FILE__)), "#{@tmpdir1}/tiger.eps")
@manifeststr = ""
epubmaker_copyImagesToDir(@tmpdir1, @tmpdir2)

assert File.exists?("#{@tmpdir2}/tiger.eps.png"), "Converting eps file into png file failed"
end

def test_epubmaker_cmd
config = prepare_samplebook(@tmpdir1)
builddir = @tmpdir1 + "/" + config['bookname'] + '-epub'
Expand All @@ -34,4 +57,10 @@ def test_epubmaker_cmd

assert File.exists?(builddir)
end

private
def touch_file(path)
File.open(path, "w").close
path
end
end
11 changes: 11 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ def @chapter.image(id)
assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, @builder.raw_result
end

def test_image_eps
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
item.instance_eval{@pathes=["./images/chap1-sampleimg.eps"]}
item
end

@builder.image_image("sampleimg","sample photo",nil)
assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.eps.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, @builder.raw_result
end

def test_image_with_metric
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1)
Expand Down
Loading