madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r22625: LJSUP-13275: Ability to get js template ...

Committer: sbelyaev
LJSUP-13275: Ability to get js template from (l-)stat
U   trunk/cgi-bin/Apache/LiveJournal.pm
U   trunk/cgi-bin/weblib.pl
Modified: trunk/cgi-bin/Apache/LiveJournal.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal.pm	2012-08-13 07:41:24 UTC (rev 22624)
+++ trunk/cgi-bin/Apache/LiveJournal.pm	2012-08-13 10:14:38 UTC (rev 22625)
@@ -387,6 +387,7 @@
             and LJ::Request->uri !~ /\.bml$/        ## BML is allowed on stat. domain
             and LJ::Request->uri !~ m|/palimg/|     ## PaletteModify actions are processed by other handler
             and LJ::Request->uri !~ m|^/__api/?|
+            and LJ::Request->uri !~ m|^/__tmpl/|
             ) or
         ($LJ::IS_SSL and LJ::Request->unparsed_uri =~ /\?\?/)
     ){

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2012-08-13 07:41:24 UTC (rev 22624)
+++ trunk/cgi-bin/weblib.pl	2012-08-13 10:14:38 UTC (rev 22625)
@@ -1411,65 +1411,92 @@
     if ( $opts->{'only_tmpl'} ) {
         my %loaded;
         foreach my $template (@LJ::SITEWIDE_TEMPLATES, @LJ::INCLUDE_TEMPLATE) {
-            my $path = [split m{(?<!\\)/}, $template];
-            my $file = pop @$path;
-            my ($type, $filter);
+            if (LJ::is_enabled('template_from_stat')) {
+                # Create template id
+                my $key = $template;
+                $key =~ s{(?<!\\)/} {-}g;
+                $key =~ s{\.(?:jq)?tmpl$} {}g;
 
-            shift @$path if $path->[0] eq 'templates';
+                my $stat_prefix = 'l-stat';
+                my $debug_data  = '';
 
-            $path     = join '/', $LJ::TEMPLATE_BASE, @$path;
-            my $fpath = join '/', $path, $file;
+                if ($LJ::IS_DEV_SERVER) {
+                    $stat_prefix =  'stat';
+
+                    $debug_data = sprintf q{
+                        data-template="%s"
+                        data-translation="%s"},
+                        $template, $LJ::TEMPLATE_TRANSLATION;
+                }
+
+                my $address = "http://$stat_prefix.$LJ::DOMAIN/__tmpl/$template";
+                $ret .= sprintf q{<script type="text/plain" id="%s" src="%s" %s>}, 
+                        $key, $address, $debug_data;
+                $ret .= '</script>';
+
+                $ret .= sprintf q{<script>LJ.UI.registerTemplate('%s', '%s', '%s');</script>}, 
+                    $key, $key, $LJ::TEMPLATE_TRANSLATION;
+            } else {
+                my $path = [split m{(?<!\\)/}, $template];
+                my $file = pop @$path;
+                my ($type, $filter);
+
+                shift @$path if $path->[0] eq 'templates';
+
+                $path     = join '/', $LJ::TEMPLATE_BASE, @$path;
+                my $fpath = join '/', $path, $file;
             
-            -f $fpath             or warn 'Missing template '. $fpath and next;
-            $loaded{lc $fpath}++ and next;
+                -f $fpath             or warn 'Missing template '. $fpath and next;
+                $loaded{lc $fpath}++ and next;
 
-            for ($file) {
-                m{\.jqtmpl$}i and do {
-                    $type   = 'JQuery.tmpl';
-                    $filter = 'jqtmpl';
-                };
+                for ($file) {
+                    m{\.jqtmpl$}i and do {
+                        $type   = 'JQuery.tmpl';
+                        $filter = 'jqtmpl';
+                    };
 
-                m{\.tmpl$}i   and do {
-                    $type   = 'HTML::Template';
-                    $filter = $LJ::TEMPLATE_FILTER;
-                };
-            }
+                    m{\.tmpl$}i   and do {
+                        $type   = 'HTML::Template';
+                        $filter = $LJ::TEMPLATE_FILTER;
+                    };
+                }
 
-            $type or next;
+                $type or next;
 
-            my $data = LJ::Response::CachedTemplate->new(
-                file               => $file,
-                path               => $path,
-                type               => $type,
-                translate          => $LJ::TEMPLATE_TRANSLATION,
-                filter             => $filter,
-            );
+                my $data = LJ::Response::CachedTemplate->new(
+                    file               => $file,
+                    path               => $path,
+                    type               => $type,
+                    translate          => $LJ::TEMPLATE_TRANSLATION,
+                    filter             => $filter,
+                );
 
-            # Create template id
-            my $key = $template;
-            $key =~ s{(?<!\\)/} {-}g;
-            $key =~ s{\.(?:jq)?tmpl$} {}g;
+                # Create template id
+                my $key = $template;
+                $key =~ s{(?<!\\)/} {-}g;
+                $key =~ s{\.(?:jq)?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-type="%s"
-                    data-filter="%s"
-                    data-translation="%s">},
-                $key, $path, $file, $type, $filter, $LJ::TEMPLATE_TRANSLATION;
-                $ret .= $data->raw_output();
-                $ret .= '</script>';
-            } else {
-                $ret .= sprintf q{<script type="text/plain" id="%s">}, $key;
-                $ret .= $data->raw_output();
-                $ret .= '</script>';
+                # 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-type="%s"
+                        data-filter="%s"
+                        data-translation="%s">},
+                    $key, $path, $file, $type, $filter, $LJ::TEMPLATE_TRANSLATION;
+                    $ret .= $data->raw_output();
+                    $ret .= '</script>';
+                } else {
+                    $ret .= sprintf q{<script type="text/plain" id="%s">}, $key;
+                    $ret .= $data->raw_output();
+                    $ret .= '</script>';
+                }
+
+                # Let js know about template 
+                $ret .= sprintf q{<script>LJ.UI.registerTemplate('%s', '%s', '%s');</script>}, $key, $key, $LJ::TEMPLATE_TRANSLATION;
             }
-
-            # Let js know about template 
-            $ret .= sprintf q{<script>LJ.UI.registerTemplate('%s', '%s', '%s');</script>}, $key, $key, $LJ::TEMPLATE_TRANSLATION;
         }
 
         return $ret;

Tags: livejournal, madeon, pl, pm, sbelyaev
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