NAME
Pod::POM::View::Restructured - View for Pod::POM that outputs reStructuredText
SYNOPSIS
use Pod::POM::View::Restructured;
my $view = Pod::POM::View::Restructured->new;
my $parser = Pod::POM->new;
my $pom = $parser->parse_file("$top_dir/lib/Pod/POM/View/Restructured.pm");
my $out = $pom->present($view);
DESCRIPTION
This module outputs reStructuredText that is expected to be used with Sphinx. Verbatim sections (indented paragraphs) in the POD will be output with syntax hilighting for Perl code by default. See "POD commands specifically for reStructuredText" for how to change this for a particular block.
METHODS
new()
Constructor.
convert_file($source_file, $title, $dest_file)
Converts the POD in $source_file
to reStructuredText. If $dest_file
is defined, it writes the output there. If $title
is defined, it is used for the title of the document. Otherwise, an attempt is made to infer the title from the NAME section (checks if the body looks like /\A\s*(\w+(?:::\w+)+)\s+-\s+/s
).
Returns the output as a string.
$source_file
and $dest_file
can be either file names or file handles.
convert_files($file_spec, $index_file, $index_title, $out_dir)
Converts the files given in $file_spec
to reStructuredText. If $index_file
is provided, it is the path to the index file to be created (with a table of contents pointing to all of the files created). If $index_title
is provided, it is used as the section title for the index file. $out_dir
is the directory the generated files will be written to.
$file_spec
is a reference to an array of hashes specifying attributes for each file to be converted. The valid keys are:
source_file
-
File to convert.
dest_file
-
File to output the reStructuredText. If not provided, a file name will be generated based on the title.
title
-
Section title for the generated reStructuredText. If not provided, an attempt will be made to infer the title from the NAME section in the POD, if it exists. As a last resort, a title will be generated that looks like "section_(\d+)".
my $conv = Pod::POM::View::Restructured->new;
my $files = [
{ source_file => "$base_dir/Restructured.pm" },
{ source_file => "$base_dir/DWIW.pm" },
{ source_file => "$base_dir/Wrapper.pm" },
];
my $rv = $conv->convert_files($files, "$dest_dir/index.rst", 'My Big Test', $dest_dir);
POD commands specifically for reStructuredText
The following sequences can be used in POD to request actions specifically for this module.
=for pod2rst next-code-block: lang
This sets up the next verbatim section, i.e., the next indented paragraph to be hilighted according to the syntax of the programming/markup/config language lang. Verbatim sections are assumed to be Perl code by default. Sphinx uses Pygments to do syntax hilighting in these sections, so you can use any value for lang that Pygments supports, e.g., Python, C, C++, Javascript, SQL, etc.
EXAMPLES
Need to document:
TODO
- code hilighting
-
Currently, a verbatim block (indented paragraph) gets output as a Perl code block by default in reStructuredText. There should be an option (e.g., in the constructor) to change the language for hilighting purposes (for all verbatim blocks), or disable syntax hilighting and just make it a preformatted paragraph. There is a way to do this in POD (see "POD commands specifically for reStructuredText"), but there should also be an option in the constructor.
- improve escaping
-
Text blocks are not escaped properly, so it is currently possible to invoke a command in reStructuredText by accident.
DEPENDENCIES
Inherits from Pod::POM::View::Text that comes with the Pod::POM distribution.
AUTHOR
Don Owens <don@regexguy.com>
LICENSE AND COPYRIGHT
Copyright (c) 2010 Don Owens <don@regexguy.com>. All rights reserved.
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
SEE ALSO
pod2rst (distributed with Pod::POM::View::HTML)
reStructuredText: http://docutils.sourceforge.net/rst.html
Sphinx (uses reStructuredText): http://sphinx.pocoo.org/
Pygments (used by Sphinx for syntax highlighting): http://pygments.org/
VERSION
0.01