diff options
| author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2008-02-29 00:14:08 +0100 | 
|---|---|---|
| committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2008-02-29 00:14:08 +0100 | 
| commit | a25f8442450d7e9fb188a979ab0897cb86e9d84f (patch) | |
| tree | 9e051ee2380470db1ca2d0b406938be05b8ecc6f | |
| parent | 3434b56d6b476f1094f6aa59ce228e930d3194fb (diff) | |
| parent | 1217f130fa8890a3c12fb4e91e3df52361218e95 (diff) | |
Merge branch 'master' of /home/argggh/git/lxrng/
| -rw-r--r-- | lib/LXRng/Web.pm | 185 | ||||
| -rw-r--r-- | tmpl/ajax_redir.tt2 | 13 | 
2 files changed, 107 insertions, 91 deletions
diff --git a/lib/LXRng/Web.pm b/lib/LXRng/Web.pm index b8e06d5..c9acc71 100644 --- a/lib/LXRng/Web.pm +++ b/lib/LXRng/Web.pm @@ -38,7 +38,7 @@ use File::Path qw(mkpath);  use POSIX qw(waitpid);  # Cache must be purged if this is changed. -use constant FRAGMENT_SIZE => 250; +use constant FRAGMENT_SIZE => 1000;  use vars qw($has_gzip_io);  eval { require PerlIO::gzip; $has_gzip_io = 1; }; @@ -77,101 +77,101 @@ sub print_markedup_file {  	    or die $template->error();  	return;      } -    else { -	my $line   = 0; -	my $focus  = 1; -	my $fline  = $context->param('line'); - -	$focus = $fline < FRAGMENT_SIZE if defined($fline); - -	my $shaid = sha1_hex(join("\0", $node->name, $node->revision, -				  $context->release)); -	my $cfile; -	$shaid =~ s,^(..)(..),$1/$2/,; -	$shaid .= '_2'; # Cache file format generation indicator -	$cfile = $context->config->{'cache'}.'/'.$shaid -	    if exists $context->config->{'cache'}; - -	if ($cfile and -e "$cfile/.complete") { -	    print("<div id=\"file_contents\">"); -	    while (-r "$cfile/$line") { -		print("<pre class=\"".($focus ? "done" : "pending"). -		      "\" id=\"$shaid/$line\">"); -		if ($focus) { -		    open(my $cache, '<', "$cfile/$line"); -		    my $buf; -		    while (read($cache, $buf, 16384) > 0) { -			print($buf); -		    } -		    close($cache); -		} -		else { -		    print("<a class=\"line\"></a>\n" x FRAGMENT_SIZE); -		} -		print("</pre>"); -		$line += FRAGMENT_SIZE; -		if (defined($fline)) { -		    $focus = ($line <= ($fline + 100) -			      and $line > ($fline - FRAGMENT_SIZE)); +    my $line   = 0; +    my $focus  = 1; +    my $fline  = $context->param('line'); + +    $focus = $fline < FRAGMENT_SIZE if defined($fline); + +    my $shaid = sha1_hex(join("\0", $node->name, $node->revision, +			      $context->release)); +    my $cfile; +    $shaid =~ s,^(..)(..),$1/$2/,; +    $shaid .= '_3'; # Cache file format generation indicator +    $cfile = $context->config->{'cache'}.'/'.$shaid +	if exists $context->config->{'cache'}; + +    if ($cfile and -e "$cfile/.complete") { +	print("<div id=\"file_contents\">"); +	while (-r "$cfile/$line") { +	    print("<pre class=\"".($focus ? "done" : "pending"). +		  "\" id=\"$shaid/$line\">"); +	    if ($focus) { +		open(my $cache, '<', "$cfile/$line"); +		my $buf; +		while (read($cache, $buf, 16384) > 0) { +		    print($buf);  		} +		close($cache);  	    } -	    print("</div>\n"); -	} -	else { -	    my $cache; -	    if ($cfile) { -		mkpath($cfile, 0, 0777); -		open($cache, '>', "$cfile/0"); +	    else { +		print("<a class=\"line\"></a>\n" x FRAGMENT_SIZE);  	    } -	    my $handle = $node->handle(); -	    LXRng::Lang->init($context); -	    my $lang   = LXRng::Lang->new($node); -	    my $parse  = LXRng::Parse::Simple->new($handle, 8, -						   @{$lang->parsespec}); -	    my $markup = LXRng::Markup::File->new('context' => $context); -	    my $subst  = $lang->markuphandlers($context, $node, $markup); - -	    print("<div id=\"file_contents\">". -		  "<pre class=\"".($focus ? "done" : "pending"). -		  "\" id=\"$shaid/0\">"); -	    while (1) { -		my @frags = map { split(/(?<=\n)/, $_) } -		$markup->markupfile($subst, $parse); -		last unless @frags; -		foreach my $f (@frags) { -		    print($f) if $focus; -		    print($cache $f) if $cache; -		    if ($f =~ /\n$/s) { -			$line++; -			if ($line % FRAGMENT_SIZE == 0) { -			    print("<a class=\"line\"></a>\n" x FRAGMENT_SIZE) -				unless $focus; -			    if (defined($fline)) { -				$focus = ($line <= ($fline + 100) -					  and $line > ($fline - FRAGMENT_SIZE)); -			    } -			    print("</pre>". -				  "<pre class=\"". -				  ($focus ? "done" : "pending"). -				  "\" id=\"$shaid/$line\">"); -			    if ($cache) { -				close($cache); -				open($cache, '>', "$cfile/$line"); -			    } -			} +	    print("</pre>"); +	    $line += FRAGMENT_SIZE; + +	    if (defined($fline)) { +		$focus = ($line <= ($fline + 100) +			  and $line > ($fline - FRAGMENT_SIZE)); +	    } +	} +	print("</div>\n"); +	return "use:".$shaid; +    } + +    my $cache; +    if ($cfile) { +	mkpath($cfile, 0, 0777); +	open($cache, '>', "$cfile/0"); +    } +    my $handle = $node->handle(); +    LXRng::Lang->init($context); +    my $lang   = LXRng::Lang->new($node); +    my $parse  = LXRng::Parse::Simple->new($handle, 8, +					   @{$lang->parsespec}); +    my $markup = LXRng::Markup::File->new('context' => $context); +    my $subst  = $lang->markuphandlers($context, $node, $markup); + +    print("<div id=\"file_contents\">". +	  "<pre class=\"".($focus ? "done" : "pending"). +	  "\" id=\"$shaid/0\">"); +    while (1) { +	my @frags = map { split(/(?<=\n)/, $_) } +	$markup->markupfile($subst, $parse); +	last unless @frags; +	foreach my $f (@frags) { +	    print($f) if $focus; +	    print($cache $f) if $cache; +	    if ($f =~ /\n$/s) { +		$line++; +		if ($line % FRAGMENT_SIZE == 0) { +		    print("<a class=\"line\"></a>\n" x FRAGMENT_SIZE) +			unless $focus; +		    if (defined($fline)) { +			$focus = ($line <= ($fline + 100) +				  and $line > ($fline - FRAGMENT_SIZE)); +		    } +		    print("</pre>". +			  "<pre class=\"". +			  ($focus ? "done" : "pending"). +			  "\" id=\"$shaid/$line\">"); +		    if ($cache) { +			close($cache); +			open($cache, '>', "$cfile/$line");  		    }  		}  	    } -	    print("</pre></div>\n"); -	    if ($cache) { -		close($cache); -		open($cache, '>', "$cfile/.complete"); -		close($cache); -	    }  	} -	return $shaid;      } +    print("</pre></div>\n"); +    if ($cache) { +	close($cache); +	open($cache, '>', "$cfile/.complete"); +	close($cache); +    } + +    return "gen:".$shaid;  }  sub print_error { @@ -225,15 +225,18 @@ sub source {      $pjx->js_encode_function('escape');      if ($context->prefs and $context->prefs->{'navmethod'} eq 'ajax') { +	print($query->header(-type => 'text/html', +			     -charset => 'utf-8'));  	if ($context->tree ne '') {  	    my $base = $context->base_url(1);  	    my $path = $context->vtree.'/'.$context->path; -	    print($query->redirect($base.'#'.$path)); +	    # print($query->redirect($base.'#'.$path)); + +	    $template->process('ajax_redir.tt2', +			       {'ajax_url' => $base.'#'.$path}) +		or die $template->error();  	}  	else { -	    print($query->header(-type => 'text/html', -				 -charset => 'utf-8')); -  	    if ($context->release eq 'trees') {  		print_tree_list($context, $template);  	    } diff --git a/tmpl/ajax_redir.tt2 b/tmpl/ajax_redir.tt2 new file mode 100644 index 0000000..54542bf --- /dev/null +++ b/tmpl/ajax_redir.tt2 @@ -0,0 +1,13 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" +"http://www.w3.org/TR/html4/loose.dtd"> +<html lang="en"> +  <head> +    <script type="text/javascript"> +      document.write('<meta http-equiv="refresh" content="0;url=[% ajax_url %]' +		     + location.hash + '">'); +    </script> +  </head> +  <body onload="location.href='[% ajax_url %]' + location.hash;"> +    <small>Redirecting to Ajax interface...</small> +  </body> +</html>  | 
