summaryrefslogtreecommitdiff
path: root/spec/open_spec.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-02-25 17:41:09 -0700
committerDan Allen <dan.j.allen@gmail.com>2022-04-05 13:43:18 -0600
commitd356798f25b0f93e4442e0879f8c511d6023bbe0 (patch)
treed18351b6331ed8d1fd595fde9a8ad2b726f460fd /spec/open_spec.rb
parenta87db305bb962323f9957b4dd0169bd93baa7be2 (diff)
resolves #2003 compute extent of content in scratch document to arrange content block in primary document
* introduce arrange_block helper to handle positioning content block in primary document * reimplement new dry_run to compute the extent and start position of the content block instead of just the height * stop rendering at page boundary in scratch document when computing start position of content block to avoid unnecessary work * ensure that caption stays with start of content block when arranging content block * prevent arrange_block from starting content block on page when no content from block fits on that page * avoid converting content that overruns page in AsciiDoc table cell in scratch document * encapsulate push/pop scratch in arrange_block * add tests for the arrange_block helper * prevent nested breakable blocks from flowing beyond first page when performing on single page only * switch dry_run method to accept keyword arguments * avoid arrange_block when converting open block when possible * include negative tests for image taller than page at top of block * verify borders and backgrounds are not drawn in scratch document * add test to verify behavior of stop_if_first_page_empty * include sanity check before drawing background and border over extent * add rdoc to dry_run and arrange_block help methods * reuse computed extent as TOC extent * remove unused code * raise error if table caption does not fit on single page * add test that footnotes are not pushed down if height exceeds height of page
Diffstat (limited to 'spec/open_spec.rb')
-rw-r--r--spec/open_spec.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/open_spec.rb b/spec/open_spec.rb
index d24b5e24..2f790751 100644
--- a/spec/open_spec.rb
+++ b/spec/open_spec.rb
@@ -3,6 +3,23 @@
require_relative 'spec_helper'
describe 'Asciidoctor::PDF::Converter - Open' do
+ it 'should be breakable by default', breakable: true do
+ with_content_spacer 10, 720 do |spacer_path|
+ pdf = to_pdf <<~EOS, analyze: true
+ image::#{spacer_path}[]
+
+ --
+ first page
+
+ second page
+ --
+ EOS
+ (expect pdf.pages).to have_size 2
+ (expect (pdf.find_unique_text 'first page')[:page_number]).to be 1
+ (expect (pdf.find_unique_text 'second page')[:page_number]).to be 2
+ end
+ end
+
it 'should keep block together when it has the unbreakable option', visual: true do
to_file = to_pdf_file <<~EOS, 'open-unbreakable-option-fit.pdf'
Make it rain.footnote:[money]
@@ -86,4 +103,52 @@ describe 'Asciidoctor::PDF::Converter - Open' do
(expect (pdf.find_unique_text 'content')[:page_number]).to be 2
(expect (pdf.find_unique_text 'Title')[:page_number]).to be 2
end
+
+ it 'should not dry run block unless necessary' do
+ calls = []
+ extensions = proc do
+ block :spy do
+ on_context :paragraph
+ process do |parent, reader, attrs|
+ block = create_paragraph parent, reader.lines, attrs
+ block.instance_variable_set :@_calls, calls
+ block.extend (Module.new do
+ def content
+ @_calls << (caller.join ?\n) if document.converter.scratch? # rubocop:disable RSpec/InstanceVariable
+ super
+ end
+ end)
+ end
+ end
+ end
+
+ {
+ '' => false,
+ %(.title) => false,
+ %([#idname]) => false,
+ %([%unbreakable]) => false,
+ %(before\n) => false,
+ %(before\n\n.title) => true,
+ %(before\n\n[#idname]) => true,
+ %(before\n\n[%unbreakable]) => true,
+ }.each do |before_block, dry_run|
+ input = <<~EOS.lstrip
+ #{before_block}
+ --
+ #{['block content'] * 4 * %(\n\n)}
+
+ [spy]
+ block content
+ --
+ EOS
+ pdf = to_pdf input, extensions: extensions, analyze: true
+ (expect pdf.pages).to have_size 1
+ (expect (pdf.find_text 'block content')[0][:page_number]).to be 1
+ if dry_run
+ (expect calls).not_to be_empty
+ else
+ (expect calls).to be_empty
+ end
+ end
+ end
end