++ed by:

1 non-PAUSE user.

Ailin Nemui
and 1 contributors

NAME

Text::Xslate::Syntax::FiltersAsTags - easily add more template tags which are mapped onto filters

VERSION

version 0.1

SYNOPSIS

    package My::Own::Syntax;
    use Mouse;

    extends 'Text::Xslate::Syntax::TTerse';     # or ::Kolon
    with 'Text::Xslate::Syntax::FiltersAsTags'; # this module!

    my @more_symbols = qw(TL R_table R_vtable R_svg R_collect_tables); # additional tags
    sub more_symbols { @more_symbols } # you must provide this method

    no Mouse;
    __PACKAGE__->meta->make_immutable;
    1

in your controller:

    my $tx = Text::Xslate->new(
        syntax => 'My::Own::Syntax',
        function => +{
                tl      => html_builder(\&translate_switch),
                r_table => html_builder { &fixup_filter_parser; make_R_table($_[0]) },
                r_svg   => html_builder { &fixup_filter_parser; make_R_svg($_[0]); },
                r_collect_tables =>
                           html_builder { &fixup_filter_parser;
                        eval_R_lines('r=list()');
                        eval_R_lines($_[0]);
                        R_merge_tables()
                },
           },
   );

    sub fixup_filter_parser {
        for (@_) {
                s/^\s*<!\[CDATA\[(.*)\]\]>\s*$/$1/s;
                s/(\n\s*)*$//; s/^(\s*\n)*//;
        }
    }

in your template:

    [% TL %][_en] observation period [_de] Beobachtungszeitraum[% END %]

    [% R_table %]
    summary(md_real$region)
    [% END %]

    [% R_svg %]
    boxplot(md_real$[% data %], log="y", main="[% data %]")
    [% END %]

    [% R_collect_tables %]<![CDATA[
    r$`[% TL %] at beginning     [% END %]` <- table(md_real[md_real$appeared.on$mday<4,]$appeared.on$hour)
    r$`[% TL %] not at beginning [% END %]` <- table(md_real[md_real$appeared.on$mday>=4,]$appeared.on$hour)
    ]]>[% END %]

DESCRIPTION

this role helps you to quickly add more template tags to your Xslate template, which are then mapped to filters in your parse run.

You only need to provide a single method in your own syntax class, more_symbols. It must return a list of additional tags allowed in the template. You connect to those tags, which are a simple convenience for a filter call, from your controller.

Note that you do need to make an own class for every domain specific template, and it does need to use Mouse because that's what Text::Xslate uses. You will get weird errors when trying to use Moo.

AUTHOR

Ailin Nemui <ailin at devio dot us>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Ailin Nemui.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.