The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tags::HTML::Container - Tags helper for container.

SYNOPSIS

 use Tags::HTML::Container;

 my $obj = Tags::HTML::Container->new(%params);
 $obj->cleanup($cleanup_cb);
 $obj->init($init_cb);
 $obj->prepare($prepare_cb);
 $obj->process($tags_cb);
 $obj->process_css($css_cb);

METHODS

new

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

Constructor.

  • css

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

    Default value is undef.

  • css_container

    CSS class for container box.

    Default value is 'container'.

  • css_inner

    CSS class for inner box in container.

    Default value is 'inner'.

  • height

    Container height in CSS style.

    Default value is '100vh'.

  • horiz_align

    Horizontal align.

    Possible values are: center left right

    Default value is 'center'.

  • padding

    Container padding.

    Default value is undef.

  • vert_align

    Vertical align.

    Possible values are: base bottom center fit top

    Default value is 'center'.

  • tags

    'Tags::Output' object.

    Default value is undef.

cleanup

 $obj->cleanup($cleanup_cb);

Cleanup Tags::HTML object for container with code defined in $cleanup_cb callback. This callback has one argument and this is $self of container object.

Returns undef.

init

 $obj->init($init_cb);

Initialize Tags::HTML object (in page run) for container with code defined in $init_cb callback. This callback has one argument and this is $self of container object.

Returns undef.

prepare

 $obj->prepare($prepare_cb);

Prepare Tags::HTML object (in page preparation) for container with code defined in $prepare_cb callback. This callback has one argument and this is $self of container object.

Returns undef.

process

 $obj->process($tags_cb);

Process Tags structure for container with code defined in $tags_cb callback. This callback has one argument and this is $self of container object. $tags_cb is required argument.

Returns undef.

process_css

 $obj->process_css($css_cb);

Process CSS::Struct structure for output with code defined in $css_cb callback. This callback has one argument and this is $self of container object. $css_cb is optional argument.

Returns undef.

ERRORS

 new():
         From Class::Utils::set_params():
                 Unknown parameter '%s'.
         from Mo::utils::CSS::check_css_unit():
                 Parameter 'height' doesn't contain number.
                         Value: %s
                 Parameter 'height' doesn't contain unit.
                         Value: %s
                 Parameter 'height' contain bad unit.
                         Unit: %s
                         Value: %s
                 Parameter 'padding' doesn't contain number.
                         Value: %s
                 Parameter 'padding' doesn't contain unit.
                         Value: %s
                 Parameter 'padding' contain bad unit.
                         Unit: %s
                         Value: %s
         From Tags::HTML::new():
                 Parameter 'css' must be a 'CSS::Struct::Output::*' class.
                 Parameter 'tags' must be a 'Tags::Output::*' class.
         Parameter 'horiz_align' is required.
         Parameter 'horiz_align' have a bad value.
                 Value: %s
         Parameter 'vert_align' is required.
         Parameter 'vert_align' have a bad value.
                 Value: %s

 process():
         From Tags::HTML::process():
                 Parameter 'tags' isn't defined.
         There is no contained callback with Tags code.

 process_css():
         From Tags::HTML::process_css():
                 Parameter 'css' isn't defined.

EXAMPLE1

 use strict;
 use warnings;

 use CSS::Struct::Output::Indent;
 use Tags::HTML::Container;
 use Tags::Output::Indent;

 # Object.
 my $css = CSS::Struct::Output::Indent->new;
 my $tags = Tags::Output::Indent->new;
 my $obj = Tags::HTML::Container->new(
         'css' => $css,
         'tags' => $tags,
 );

 # Process container with text.
 $obj->process(sub {
         my $self = shift;
         $self->{'tags'}->put(
                 ['d', 'Hello World!'],
         );
         return;
 });
 $obj->process_css;

 # Print out.
 print $tags->flush;
 print "\n\n";
 print $css->flush;

 # Output:
 # <div class="container">
 #   <div class="inner">
 #     Hello World!
 #   </div>
 # </div>
 # 
 # .container {
 #         display: flex;
 #         align-items: center;
 #         justify-content: center;
 #         height: 100vh;
 # }

EXAMPLE2

 use strict;
 use warnings;
 
 use CSS::Struct::Output::Indent;
 use Plack::App::Tags::HTML;
 use Plack::Runner;
 use Tags::HTML::ChangePassword;
 use Tags::Output::Indent;
 
 my $css = CSS::Struct::Output::Indent->new;
 my $tags = Tags::Output::Indent->new(
         'xml' => 1,
         'preserved' => ['style'],
 );
 my $change_password = Tags::HTML::ChangePassword->new(
         'css' => $css,
         'tags' => $tags,
 );
 $change_password->process_css;
 my $app = Plack::App::Tags::HTML->new(
         'component' => 'Tags::HTML::Container',
         'data' => [sub {
                 my $self = shift;
                 $change_password->process;
                 return;
         }],
         'css' => $css,
         'tags' => $tags,
 )->to_app;
 Plack::Runner->new->run($app);

 # Output screenshot is in images/ directory.
Web app example

DEPENDENCIES

Class::Utils, Error::Pure, List::Util, Mo::utils::CSS, Readonly, Tags::HTML,

REPOSITORY

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

AUTHOR

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

http://skim.cz

LICENSE AND COPYRIGHT

© 2023-2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.07