Shlomi Fish > HTML-TabbedExamples-Generate-0.0.3 > HTML::TabbedExamples::Generate

Download:
HTML-TabbedExamples-Generate-0.0.3.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.0.3   Source  

NAME ^

HTML::TabbedExamples::Generate - generate syntax-highlighted examples for codes with a markup compatible with jQueryUI's tab widgets.

SYNOPSIS ^

        use HTML::TabbedExamples::Generate;

        use strict;
        use warnings;

        # Examples generator:
        my $ex_gen = HTML::TabbedExamples::Generate->new(
            {
                default_syntax => 'perl',
            }
        );

        print $ex_gen->html_with_title(
            {
                title => "Copying a file",
                id_base => "copying_a_file",
                examples =>
                [
                    {
                        id => "io_all",
                        label => "IO-All",
                        code => <<'EOF',
        use IO::All;

        my ($source_filename, $dest_filename) = @_;
        io->file($source_filename) > io->file($dest_filename);
        EOF

                    },
                    {
                        id => "core",
                        label => "Core Perl",
                        code => <<'EOF',
        use File::Copy qw(copy);

        my ($source_filename, $dest_filename) = @_;

        copy($source_filename, $dest_filename);
        EOF
                    },
                ],
            }
        );

        print $ex_gen->html_with_title(
            {
                title => "Overwriting a file with text",
                id_base => "overwrite_a_file",
                examples =>
                [
                    {
                        id => "io_all",
                        label => "IO-All",
                        code => <<'EOF',
        use IO::All;

        io->file("output.txt")->utf8->print("Hello World!\n");
        EOF

                    },
                    {
                        id => "core",
                        label => "Core Perl",
                        code => <<'EOF',
        use autodie;

        open my $out, '>:encoding(utf8)', "output.txt";
        print {$out} "Hello World!\n";
        close($out);
        EOF
                    },
                ],
            }
        );

METHODS ^

my $obj = HTML::TabbedExamples::Generate->new({ default_syntax => "perl", main_pre_css_classes => [qw( code my_example1 )]})

Returns a new object with a default_syntax for the examples, and some classes to add for the main pre tag. Default 'main_pre_css_classes' value is only the class 'code'.

my $html_markup_string = $obj->render({ examples => \@examples, id_base => 'my_example_id'})

Renders some examples. 'id_base' is the prefix to prepend to the classes’ IDs. 'examples' points to an array-ref of examples, which are hash-refs cotnaining:

my $html_markup_string = $obj->html_with_title({ title => 'My title to escape', %ARGS })

Same arguments as render() with the addition of 'title' which is a title to be placed inside an <h3>..</h3> tag, which will be escaped. Returns the complete markup.

syntax highlighting: