Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[livejournal] r21813: LJSUP-11969: Add an api to insert transl...

Committer: anazarov
LJSUP-11969: Add an api to insert translated template into page
U   trunk/cgi-bin/LJ/SiteScheme.pm
U   trunk/cgi-bin/weblib.pl
Modified: trunk/cgi-bin/LJ/SiteScheme.pm
===================================================================
--- trunk/cgi-bin/LJ/SiteScheme.pm	2012-04-26 11:51:02 UTC (rev 21812)
+++ trunk/cgi-bin/LJ/SiteScheme.pm	2012-04-26 11:56:12 UTC (rev 21813)
@@ -36,7 +36,7 @@
         $params->{'lj_res_in_bottom'}      = LJ::Request->get_param('res_bottom')? 1 : 0;
         $params->{'lj_res_includes'}       = LJ::res_includes();
         $params->{'lj_res_includes_basic'} = LJ::res_includes({ only_needed => 1 });
-        $params->{'lj_res_templates'}      = LJ::res_includes({ only_tmpl   => 1 });
+        $params->{'lj_res_templates'}      = LJ::res_includes({ only_needed => 1, only_tmpl   => 1 });
         $params->{'lj_res_includes_css'}   = LJ::res_includes({ only_css    => 1 });
         $params->{'lj_res_includes_js'}    = LJ::res_includes({ only_js     => 1 });
     }

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2012-04-26 11:51:02 UTC (rev 21812)
+++ trunk/cgi-bin/weblib.pl	2012-04-26 11:56:12 UTC (rev 21813)
@@ -1384,6 +1384,51 @@
         $wstatprefix = $LJ::WSTATPREFIX;
     }
 
+    if ( $opts->{'only_tmpl'} ) {{
+        # add jQuery.tmpl templates
+        my %loaded;
+        foreach my $template (@LJ::INCLUDE_TEMPLATE) {
+            my $path = [split m{(?<!\\)/}, $template];
+            my $file = pop @$path;
+
+            shift @$path if $path->[0] eq 'templates';
+
+            $path     = join '/', $LJ::TEMPLATE_BASE, @$path;
+            my $fpath = join('/', $path, $file);
+            
+            -f $fpath         or  next;
+            $loaded{$fpath}++ and next;
+
+            my $data = LJ::Response::CachedTemplate->new(
+                file               => $file,
+                path               => $path,
+                translate          => $LJ::TEMPLATE_TRANSLATION,
+                filter             => $LJ::TEMPLATE_FILTER,
+            );
+
+            my $key = $template;
+            $key =~ s{(?<!\\)/} {-}g;
+            $key =~ s{\.tmpl$} {}g;
+
+            # TODO: </script> in template can ruin your day
+            if ( $LJ::IS_DEV_SERVER ) {
+                $ret .= sprintf q{
+                    <script type="text/plain" id="%s" data-path="%s" data-file="%s" data-filter="%s" data-translation="%s">
+                    %s
+                    </script>
+                }, $key, $path, $file, $LJ::TEMPLATE_FILTER, $LJ::TEMPLATE_TRANSLATION, $data->raw_output();
+
+
+            } else {
+                $ret .= sprintf q{
+                    <script type="text/plain" id="%s">%s</script>
+                }, $key, $data->raw_output();
+            }
+        }
+
+        return $ret;
+    }}
+
     # include standard JS info
     unless ( $only_needed ) {
         # find current journal
@@ -1657,52 +1702,7 @@
         }
     }
 
-    # add jQuery.tmpl templates
-    {
-        next unless $opts->{'only_tmpl'};
-        my %loaded;
-        foreach my $template (@LJ::INCLUDE_TEMPLATE) {
-            my $path = [split m{(?<!\\)/}, $template];
-            my $file = pop @$path;
 
-            shift @$path if $path->[0] eq 'templates';
-
-            $path     = join '/', $LJ::TEMPLATE_BASE, @$path;
-            my $fpath = join('/', $path, $file);
-            
-            -f $fpath         or  next;
-            $loaded{$fpath}++ and next;
-
-            my $data = LJ::Response::CachedTemplate->new(
-                file               => $file,
-                path               => $path,
-                translate          => $LJ::TEMPLATE_TRANSLATION,
-                filter             => $LJ::TEMPLATE_FILTER,
-            );
-
-            my $key = $template;
-            $key =~ s{(?<!\\)/} {-}g;
-            $key =~ s{\.tmpl$} {}g;
-
-            # TODO: </script> in template can ruin your day
-            if ( $LJ::IS_DEV_SERVER ) {
-                $ret .= sprintf q{
-<script type="text/plain" id="%s" data-path="%s" data-file="%s" data-filter="%s" data-translation="%s">
-%s
-</script>
-                }, $key, $path, $file, $LJ::TEMPLATE_FILTER, $LJ::TEMPLATE_TRANSLATION, $data->raw_output();
-
-
-            } else {
-                $ret .= sprintf q{
-<script type="text/plain" id="%s">
-%s
-</script>
-                }, $key, $data->raw_output();
-            }
-        }
-    }
-
     return $ret;
 }
 

Tags: anazarov, livejournal, nfokz, pl, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments