summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarat Radchenko <marat@slonopotamus.org>2020-02-19 00:50:22 +0300
committerMarat Radchenko <marat@slonopotamus.org>2020-02-19 00:52:20 +0300
commit76dc5a62369ee0f32757de7a741b40a00a7254d8 (patch)
tree7324f3b9209a0092168ba3ccc74ad5d826dbb9cc
parentdbc49ec1a67c359d60190d8b9c235b4a0d307d9b (diff)
fix logging to work through logger
fix front matter files to be actually added to spine (and test that) fix image data not being included into epub
-rw-r--r--lib/asciidoctor-epub3/converter.rb8
-rw-r--r--spec/converter_spec.rb26
-rw-r--r--spec/fixtures/front-matter-multi/book.adoc4
-rw-r--r--spec/fixtures/front-matter-multi/chapter.adoc1
-rw-r--r--spec/fixtures/front-matter/book.adoc3
-rw-r--r--spec/fixtures/front-matter/chapter.adoc1
6 files changed, 25 insertions, 18 deletions
diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb
index 0221ac3..d1ea8e5 100644
--- a/lib/asciidoctor-epub3/converter.rb
+++ b/lib/asciidoctor-epub3/converter.rb
@@ -1185,14 +1185,14 @@ body > svg {
fmglob = 'front-matter.*\.html'
fm_path = File.join workdir, fmdir
unless Dir.exist? fm_path
- warn %(Directory specified by 'epub3-frontmattderdir' doesn't exist! Ignoring ...)
+ logger.warn %(#{File.basename doc.attr('docfile')}: directory specified by 'epub3-frontmattderdir' doesn't exist! Ignoring ...)
return []
end
fms = Dir.entries(fm_path).delete_if {|x| !x.match fmglob }.sort.map {|y| File.join fm_path, y }
if fms && !fms.empty?
fms
else
- warn %(Directory specified by 'epub3-frontmattderdir' contains no suitable files! Ignoring ...)
+ logger.warn %(#{File.basename doc.attr('docfile')}: directory specified by 'epub3-frontmattderdir' contains no suitable files! Ignoring ...)
[]
end
elsif File.exist? File.join workdir, 'front-matter.html'
@@ -1210,11 +1210,11 @@ body > svg {
front_matter_content = ::File.read front_matter
front_matter_file = File.basename front_matter, '.html'
- item = @book.add_item "#{front_matter_file}.xhtml", content: (postprocess_xhtml front_matter_content)
+ item = @book.add_ordered_item "#{front_matter_file}.xhtml", content: (postprocess_xhtml front_matter_content)
item.add_property 'svg' if SvgImgSniffRx =~ front_matter_content
front_matter_content.scan ImgSrcScanRx do
- @book.add_item $1
+ @book.add_item $1, content: File.join(File.dirname(front_matter), $1)
end
end
diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb
index ceb6bae..ea872ca 100644
--- a/spec/converter_spec.rb
+++ b/spec/converter_spec.rb
@@ -47,21 +47,31 @@ describe Asciidoctor::Epub3::Converter do
it 'adds front matter page with images' do
book, = to_epub 'front-matter/book.adoc'
- front_matter = book.item_by_href 'front-matter.xhtml'
+ spine = book.spine.itemref_list
+ expect(spine).to have_size(2)
+
+ front_matter = book.items[spine[0].idref]
expect(front_matter).not_to be_nil
+ expect(front_matter.href).to eq('front-matter.xhtml')
expect(front_matter.content).to include 'Matter. Front Matter.'
expect(book).to have_item_with_href 'square.png'
end
it 'adds multiple front matter page with images' do
- book, = to_epub 'front-matter-multi/book.adoc', attributes: { 'epub3-frontmatterdir' => 'fm' }
- front_matter = book.item_by_href 'front-matter.1.xhtml'
- expect(front_matter).not_to be_nil
- expect(front_matter.content).to include 'Matter. Front Matter.'
+ book, = to_epub 'front-matter-multi/book.adoc'
+ spine = book.spine.itemref_list
+ expect(spine).to have_size(3)
+
+ front_matter_1 = book.items[spine[0].idref]
+ expect(front_matter_1).not_to be_nil
+ expect(front_matter_1.href).to eq('front-matter.1.xhtml')
+ expect(front_matter_1.content).to include 'Matter. Front Matter.'
expect(book).to have_item_with_href 'square.png'
- front_matter = book.item_by_href 'front-matter.2.xhtml'
- expect(front_matter).not_to be_nil
- expect(front_matter.content).to include 'Matter. Front Matter. 2'
+
+ front_matter_2 = book.items[spine[1].idref]
+ expect(front_matter_2).not_to be_nil
+ expect(front_matter_2.href).to eq('front-matter.2.xhtml')
+ expect(front_matter_2.content).to include 'Matter. Front Matter. 2'
expect(book).to have_item_with_href 'square_blue.png'
end
diff --git a/spec/fixtures/front-matter-multi/book.adoc b/spec/fixtures/front-matter-multi/book.adoc
index 46560c6..b11f14a 100644
--- a/spec/fixtures/front-matter-multi/book.adoc
+++ b/spec/fixtures/front-matter-multi/book.adoc
@@ -1,4 +1,4 @@
= Front matter book
-:doctype: book
+:epub3-frontmatterdir: fm
-include::chapter.adoc[leveloffset=+1]
+Nothing to see here.
diff --git a/spec/fixtures/front-matter-multi/chapter.adoc b/spec/fixtures/front-matter-multi/chapter.adoc
deleted file mode 100644
index 31b7fa2..0000000
--- a/spec/fixtures/front-matter-multi/chapter.adoc
+++ /dev/null
@@ -1 +0,0 @@
-= Chapter
diff --git a/spec/fixtures/front-matter/book.adoc b/spec/fixtures/front-matter/book.adoc
index 46560c6..fa1291c 100644
--- a/spec/fixtures/front-matter/book.adoc
+++ b/spec/fixtures/front-matter/book.adoc
@@ -1,4 +1,3 @@
= Front matter book
-:doctype: book
-include::chapter.adoc[leveloffset=+1]
+Nothing to see here.
diff --git a/spec/fixtures/front-matter/chapter.adoc b/spec/fixtures/front-matter/chapter.adoc
deleted file mode 100644
index 31b7fa2..0000000
--- a/spec/fixtures/front-matter/chapter.adoc
+++ /dev/null
@@ -1 +0,0 @@
-= Chapter