[dw-free] Add combo ml_scope/INCLUDE ( or PROCESS ) function to plugin.
[commit: http://hg.dwscoalition.org/dw-free/rev/f7495c8d423b]
http://bugs.dwscoalition.org/show_bug.cgi?id=4091
Add dw.scoped_include/dw.scoped_process, which are to be used when you want
to include / process another template file and these files have their own
set of translation strings.
Patch by
exor674.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=4091
Add dw.scoped_include/dw.scoped_process, which are to be used when you want
to include / process another template file and these files have their own
set of translation strings.
Patch by
Files modified:
- cgi-bin/DW/Template/Plugin.pm
- views/admin/stats.tt
- views/entry/form.tt
- views/protected.tt
--------------------------------------------------------------------------------
diff -r eca28858bfd6 -r f7495c8d423b cgi-bin/DW/Template/Plugin.pm
--- a/cgi-bin/DW/Template/Plugin.pm Mon Dec 05 18:41:11 2011 +0800
+++ b/cgi-bin/DW/Template/Plugin.pm Mon Dec 05 20:26:14 2011 +0800
@@ -124,6 +124,42 @@
my $self = shift;
return LJ::img(@_);
}
+
+=head2 scoped_include
+
+Easy way to handle changing the ml scope around an INCLUDE block.
+
+ [% dw.scoped_include 'blah.tt' a=1 %]
+
+=cut
+
+sub scoped_include {
+ my ( $self, $page, $args ) = @_;
+ my $old_scope = $self->ml_scope;
+ $self->ml_scope( '/' . $page );
+ my $rv = $self->{_CONTEXT}->include( $page, $args || {} );
+ $self->ml_scope( $old_scope );
+ return $rv;
+}
+
+=head2 scoped_process
+
+Easy way to handle changing the ml scope around a PROCESS block.
+
+ [% dw.scoped_process 'blah.tt' %]
+ [% dw.scoped_process 'blah.tt' a=1 %]
+
+=cut
+
+sub scoped_process {
+ my ( $self, $page, $args ) = @_;
+ my $old_scope = $self->ml_scope;
+ $self->ml_scope( '/' . $page );
+ my $rv = $self->{_CONTEXT}->process( $page, $args || {} );
+ $self->ml_scope( $old_scope );
+ return $rv;
+}
+
=head1 AUTHOR
=over
diff -r eca28858bfd6 -r f7495c8d423b views/admin/stats.tt
--- a/views/admin/stats.tt Mon Dec 05 18:41:11 2011 +0800
+++ b/views/admin/stats.tt Mon Dec 05 20:26:14 2011 +0800
@@ -15,8 +15,7 @@
%]
[% dw.need_res( 'stc/sitestats.css' ) %]
-[% scope = dw.ml_scope( ); CALL dw.ml_scope( '/stats/site.tt' );
- INCLUDE stats/site.tt; CALL dw.ml_scope( scope ); %]
+[% dw.scoped_include( 'stats/site.tt' ); %]
[% sections.title = '.title' | ml( sitenameshort => site.nameshort ) %]
[%#
diff -r eca28858bfd6 -r f7495c8d423b views/entry/form.tt
--- a/views/entry/form.tt Mon Dec 05 18:41:11 2011 +0800
+++ b/views/entry/form.tt Mon Dec 05 20:26:14 2011 +0800
@@ -246,10 +246,7 @@
[%- BLOCK column %]
[% FOREACH component = components %]
<div class='component [% UNLESS panels.show.$component -%] inactive_component [%- END -%]' id='[% component %]_component'>
- [%- CALL dw.ml_scope( "/entry/module-${component}.tt" );
- INCLUDE "entry/module-${component}.tt";
- CALL dw.ml_scope( "/entry/form.tt" )
- %]
+ [%- dw.scoped_include( "entry/module-${component}.tt" ); %]
</div>
[%- END -%]
[% END -%]
diff -r eca28858bfd6 -r f7495c8d423b views/protected.tt
--- a/views/protected.tt Mon Dec 05 18:41:11 2011 +0800
+++ b/views/protected.tt Mon Dec 05 20:26:14 2011 +0800
@@ -28,9 +28,6 @@
</div>
[% UNLESS remote %]
- [% old_scope = dw.ml_scope() %]
- [% CALL dw.ml_scope( '/login.tt' ) %]
- [% INCLUDE login.tt %]
- [% CALL dw.ml_scope( old_scope ) %]
+ [% dw.scoped_include( "login.tt" ); %]
[% END %]
--------------------------------------------------------------------------------
