Skip to content

michal-josef-spacek/Tags-HTML-Messages

Repository files navigation

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'.

    *       "flag_no_messages"

            Flag for no messages printing.

            Possible values:

             0 - Print nothing
             1 - Print message box with 'No messages.' text.

            Default value is 1.

    *       "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($message_types_hr);

    Process CSS::Struct structure for output.

    Variable $message_type_hr is reference to hash with keys for message
    type and value for color in CSS style. Possible message types 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.

     process_css():
             Message types must be a hash reference.

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(
                     'lang' => 'en',
                     'text' => 'Ok #1',
             ),
             Data::Message::Simple->new(
                     'text' => 'Ok #2',
             ),
     ];

     # Process page.
     $messages->process_css({
             'error' => 'red',
             '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" lang="en">
     #         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-2024

    BSD 2-Clause License

VERSION
    0.10

About

Tags helpers for HTML messages.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages