NAME
dtRdr::Book::ThoutBook_1_0::Base - shared stuff
SYNOPSIS
Constructor
new
my $book = dtRdr::Book::ThoutBook_1_0_subclass->new();
Methods
set_id
URI-escapes the id because Thout1.0 books didn't have a proper ID.
$book->set_id($id);
_id_escape
$id = $self->_id_escape($id);
set_base_dir
$book->set_base_dir($dir);
find_toc
Overrides the dtRdr::Book method.
This is needed because Thout 1.0 implements a showpage instruction (a pseudo goto) and because loading a render="false" *root* node renders the first child.
my $toc = $book->find_toc($id);
set_xml_content
$self->set_xml_content($string);
setup_metadata
my $meta = $self->setup_metadata;
reduce_word_scope
Returns a Range with the appropriate TOC node and start/end positions (in cache-coordinates.)
my $range = $book->reduce_word_scope($node, $start, $end);
In our case, this involves checking each node along the way to ensure that we properly account for holes (renderchildren=0s' children and render=0s are holes.)
_RP_to_NP
Translate a rendered position to a node position.
$self->_RP_to_NP($node, $pos);
_NP_to_RP
Translate the node position to a rendered position.
my $render_pos = $self->_NP_to_RP($node, $node_position);
_node_holes
Gets the holes (nonrendered children) for a node. @holes will be a list of [$global_start, $global_stop] array-ref pairs.
my @holes = $self->_node_holes($node);
Node Relations
Our rendered structure does not map directly onto the TOC structure.
We have to handle:
showpage - does nothing except give a different response for find_toc() -- therefore we ignore it in all node relations
render=0 - trim yourself
render="parent" - trim yourself
render_children=0 - trim all your children
root node - is a switcharoo to its first child when render=false
descendant_nodes
my @nodes = $book->descendant_nodes($node);
render_children=0 - stop descending
render=0 - bye
showpage - not an issue
ancestor_nodes
Returns the node's ancestors, taking into account whether this node or one of it's parents is a hole.
my @nodes = $book->ancestor_nodes($node);
TOC handling
build_toc
Run through a sax parse to build-up a TOC tree and memorize some byte offsets and character positions.
$self->build_toc or die;
_get_toc_handlers
Gets the SAX parser handler subs.
my $data = $self->_get_toc_handlers(build_aot => 1);
$parser->setHandlers(%{$data->{handlers}});
Options:
build_aot BOOL
Build the Annotation Offset Table. This will end up in the $toc as word_start/word_end values if it succeeds. The parse should die if it fails.
TODO This really isn't an option -- if the book needs to place annotations it is required.
_load_cached_toc
$self->_load_cached_toc;
whitespace_before
$book->whitespace_before($node);
get_content_by_id
Get the content for the $id (ala find_toc()
.)
my $content = $book->get_content_by_id($id);
get_content
Gets trimmed, wrapped, and NBH'd content.
my $content = $book->get_content($toc);
get_trimmed_content
my $xml = $self->get_trimmed_content($toc);
_build_trim_plan
@plan = $self->_build_trim_plan($node);
_append_trim_plan
$self->_append_trim_plan($start, $stop, \@plan);
get_copy_content
$book->get_copy_content($toc);
get_raw_content
$book->get_raw_content($toc);
url_for
$book->url_for($toc);
HTML formatting
TODO rework these
_fancy_html_lead
$content = $self->_fancy_html_lead;
_html_lead
$self->_html_lead;
_html_tail
$self->_html_tail;
TOC-related Methods
These methods contain the rendering-order logic for this type of book. Goto and redirect constructs make this slightly different than the purely structural ordering of the TOC object.
next_node
Return the TOC object for the (linearly) next node. If there is none, returns undef.
my $next = $book->next_node($toc);
prev_node
Return the TOC object for the (linearly) previous node.
my $prev = $book->prev_node($toc);
searcher
Returns a subref for the quicksearch (first-pass.) See dtRdr::Search::Book for details.
my $subref = $book->searcher($regexp);
AUTHOR
Eric Wilhelm <ewilhelm at cpan dot org>
http://scratchcomputing.com/
COPYRIGHT
Copyright (C) 2006 Eric L. Wilhelm and OSoft, All Rights Reserved.
NO WARRANTY
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
LICENSE
The dotReader(TM) is OSI Certified Open Source Software licensed under the GNU General Public License (GPL) Version 2, June 1991. Non-encrypted and encrypted packages are usable in connection with the dotReader(TM). The ability to create, edit, or otherwise modify content of such encrypted packages is self-contained within the packages, and NOT provided by the dotReader(TM), and is addressed in a separate commercial license.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.