File: insert_section_after.rb

package info (click to toggle)
ruby-prawn 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,936 kB
  • ctags: 802
  • sloc: ruby: 13,906; sh: 43; makefile: 15
file content (47 lines) | stat: -rw-r--r-- 1,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
# encoding: utf-8
#
# Another way to insert nodes into an existing outline is the
# <code>insert_section_after</code> method.
#
# It accepts the title of the node that the new section will go after and a
# block declaring the new section.
#
# As is the case with <code>add_subsection_to</code> the section added
# doesn't need to be a section, it may be just a page.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  # First we create 10 pages and some default outline
  (1..10).each do |index|
    text "Page #{index}"
    start_new_page
  end

  outline.define do
    section("Section 1", :destination => 1) do
      page :title => "Page 2", :destination => 2
      page :title => "Page 3", :destination => 3
    end
  end

  # Now we will start adding nodes to the previous outline
  outline.insert_section_after("Page 2") do
    outline.section("Section after Page 2") do
      outline.page :title => "Page 4", :destination => 4
    end
  end

  outline.insert_section_after("Section 1") do
    outline.section("Section after Section 1") do
      outline.page :title => "Page 5", :destination => 5
    end
  end

  # Adding just a page
  outline.insert_section_after("Page 3") do
    outline.page :title => "Page after Page 3", :destination => 6
  end
end