NAME

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

VERSION

version 0.2.1

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:

  • label

    The tab's label.

  • no_syntax

    If true, disable syntax highlighting.

  • syntax

    If true, override the default_syntax

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.

SUPPORT

Websites

The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-html-tabbedexamples-generate at rt.cpan.org, or through the web interface at https://rt.cpan.org/Public/Bug/Report.html?Queue=HTML-TabbedExamples-Generate. You will be automatically notified of any progress on the request by the system.

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/shlomif/perl-html-tabbedexamples-generate

git clone git://github.com/shlomif/perl-html-tabbedexamples-generate.git

AUTHOR

Shlomi Fish <shlomif@cpan.org>

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/shlomif/perl-html-tabbedexamples-generate/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Shlomi Fish.

This is free software, licensed under:

The MIT (X11) License