### Home Classes Methods

### In Files

- lib/prawn/outline.rb

### Parent

Object

### Methods

- ::new
- #add_subsection_to
- #define
- #insert_section_after
- #page
- #section
- #update

### Files

- COPYING
- GPLv2
- GPLv3
- LICENSE

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Core
- Prawn::Core::Page
- Prawn::Core::Page::GraphicsState
- Prawn::Core::Reference
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::Internals
- Prawn::Document::PageGeometry
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::GraphicState
- Prawn::GraphicStateStack
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::Gradient
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::Images
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Layout
- Prawn::Measurements
- Prawn::Outline
- Prawn::Stamp
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Arcfour
- Numeric

No matching classes.

# Prawn::Outline

The Outline class organizes the outline tree items for the document. Note that the prev and parent instance variables are adjusted while navigating through the nested blocks. These variables along with the presence or absense of blocks are the primary means by which the relations for the various OutlineItems and the OutlineRoot are set. Unfortunately, the best way to understand how this works is to follow the method calls through a real example.

Some ideas for the organization of this class were gleaned from name_tree. In particular the way in which the OutlineItems are finally rendered into document objects in PdfObject through a hash.

### Attributes

document[RW]
items[RW]
parent[RW]
prev[RW]

### Public Class Methods

new(document) click to toggle source

    # File lib/prawn/outline.rb, line 41
    def initialize(document)
      @document = document
      @parent = root
      @prev = nil
      @items = {}
    end

### Public Instance Methods

add_subsection_to(title, position = :last, &block) click to toggle source

Inserts an outline section to the outline tree (see outlinedefine). Although you will probably choose to exclusively use outlinedefine so that your outline tree is contained and easy to manage, this method gives you the option to insert sections to the outline tree at any point during document generation. This method allows you to add a child subsection to any other item at any level in the outline tree. Currently the only way to locate the place of entry is with the title for the item. If your title names are not unique consider using define_outline. The method takes the following arguments:

    title: a string that must match an outline title to add the subsection to
    position: either :first or :last(the default) where the subsection will be placed relative
       to other child elements. If you need to position your subsection in between
       other elements then consider using #insert_section_after
    block: uses the same DSL syntax as outline#define, for example:

Consider using this method inside of outline.update if you want to have the outline object to be scoped as self (see insert_section_after example).

    go_to_page 2
    start_new_page
    text "Inserted Page"
    outline.add_subsection_to :title => 'Page 2', :first do
      outline.page :destination => page_number, :title => "Inserted Page"
    end

    # File lib/prawn/outline.rb, line 107
    def add_subsection_to(title, position = :last, &block)
      @parent = items[title]
      raise Prawn::Errors::UnknownOutlineTitle,
        "\n No outline item with title: '#{title}' exists in the outline tree" unless @parent
      @prev = position == :first ? nil : @parent.data.last
      nxt = position == :first ? @parent.data.first : nil
      insert_section(nxt, &block)
    end

define(&block) click to toggle source

Defines/Updates an outline for the document. The outline is an optional nested index that appears on the side of a PDF document usually with direct links to pages. The outline DSL is defined by nested blocks involving two methods: section and page; see the documentation on those methods for their arguments and options. Note that one can also use outlineupdate to add more sections to the end of the outline tree using the same syntax and scope.

The syntax is best illustrated with an example:

Prawn::Document.generate(outlined_document.pdf) do

    text "Page 1. This is the first Chapter. "
    start_new_page
    text "Page 2. More in the first Chapter. "
    start_new_page
    outline.define do
      section 'Chapter 1', :destination => 1, :closed => true do
        page :destination => 1, :title => 'Page 1'
        page :destination => 2, :title => 'Page 2'
      end
    end
    start_new_page do
    outline.update do
      section 'Chapter 2', :destination =>  2, do
        page :destination => 3, :title => 'Page 3'
      end
    end

end

    # File lib/prawn/outline.rb, line 76
    def define(&block)
      instance_eval(&block)  if block
    end

Also aliased as: update
insert_section_after(title, &block) click to toggle source

Inserts an outline section to the outline tree (see outlinedefine). Although you will probably choose to exclusively use outlinedefine so that your outline tree is contained and easy to manage, this method gives you the option to insert sections to the outline tree at any point during document generation. Unlike outline.add_section, this method allows you to enter a section after any other item at any level in the outline tree. Currently the only way to locate the place of entry is with the title for the item. If your title names are not unique consider using define_outline. The method takes the following arguments:

    title: the title of other section or page to insert new section after
    block: uses the same DSL syntax as outline#define, for example:

    go_to_page 2
    start_new_page
    text "Inserted Page"
    update_outline do
      insert_section_after :title => 'Page 2' do
        page :destination => page_number, :title => "Inserted Page"
      end
    end

    # File lib/prawn/outline.rb, line 137
    def insert_section_after(title, &block)
      @prev = items[title]
      raise Prawn::Errors::UnknownOutlineTitle,
        "\n No outline item with title: '#{title}' exists in the outline tree" unless @prev
      @parent = @prev.data.parent
      nxt = @prev.data.next
      insert_section(nxt, &block)
    end

page(options = {}) click to toggle source

See Outline#define above for more documentation on how it is used in that context

Adds a page to the outline. Although you will probably choose to exclusively use outlinedefine so that your outline tree is contained and easy to manage, this method also gives you the option to add pages to the root of outline tree at any point during document generation. Note that the page will be added at the top level after the other root outline elements. For more flexible placement try using outlineinsert_section_after and/or outlineadd_subsection_to.

Takes the following arguments:

    options:
           title - REQUIRED. The outline text that appears for the page.
           destination - integer defining the page number for the destination link.
             currently only :FIT destination supported with link to top of page.
           closed - whether the section should show its nested outline elements.
                  - defaults to false.

example usage:

    outline.page :title => "Very Last Page"

Note: this method is almost identical to section except that it does not accept a block thereby defining the outline item as a leaf on the outline tree structure.

    # File lib/prawn/outline.rb, line 195
    def page(options = {})
      if options[:title]
        title = options[:title]
      else
        raise Prawn::Errors::RequiredOption,
          "\nTitle is a required option for page"
      end
      add_outline_item(title, options)
    end

section(title, options = {}, &block) click to toggle source

See outlinedefine above for documentation on how this is used in that context

Adds an outine section to the outline tree. Although you will probably choose to exclusively use outlinedefine so that your outline tree is contained and easy to manage, this method gives you the option to add sections to the outline tree at any point during document generation. When not being called from within another section block the section will be added at the top level after the other root elements of the outline. For more flexible placement try using outlineinsert_section_after and/or outlineadd_subsection_to Takes the following arguments:

    title: the outline text that appears for the section.
    options: destination - optional integer defining the page number for a destination link.
                  - currently only :FIT destination supported with link to top of page.
             closed - whether the section should show its nested outline elements.
                    - defaults to false.
             block: more nested subsections and/or page blocks

example usage:

    outline.section 'Added Section', :destination => 3 do
      outline.page :destionation => 3, :title => 'Page 3'
    end

    # File lib/prawn/outline.rb, line 169
    def section(title, options = {}, &block)
      add_outline_item(title, options, &block)
    end

update(&block) click to toggle source
Alias for: define

[Validate]

Generated with the Darkfish Rdoc Generator 2.