File: TTLogReport.pod

package info (click to toggle)
liblog-report-template-perl 1.03-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 204 kB
  • sloc: perl: 732; makefile: 2
file content (148 lines) | stat: -rw-r--r-- 4,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
=encoding utf8

=head1 NAME

Dancer2::Template::TTLogReport - Template toolkit engine with Log::Report translations for Dancer2

=head1 INHERITANCE

 Dancer2::Template::TTLogReport
   is a Moo::Object

=head1 SYNOPSIS

To use this engine, you may configure L<Dancer2> via C<config.yaml>:

  template:   "TTLogReport"

Or you may also change the rendering engine on a per-route basis by
setting it manually with C<set>:

  set template => 'TTLogReport';

Application:

  # In your daemon startup
  my $pot    = Log::Report::Translator::POT->new(lexicon => $poddir);
  my $domain = (engine 'template')->addTextdomain(name => $mydomain);
  $domain->configure(translator => $pot);

  # Use it:
  get '/' => sub {
    template index => {
        title        => 'my webpage',

        # The actual language is stored in the user session.
        translate_to => 'nl_NL.utf-8',
    };
  };

=head1 DESCRIPTION

This template engine allows you to use L<Template>::Toolkit in L<Dancer2>,
including the translation extensions offered by L<Log::Report::Template>.

=head1 METHODS

=head2 Constructors

Standard Moo with Dancer2::Core::Role::Template extensions.

=head2 Accessors

=over 4

=item $obj-E<gt>B<tt>()

Returns the L<Log::Report::Template|Log::Report::Template> object which is performing the
template processing.  This object gets instantiated based on values
found in the Dancer2 configuration file.

=back

=head2 Action

=over 4

=item $obj-E<gt>B<addTextDomain>(%options)

Forwards the C<%options> to L<Log::Report::Template::addTextdomain()|Log::Report::Template/"Handling text domains">.

example: 

  my $lexicon = $directory;  # f.i. $directory/<domain>/nl_NL.utf-8.po
  my $tables  = Log::Report::Translator::POT->new(lexicon => $lexicon);
  (engine 'template')->addTextdomain(name => 'mydomain')->configure(translator => $tables);

=item $obj-E<gt>B<render>($template, \%tokens)

Renders the template.  The first arg is a filename for the template file
or a reference to a string that contains the template. The second arg
is a hashref for the tokens that you wish to pass to
L<Template::Toolkit> for rendering.

When a translation language is set, then this renderer adds the following
variables: C<language> (like "nl"), C<language_territory> (like "nl_BE"),
and C<locale> (like "nl_BE.utf8").

=back

=head1 DETAILS

=head2 Dancer2 Configuration

Most configuration variables are available when creating a new instance
of a L<Template>::Toolkit object can be declared in your config.yml file.
For example:

  template: TTLogReport

  engines:
    template:
      TTLogReport:
        start_tag: '<%'
        end_tag:   '%>'

(Note: C<start_tag> and C<end_tag> are regexes.  If you want to use PHP-style
tags, you will need to list them as C<< <\? >> and C<< \?> >>.)
See L<Template::Manual::Config> for the configuration variables.

In addition to the standard configuration variables, the option C<show_private_variables>
is also available. Template::Toolkit, by default, does not render private variables
(the ones starting with an underscore). If in your project it gets easier to disable
this feature than changing variable names, add this option to your configuration.

  show_private_variables: true

B<Warning:> Given the way Template::Toolkit implements this option, different Dancer2
applications running within the same interpreter will share this option!

=head2 Advanced Customization

Module L<Dancer2::Template::TemplateToolkit> describes how to extend the Template
by wrapping the C<_build_engine> method.  The instantiation trick is insufficient
for a bit more complex modules, like our Log::Report translation feature.  You may
be able to extend this module with your own templater, however.

  # in config.yml
  engines:
    template:
      TTLogReport:
        start_tag: '<%'
        end_tag:   '%>'
        templater: Log::Report::Template  # default

=head1 SEE ALSO

This module is part of Log-Report-Template version 1.03,
built on September 08, 2025. Website: F<http://perl.overmeer.net/CPAN/>

=head1 LICENSE

For contributors see file ChangeLog.

This software is copyright (c) 2017-2025 by Mark Overmeer.

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