Dancer2-Template-TemplateFlute

 view release on metacpan or  search on metacpan

lib/Dancer2/Template/TemplateFlute.pm  view on Meta::CPAN


=head1 DESCRIPTION

This class is an interface between Dancer2's template engine abstraction layer
and the L<Template::Flute> module.

In order to use this engine, use the template setting:

    template: template_flute

The default template extension is ".html".

=head2 LAYOUT

Each layout needs a specification file and a template file. To embed
the content of your current view into the layout, put the following
into your specification file, e.g. F<views/layouts/main.xml>:

    <specification>
    <value name="content" id="content" op="hook"/>
    </specification>

This replaces the contents of the following block in your HTML
template, e.g. F<views/layouts/main.html>:

    <div id="content">
    Your content
    </div>

=head2 ITERATORS

Iterators can be specified explicitly in the configuration file as below.

  engines:
    template:
      template_flute:
        iterators:
          fruits:
            class: JSON
            file: fruits.json

=head2 FILTER OPTIONS

Filter options and classes can be specified in the configuration file as below.

  engines:
    template:
      template_flute:
        filters:
          currency:
            options:
              int_curr_symbol: "$"
          image:
            class: "Flowers::Filters::Image"

=head2 ADJUSTING URIS

We automatically adjust links in the templates if the value of
C<request->path> is different from C<request->path_info>.

=head2 EMBEDDING IMAGES IN EMAILS

If you pass a value named C<email_cids>, which should be an empty hash
reference, all the images C<src> attributes will be rewritten using
the CIDs, and the reference will be populated with an hashref, as
documented in L<Template::Flute>

Further options for the CIDs should be passed in an optional value
named C<cids>. See L<Template::Flute> for them.


=head2 DISABLE OBJECT AUTODETECTION

Sometimes you want to pass values to a template which are objects, but
don't have an accessor, so they should be treated like hashrefs instead.

You can specify classes with the following syntax:

  engines:
    template:
      template_flute:
        autodetect:
          disable:
            - My::Class1
            - My::Class2


The class matching is checked by L<Template::Flute> with C<isa>, so
any parent class would do.

=head2 LOCALIZATION

Templates can be localized using the Template::Flute::I18N module. You
can define a class that provides a method which takes as first (and
only argument) the string to translate, and returns the translated
one. You have to provide the class and the method. If the class is not
provided, no localization is done. If no method is specified,
'localize' will be used. The app will crash if the class doesn't
provide such method.

B<Be sure to return the argument verbatim if the module is not able to
translate the string>.

Example configuration, assuming the class C<MyApp::Lexicon> provides a
C<try_to_translate> method.

  engines:
    template:
      template_flute:
        i18n:
          class: MyApp::Lexicon
          method: try_to_translate


A class could be something like this:

  package MyTestApp::Lexicon;
  use Dancer2;

  sub new {
      my $class = shift;



( run in 0.737 second using v1.01-cache-2.11-cpan-71847e10f99 )