App-Mowyw

 view release on metacpan or  search on metacpan

lib/App/Mowyw.pm  view on Meta::CPAN

# parse sub: parse a 'menu' statement.
# note that TAG_START and the keyword "menu" are already stripped
sub p_menu {
    my $tokens = shift;
    my $meta = shift;
#    print Dumper $meta;
    my $key = strip_ws(p_expect($tokens, "UNMATCHED", $meta));
    my @words = split /\s+/, $key;
    p_expect($tokens, "TAG_END", $meta);
    my $menu_fn = shift @words;
#    print "\nMenu: '$menu_fn'\n";
    $menu_fn = get_include_filename('menu', $menu_fn, $meta->{FILES}->[-1]);
#    print "Menu after frobbing: '$menu_fn'\n";

    my $m = my_dclone($meta);
    push @{$m->{ITEMS}}, @words;
    unshift @{$m->{FILES}}, $menu_fn;
    return parse_file($menu_fn, $m);
}

# parse sub: parse an 'option' statement
sub p_option {
    my $tokens = shift;

script/mowyw  view on Meta::CPAN


(The menu name is purely for your internal use, it will appear nowhere in the
output)

Now in your index page you can include that menu with the directive 
C<[% menu home %]>. This will produce the menu contents with the markup
stripped, and insde the C<home> all of the contents will appear, the other menu
items only contribute the parts that are B<not> enclosed in double curly
braces.

Menus can ben nested, a nested menu entry can be accessed for example with
C<[% menu sec subitem1 %]>.

It's best to take a look at the examples in the distribution, which should
nicely illustrate the menu mechanism.


=head1 SYNTAX HILIGHTING

Syntax hilighting requires vim (see L<http://www.vim.org/>) and
L<Text::VimColor> to be installed

t/menu.t  view on Meta::CPAN

BEGIN { use_ok('App::Mowyw', 'parse_str'); };

my %meta = ( VARS => {}, FILES => [qw(t/menu.t)]);
$App::Mowyw::config{default}{include} = 't/';
$App::Mowyw::config{default}{menu}    = 't/menu-';
$App::Mowyw::config{default}{postfix} = '';


is  parse_str('[% menu sample %]', \%meta),
    " i1 i2 \n",
    'Menu without selected item';

is  parse_str('[% menu sample i1 %]', \%meta),
    " i1b i2 \n",
    'Menu with first item selected';

is  parse_str('[% menu sample i2 %]', \%meta),
    " i1 i2b \n",
    'Menu with second item selected';

is  parse_str('[% menu sample i3 %]', \%meta),
    " i1 i2  i3i1\n",
    'Menu with third item selected';

is  parse_str('[% menu sample i3 i3i1 %]', \%meta),
    " i1 i2  i3i1b\n",
    'Menu with third item and subitem selected';



( run in 1.378 second using v1.01-cache-2.11-cpan-49f99fa48dc )