@@ -21,33 +21,52 @@ sub init {
2121 my $charset = setting(' charset' ) || ' ' ;
2222 my @encoding = length ($charset ) ? ( ENCODING => $charset ) : ();
2323
24- my $tt_config = {
25- ANYCASE => 1,
26- ABSOLUTE => 1,
27- @encoding ,
28- %{$self -> config},
29- };
24+ my $is_subclass = $class ne ' Template' ;
3025
31- my $start_tag = $self -> config-> {start_tag } || ' <%' ;
32- my $stop_tag =
33- $self -> config-> {stop_tag }
34- || $self -> config-> {end_tag }
35- || ' %>' ;
26+ my @anycase = $is_subclass ? () : ( ANYCASE => 1 );
27+ my @absolute = $is_subclass ? () : ( ABSOLUTE => 1 );
28+
29+ my @inc_path = $is_subclass ? ()
30+ : ( INCLUDE_PATH => $self -> config-> {INCLUDE_PATH } || setting(' views' ) );
31+
32+ my $start_tag = $is_subclass
33+ ? $self -> config-> {start_tag }
34+ : $self -> config-> {start_tag } || ' <%' ;
35+
36+ my $stop_tag = $is_subclass
37+ ? $self -> config-> {stop_tag } || $self -> config-> {end_tag }
38+ : $self -> config-> {stop_tag } || $self -> config-> {end_tag } || ' %>' ;
3639
3740 # TT expects quotemeta()'ed values here to be used as-is within
3841 # its regexp-based tokenizer. To support existing Dancer users who
3942 # prefer the default TT tags and who've already figured this out,
4043 # let's skip this if the tags are already ok.
4144 # Just FYI: TT hardcodes '\[%' and '%\]' as default.
4245 #
43- $tt_config -> {START_TAG } = $start_tag eq ' \[%' || $start_tag eq ' \[\%'
44- ? $start_tag
45- : quotemeta ($start_tag );
46- $tt_config -> {END_TAG } = $stop_tag eq ' %\]' || $stop_tag eq ' \%\]'
47- ? $stop_tag
48- : quotemeta ($stop_tag );
46+ my @start = ();
47+ if (defined $start_tag ) {
48+ @start = ( START_TAG => $start_tag eq ' \[%' || $start_tag eq ' \[\%'
49+ ? $start_tag
50+ : quotemeta ($start_tag )
51+ );
52+ }
53+ my @stop = ();
54+ if (defined $stop_tag ) {
55+ @stop = ( END_TAG => $stop_tag eq ' %\]' || $stop_tag eq ' \%\]'
56+ ? $stop_tag
57+ : quotemeta ($stop_tag )
58+ );
59+ }
4960
50- $tt_config -> {INCLUDE_PATH } ||= setting(' views' );
61+ my $tt_config = {
62+ @anycase ,
63+ @absolute ,
64+ @encoding ,
65+ @inc_path ,
66+ @start ,
67+ @stop ,
68+ %{$self -> config},
69+ };
5170
5271 $_engine = $class -> new(%$tt_config );
5372}
@@ -108,13 +127,22 @@ initialization. You could, for instance, enable saving the compiled templates:
108127 COMPILE_DIR: 'caches/templates'
109128 COMPILE_EXT: '.ttc'
110129
130+ Note though that unless you change them, Dancer sets both of the Template
131+ options C<ANYCASE > and C<ABSOLUTE > on, as well as pointing C<INCLUDE_PATH >
132+ to your B<views > directory and setting C<ENCODING > to your B<charset >
133+ setting.
134+
135+ =head1 SUBCLASSING
136+
111137By default, L<Template> is used, but you can configure Dancer to use a
112- subclass with the C<subclass > option.
138+ subclass of Template with the C<subclass > option.
113139
114140 engines:
115141 template_toolkit:
116142 subclass: My::Template
117143
144+ When used like this, Dancer skips the defaults mentioned above. Only those
145+ included in your config file are sent to the subclass.
118146
119147=head1 WRAPPER, META variables, SETs
120148
0 commit comments