Module: Prawn::Grouping

Defined in:
lib/prawn/grouping.rb,
lib/prawn/grouping/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#group(options = {}, &b) ⇒ Object

Groups a given block vertiacally within the current context, if possible.

Parameters are:

options

A hash for grouping options.

:too_tall

A proc called before the content is rendered and does not fit a single context.

:fits_new_context

A proc called before the content is rendered and does fit a single context.

:fits_current_context

A proc called before the content is rendered and does fit context.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/prawn/grouping.rb', line 19

def group(options = {}, &b)
  too_tall             = options[:too_tall]
  fits_new_context     = options[:fits_new_context]
  fits_current_context = options[:fits_current_context]

  # create a temporary document with current context and offset
  pdf = create_box_clone
  pdf.y = y
  pdf.instance_exec pdf, &b

  if pdf.page_count > 1
    # create a temporary document without offset
    pdf = create_box_clone
    pdf.instance_exec pdf, &b

    if pdf.page_count > 1
      # does not fit new context
      too_tall.call if too_tall
      b.call(self)
    else
      fits_new_context.call if fits_new_context
      bounds.move_past_bottom
      b.call(self)
    end
    return false
  else
    # just render it
    fits_current_context.call if fits_current_context
    b.call(self)
    return true
  end
end