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

HTML::Widgets::Index::Format - Formatting for rendering HTML::Widgets::Menu

SYNOPSIS

  use HTML::Widgets::Index::Format;
  my $format = HTML::Widgets::Index::Format(
      default => {
                 active_item_start => '',
                 active_item_end => "\n",
                 inactive_item_start => '',
                 inactive_item_end => "\n",
                 active_text_start => '<b>',
                 active_text_end => '</b>',
                 inactive_text_start => '',
                 inactive_text_end => '',
                 inactive_text_placeholder => '<text>', 
                 active_text_placeholder=>'<text>',
                 link_args=>'',
                 indent_active => '*',
                 indent_inactive => ' ',
                 javascript => 0,
                 no_javascript => '',
      },
      1 => {
         active_text_placeholder => '<span class="menu1"><text></span>',
         indent => ' ',
      }
  );

DESCRIPTION

With this object you can alter the format of the output. Each level of the Index can have different formatting. The levels are numbered starting from 1, and there is a default level. Undefined formatting applies default options.

Remember that since Format.pm version 0.02, indent attributes are recursively checked in descendant order, so a level 3 inactive menu item would have level 1, 2 and 3 indentation in this order. When an item is rendered active, his active_indent attribute will be used, along with recursed inactive indents. In case recursing leads to an image indent, the remaining levels will be indented using that image, correctly resized horizontally to fill those levels, while keeping the higher levels active and inactive indents.

In the placeholders you can use the special tags: <text> and <url> that are replaced with the text and url items when rendered.

Example for menu with tables and image items in the first level. Notice:

  • indenting is done using an image that is one pixel long

  • In level 1, a reference to an image is built.

  • The item starts and finishes with <tr> & <td> tags. So each one is one row of the table.

  my $format = {
        default => {
   
        link_args => 'class="menu"',
        active_item_start => 
              '<tr><td bgcolor="white">'.
                    '<img src="/img/point.gif" height="1">'.
              '</td></tr>'.
              "<tr><td>\n",
   
        active_item_end => "</td></tr>\n",
        inactive_item_start => 
              '<tr><td bgcolor="white">'.
                    '<img src="/img/point.gif" width="15" height="1">'.
              "</td></tr><tr><td>\n",

        inactive_item_end => "</td></tr>\n",

        active_text_placeholder =>
              '<span class="menu_active"><text></span>',

        indent_inactive => 
               '<img src="/img/point.gif" width="4" height="1">',

        indent_active =>
               '<img src="/img/point.gif" width="4" height="1">',
        },
        1=> {
                indent_active => '',
                indent_inactive => '',
                inactive_text_placeholder => 
                        '<img src="/img/icon/<url>.gif" alt="<text>" border="0">',
                active_text_placeholder => 
            '<img src="/img/icon/<url>.gif" alt="<text>" border="0">',
        }
  };

For this menu to be rendered you should print the table html tags before and after:

  my $menu = HTML::Widgets::Index->open(
      dbh => $dbh,
     format => $format,
  );
  print '<table border="0">', $menu->get_html , '</table>';

CONSTRUCTOR

new

METHODS

The methods of this module are used from the html renderer. The end use should just check the DESCRIPTION of the items.

uri

  Applies the format to an URI

    $format->uri($item,$level,$active);

indent

        Intents depending of the level and if it's active or not

        $format->indent($level , $active );

text

   Applies format to the text

        $format->text($item,$level,$active);

AUTHOR

A. U. Thor, <a.u.thor@a.galaxy.far.far.away>

SEE ALSO

perl.