Text::Format provides the ability to nicely
format fixed-width text with knowledge of the writeable space (number of
columns), margins, and indentation settings.
Copyright:
Copyright (c) 2002 - 2003 by Austin Ziegler
Version:
0.61
Based On:
Perl Text::Format,
Copyright (c) 1998 Gábor Egressy
Licence:
Ruby's, Perl Artistic, or GPL version 2 (or later)
The number of spaces to indent all lines after the first line of a
paragraph.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin INDENT text is formatted into here right margin
The total width of the format area. The margins, indentation, and text are
formatted into this space.
COLUMNS
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin indent text is formatted into here right margin
The number of spaces to indent the first line of a paragraph.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin INDENT text is formatted into here right margin
Normally, words larger than the format area will be placed on a line by
themselves. Setting this to true will force words larger than the
format area to be split into one or more "words" each at most the
size of the format area. The first line and the original word will be
placed into #split_words. Note that this will cause the output to
look similar to a #format_style of JUSTIFY. (Lines will be filled as
much as possible.)
The object responsible for hyphenating. It must respond to #hyphenate_to(word, size) and return an
array of the word hyphenated into two parts. The size is the MAXIMUM size
permitted, including any hyphenation marks.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
LEFT MARGIN indent text is formatted into here right margin
A hash which holds the regular expressions on which spaces should not be
broken. The hash is set up such that the key is the first word and the
value is the second word.
For example, if nobreak_regex contains the following hash:
Then "Mr. Jones", "Mrs. Jones", and "Jones
Jr." would not be broken. If this simple matching algorithm indicates
that there should not be a break at the current end of line, then a
backtrack is done until there are two words on which line breaking is
permitted. If two such words are not found, then the end of the line will
be broken regardless. If there is a single word on the current line,
then no backtrack is done and the word is stuck on the end.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin indent text is formatted into here RIGHT MARGIN
Specifies the split mode; used only when #hard_margins is set to
true. Allowable values are:
SPLIT_FIXED
The word will be split at the number of characters needed, with no marking
at all.
repre
senta
ion
SPLIT_CONTINUATION
The word will be split at the number of characters needed, with a C-style
continuation character. If a word is the only item on a line and it cannot
be split into an appropriate size, SPLIT_FIXED will be used.
repr # esen # tati # on
SPLIT_HYPHENATION
The word will be split according to the hyphenator specified in
#hyphenator. If there is no #hyphenator specified, works like
SPLIT_CONTINUATION. The example is using TeX::Hyphen. If a word is the only
item on a line and it cannot be split into an appropriate size,
SPLIT_CONTINUATION mode will be used.
The array of text to be placed before each paragraph when
#tag_paragraph is true. When #format() is called, only the first
element of the array is used. When #paragraphs is called, then each entry
in the array will be used once, with corresponding paragraphs. If the tag
elements are exhausted before the text is exhausted, then the remaining
paragraphs will not be tagged. Regardless of indentation settings, a blank
line will be inserted between all paragraphs when #tag_paragraph
is true.
The text to be manipulated. Note that value is optional, but if the
formatting functions are called without values, this text is what will be
formatted.
This constructor takes advantage of a technique for Ruby object
construction introduced by Andy Hunt and Dave Thomas (see reference), where
optional values are set using commands in a block.
As shown above, arg is optional. If arg is specified and
is a String, then arg is used as the default value of
#text. Alternately, an existing Text::Format object can be used or a Hash can be
used. With all forms, a block can be specified.
Compares two Text::Format objects. All settings
of the objects are compared except #hyphenator. Generated results
(e.g., #split_words) are not compared, either.
The total width of the format area. The margins, indentation, and text are
formatted into this space. The value provided is silently converted to a
positive integer.
COLUMNS
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin indent text is formatted into here right margin
The number of spaces used for the left margin. The value provided is
silently converted to a positive integer value.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
LEFT MARGIN indent text is formatted into here right margin
The number of spaces used for the right margin. The value provided is
silently converted to a positive integer value.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin indent text is formatted into here RIGHT MARGIN
The number of spaces to indent the first line of a paragraph. The value
provided is silently converted to a positive integer value.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin INDENT text is formatted into here right margin
The number of spaces to indent all lines after the first line of a
paragraph. The value provided is silently converted to a positive integer
value.
columns
<-------------------------------------------------------------->
<-----------><------><---------------------------><------------>
left margin INDENT text is formatted into here right margin
The object responsible for hyphenating. It must respond to #hyphenate_to(word, size) and return an
array of the word hyphenated into two parts. The size is the MAXIMUM size
permitted, including any hyphenation marks.
Specifies the split mode; used only when #hard_margins is set to
true. Allowable values are:
SPLIT_FIXED
The word will be split at the number of characters needed, with no marking
at all.
repre
senta
ion
SPLIT_CONTINUATION
The word will be split at the number of characters needed, with a C-style
continuation character.
repr # esen # tati # on
SPLIT_HYPHENATION
The word will be split according to the hyphenator specified in
#hyphenator. If there is no #hyphenator specified, works like
SPLIT_CONTINUATION. The example is using TeX::Hyphen as the #hyphenator.
rep-
re-
sen-
ta-
tion
These values can be bitwise ORed together (e.g., SPLIT_FIXED |
SPLIT_CONTINUATION) to provide fallback split methods. In the example
given, an attempt will be made to split the word using the rules of
SPLIT_CONTINUATION; if there is not enough room, the word will be split
with the rules of SPLIT_FIXED. These combinations are also available as the
following values:
Formats text into a nice paragraph format. The text is separated into words
and then reassembled a word at a time using the settings of this Format object. If a word is larger than the number
of columns available for formatting, then that word will appear on the line
by itself.
If to_wrap is nil, then the value of #text will
be worked on.
Considers each element of text (provided or internal) as a paragraph. If
#first_indent is the same as #body_indent, then
paragraphs will be separated by a single empty line in the result;
otherwise, the paragraphs will follow immediately after each other. Uses
#format to do the heavy lifting.