Committer: anazarov
LJSUP-11969: Add an api to insert translated template into pageU trunk/cgi-bin/LJ/HTML/Template.pm U trunk/cgi-bin/LJ/SiteScheme.pm U trunk/cgi-bin/weblib.pl U trunk/templates/SiteScheme/lynx.tmpl
Modified: trunk/cgi-bin/LJ/HTML/Template.pm =================================================================== --- trunk/cgi-bin/LJ/HTML/Template.pm 2012-04-26 10:53:52 UTC (rev 21805) +++ trunk/cgi-bin/LJ/HTML/Template.pm 2012-04-26 10:54:03 UTC (rev 21806) @@ -29,22 +29,6 @@ ); } - if ( LJ::is_web_context() ) { - %common_params = ( - %common_params, - - 'lj_res_includes_basic' - => LJ::res_includes({ 'only_needed' => 1 }), - - 'lj_res_includes' => LJ::res_includes(), - - ## - 'lj_res_in_bottom' => (LJ::Request->get_param('res_bottom') ? 1 : 0), - 'lj_res_includes_css' => LJ::res_includes({ only_css => 1 }), - 'lj_res_includes_js' => LJ::res_includes({ only_js => 1 }), - ); - } - if ($opts->{'use_expr'}) { require HTML::Template::Pro; # load module on demand Modified: trunk/cgi-bin/LJ/SiteScheme.pm =================================================================== --- trunk/cgi-bin/LJ/SiteScheme.pm 2012-04-26 10:53:52 UTC (rev 21805) +++ trunk/cgi-bin/LJ/SiteScheme.pm 2012-04-26 10:54:03 UTC (rev 21806) @@ -32,6 +32,15 @@ my $params = $handler->template_params($args_normalized); + if ( LJ::is_web_context() ) { + $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_includes_css'} = LJ::res_includes({ only_css => 1 }); + $params->{'lj_res_includes_js'} = LJ::res_includes({ only_js => 1 }); + } + my $template = LJ::HTML::Template->new( { 'use_expr' => 1 }, 'filename' => $filename, ); Modified: trunk/cgi-bin/weblib.pl =================================================================== --- trunk/cgi-bin/weblib.pl 2012-04-26 10:53:52 UTC (rev 21805) +++ trunk/cgi-bin/weblib.pl 2012-04-26 10:54:03 UTC (rev 21806) @@ -1309,6 +1309,7 @@ if ($opts->{clean_list}) { %LJ::NEEDED_RES = (); @LJ::NEEDED_RES = (); + @LJ::INCLUDE_TEMPLATE = (); return; } @@ -1320,6 +1321,11 @@ $resopts = $key->[0]; } + if ( $reskey =~ m!^templates/! ) { + push @LJ::INCLUDE_TEMPLATE, $reskey; + next; + } + die "Bogus reskey $reskey" unless $reskey =~ m!^(js|stc)/!; ## is the key part of library/package @@ -1652,6 +1658,52 @@ } } + # 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; } Modified: trunk/templates/SiteScheme/lynx.tmpl =================================================================== --- trunk/templates/SiteScheme/lynx.tmpl 2012-04-26 10:53:52 UTC (rev 21805) +++ trunk/templates/SiteScheme/lynx.tmpl 2012-04-26 10:54:03 UTC (rev 21806) @@ -25,6 +25,7 @@ <TMPL_VAR head> <TMPL_VAR additional_head_content> +<TMPL_VAR lj_res_templates> </head> <body class='<TMPL_VAR body_class>' <TMPL_VAR bodyopts> >