NAME

Tags::HTML::Messages - Tags helper for HTML messages.

SYNOPSIS

use Tags::HTML::Messages;

my $obj = Tags::HTML::Messages->new(%params);
$obj->process($message_ar);
$obj->process_css($type, $color);

METHODS

new

my $obj = Tags::HTML::Messages->new(%params);

Constructor.

  • css

    'CSS::Struct::Output' object for process_css processing.

    Default value is undef.

  • css_messages

    CSS class for main messages div block.

    Default value is 'messages'.

  • tags

    'Tags::Output' object.

    Default value is undef.

process

$obj->process($message_ar);

Process Tags structure for output.

Reference to array with message objects $message_ar must be a instance of Data::Message::Simple object.

Returns undef.

process_css

$obj->process_css($type, $color);

Process CSS::Struct structure for output.

Variable $type is string which define message type. Possible values are info and error now. Types are defined in Data::Message::Simple.

Returns undef.

ERRORS

new():
        From Class::Utils::set_params():
                Unknown parameter '%s'.
        Parameter 'css' must be a 'CSS::Struct::Output::*' class.
        Parameter 'tags' must be a 'Tags::Output::*' class.

process():
        Bad list of messages.
        Bad message data object.

EXAMPLE1

use strict;
use warnings;

use CSS::Struct::Output::Indent;
use Data::Message::Simple;
use Tags::HTML::Page::Begin;
use Tags::HTML::Page::End;
use Tags::HTML::Messages;
use Tags::Output::Indent;

# Object.
my $tags = Tags::Output::Indent->new(
        'preserved' => ['style'],
        'xml' => 1,
);
my $css = CSS::Struct::Output::Indent->new;
my $begin = Tags::HTML::Page::Begin->new(
        'css' => $css,
        'lang' => {
                'title' => 'Tags::HTML::Messages example',
        },
        'generator' => 'Tags::HTML::Messages',
        'tags' => $tags,
);
my $end = Tags::HTML::Page::End->new(
        'tags' => $tags,
);
my $messages = Tags::HTML::Messages->new(
        'css' => $css,
        'tags' => $tags,
);

# Error structure.
my $message_ar = [
        Data::Message::Simple->new(
                'text' => 'Error #1',
                'type' => 'error',
        ),
        Data::Message::Simple->new(
                'text' => 'Error #2',
                'type' => 'error',
        ),
        Data::Message::Simple->new(
                'text' => 'Ok #1',
        ),
        Data::Message::Simple->new(
                'text' => 'Ok #2',
        ),
];

# Process page.
$messages->process_css('error', 'red');
$messages->process_css('info', 'green');
$begin->process;
$messages->process($message_ar);
$end->process;

# Print out.
print $tags->flush;

# Output:
# <!DOCTYPE html>
# <html lang="en">
#   <head>
#     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
#     <meta name="generator" content="Tags::HTML::Messages" />
#     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
#     <title>
#       Tags::HTML::Messages example
#     </title>
#     <style type="text/css">
# .error {
#         color: red;
# }
# .info {
#         color: green;
# }
# </style>
#   </head>
#   <body>
#     <div class="messages">
#       <span class="error">
#         Error #1
#       </span>
#       <br />
#       <span class="error">
#         Error #2
#       </span>
#       <br />
#       <span class="info">
#         Ok #1
#       </span>
#       <br />
#       <span class="info">
#         Ok #2
#       </span>
#     </div>
#   </body>
# </html>

DEPENDENCIES

Class::Utils, Error::Pure, Scalar::Util, Tags::HTML.

REPOSITORY

https://github.com/michal-josef-spacek/Tags-HTML-Messages

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© Michal Josef Špaček 2020-2023

BSD 2-Clause License

VERSION

0.04