File: paragraph_indentation.rb

package info (click to toggle)
ruby-prawn 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,220 kB
  • ctags: 826
  • sloc: ruby: 14,469; sh: 43; makefile: 18
file content (33 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download
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
# encoding: utf-8
#
# Prawn strips all whitespace from the beginning and the end of strings so there
# are two ways to indent paragraphs:
#
# One is to use non-breaking spaces which Prawn won't strip. One shortcut to
# using them is the <code>Prawn::Text::NBSP</code>.
#
# The other is to use the <code>:indent_paragraphs</code> option with the text
# methods. Just pass a number with the space to indent the first line in each
# paragraph.
#
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
  # Using non-breaking spaces
  text " " * 10 + "This paragraph won't be indented. " * 10 +
       "\n#{Prawn::Text::NBSP * 10}" + "This one will with NBSP. " * 10

  move_down 20
  text "This paragraph will be indented. " * 10 +
       "\n" + "This one will too. " * 10,
       :indent_paragraphs => 60

  move_down 20

  text "FROM RIGHT TO LEFT:"
  text "This paragraph will be indented. " * 10 +
       "\n" + "This one will too. " * 10,
       :indent_paragraphs => 60, :direction => :rtl
end