You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2011/03/27 00:30:10 UTC
svn commit: r1085828 - in /trafficserver/site/branches/ats-cms:
content/docs/trunk/admin/plugins/
content/docs/trunk/admin/plugins/header_filter/
content/docs/trunk/admin/plugins/mysql_remap/
content/docs/trunk/admin/plugins/stats_over_http/ lib/ templ...
Author: amc
Date: Sat Mar 26 23:30:10 2011
New Revision: 1085828
URL: http://svn.apache.org/viewvc?rev=1085828&view=rev
Log:
Fixed auto navigation link calculation.
Added:
trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/header_filter/index.en.mdtext
trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/index.en.mdtext
trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/mysql_remap/index.en.mdtext
trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/order.txt
trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/stats_over_http/index.en.mdtext
Modified:
trafficserver/site/branches/ats-cms/lib/view.pm
trafficserver/site/branches/ats-cms/templates/single_narrative.html
Added: trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/header_filter/index.en.mdtext
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/header_filter/index.en.mdtext?rev=1085828&view=auto
==============================================================================
--- trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/header_filter/index.en.mdtext (added)
+++ trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/header_filter/index.en.mdtext Sat Mar 26 23:30:10 2011
@@ -0,0 +1,25 @@
+Doc: Apache Traffic Server
+Title: Header Filter
+Notice: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ .
+ http://www.apache.org/licenses/LICENSE-2.0
+ .
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+Navigation: [*](*)
+ [SDK](../sdk/index.en.html)
+
+
+# Overview # {#overview}
+
+You can filter headers.
Added: trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/index.en.mdtext
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/index.en.mdtext?rev=1085828&view=auto
==============================================================================
--- trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/index.en.mdtext (added)
+++ trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/index.en.mdtext Sat Mar 26 23:30:10 2011
@@ -0,0 +1,25 @@
+Doc: Apache Traffic Server
+Title: Plugins
+Notice: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ .
+ http://www.apache.org/licenses/LICENSE-2.0
+ .
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+Navigation: [*](*)
+ [SDK](../sdk/index.en.html)
+
+
+# Overview # {#overview}
+
+Plugins are cool!
Added: trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/mysql_remap/index.en.mdtext
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/mysql_remap/index.en.mdtext?rev=1085828&view=auto
==============================================================================
--- trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/mysql_remap/index.en.mdtext (added)
+++ trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/mysql_remap/index.en.mdtext Sat Mar 26 23:30:10 2011
@@ -0,0 +1,25 @@
+Doc: Apache Traffic Server
+Title: MySQL Remap
+Notice: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ .
+ http://www.apache.org/licenses/LICENSE-2.0
+ .
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+Navigation: [*](*)
+ [SDK](../sdk/index.en.html)
+
+
+# Overview # {#overview}
+
+MySQL can help with remapping.
Added: trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/order.txt
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/order.txt?rev=1085828&view=auto
==============================================================================
--- trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/order.txt (added)
+++ trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/order.txt Sat Mar 26 23:30:10 2011
@@ -0,0 +1,3 @@
+header_filter
+mysql_remap
+stats_over_http
Added: trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/stats_over_http/index.en.mdtext
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/stats_over_http/index.en.mdtext?rev=1085828&view=auto
==============================================================================
--- trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/stats_over_http/index.en.mdtext (added)
+++ trafficserver/site/branches/ats-cms/content/docs/trunk/admin/plugins/stats_over_http/index.en.mdtext Sat Mar 26 23:30:10 2011
@@ -0,0 +1,25 @@
+Doc: Apache Traffic Server
+Title: Stats over HTTP
+Notice: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ .
+ http://www.apache.org/licenses/LICENSE-2.0
+ .
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+Navigation: [*](*)
+ [SDK](../sdk/index.en.html)
+
+
+# Overview # {#overview}
+
+Statistics are available via direct HTTP access to Traffic Server.
Modified: trafficserver/site/branches/ats-cms/lib/view.pm
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/lib/view.pm?rev=1085828&r1=1085827&r2=1085828&view=diff
==============================================================================
--- trafficserver/site/branches/ats-cms/lib/view.pm (original)
+++ trafficserver/site/branches/ats-cms/lib/view.pm Sat Mar 26 23:30:10 2011
@@ -15,16 +15,25 @@ use ASF::Util qw/read_text_file shuffle/
use File::Temp qw/tempfile/;
use LWP::Simple;
use File::Spec;
+use Cwd 'realpath';
+use Carp;
use constant ROOT_DIR => 'content';
+# Currently required suffix for content files.
+use constant SUFFIX => 'mdtext';
+# Language to use when we can't find what we want.
+use constant DEFAULT_LANG => 'en';
+# Where stem ordering data lives.
+# The top directory is the outermost directory that has an order file.
use constant ORDER_FILE => 'order.txt';
-# When we find this file during a directory ascent,
-# we've found the top documentation directory.
-use constant TOP_MARKER_FILE => 'STATUS';
# External variable file
use constant VAR_FILE => 'vars.txt';
+# Boolean constants
+use constant TRUE => 1;
+use constant FALSE => 0;
+
push @Dotiac::DTL::TEMPLATE_DIRS, "templates";
# This is most widely used view. It takes a
@@ -41,80 +50,16 @@ sub single_narrative {
$args{path} =~ s/\.mdtext$/\.html/;
$args{breadcrumbs} = breadcrumbs($args{path});
$args{langs} = langs($file);
+ my $chain = ascend($file);
# Debugging support
# This lets me set the style sheet correctly when writing
# to the local disk.
$args{style} = $ENV{TS_STYLE} if $ENV{TS_STYLE};
- # Shared variable support. We start at the top directory
- # and load header args from a magic file down to where
- # the target is.
- my @dirs = File::Spec->splitdir((File::Spec->splitpath($args{path}))[1]);
- shift @dirs if not $dirs[0];
- my $var_path = ROOT_DIR;
- # Descend to top dir
- while (@dirs and not -r File::Spec->catfile($var_path, TOP_MARKER_FILE)) {
- $var_path = File::Spec->catdir($var_path, shift @dirs);
- }
- warn "Failed to find base directory marker file from $file.\n" if not @dirs;
- # Now start reading var files.
- while (@dirs) {
- my $var_file = File::Spec->catfile($var_path, VAR_FILE);
- if (-r $var_file) {
- read_text_file $var_file, \%args;
- delete $args{content}; # discard any content.
- }
- $var_path = File::Spec->catdir($var_path, shift @dirs);
- }
-
- # Finally, read the actual target file.
+ load_vars($chain, \%args);
read_text_file $file, \%args;
-
- # Process any user supplied nav links.
- my $user_navs; # array ref of nav links from user data.
- my $user_nav_fill = 0; # Need to fill generated links from navigation?
- if ($args{headers}{navigation}) {
- ($user_navs, $user_nav_fill) = parse_links($args{headers}{navigation});
- }
- if ($user_navs) {
- # If user has marked nav links for fill from generated data,
- # find those and fill in the generated values.
- if ($user_nav_fill) {
- my %auto_navs;
- # Make a hash keyed on link text of the generated links.
- $auto_navs{$_->{text}} = $_ for (@{nav($file)});
- # Fill as appropriate.
- for (@$user_navs) {
- $_->{url} = $auto_navs{$_->{text}}->{url} if exists $auto_navs{$_->{text}} and $_->{url} eq '*';
- }
- # Clean out any navs that were marked for substitution but
- # didn't get matched.
- @$user_navs = grep { $_->{url} ne '*' } @$user_navs;
- }
- $args{nav} = $user_navs;
- } else {
- $args{nav} = nav($file);
- }
- # Clean up empty lists
- delete $args{nav} if ref $args{nav} eq 'ARRAY' and not @{$args{nav}};
-
- my $page_path = $file;
- $page_path =~ s/\.[^.]+$/.page/;
- if (-d $page_path) {
- for my $f (grep -f, glob "$page_path/*.mdtext") {
- $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n";
- $args{$1} = {};
- read_text_file $f, $args{$1};
- # pre process $args{content} to include language links.
- # this is ugly
- $f =~ s/.+?\.([^.]+)\.mdtext/$1/;
- my $fl = glob "$f*";
- $fl =~ s/.+?\.([^.]+)\.mdtext/ [$1]($1) |/g;
- chop $fl;
- $args{content} =~ s/\[LANG\]/$fl/;
- }
- }
+ nav_links($chain, \%args);
return Dotiac::DTL::Template($template)->render(\%args), html => \%args;
}
@@ -244,126 +189,246 @@ sub breadcrumbs {
return join " » ", @rv;
}
+# Split a content file in to its parts - ( stem, lang, format )
+sub split_content_name {
+ my @zret = ('', '', ''); # default to empty strings.
+ $_[0] =~ m!([^/]+)$!; # strip any leading directories.
+ my (undef, undef, $name) = File::Spec->splitpath($_[0]);
+ confess 'Invalid content file path "', $_[0], "\"\n" unless $name;
+ @zret = ($1, $2, $3) if $name =~ m!([^.]+)[.]([^.]+)[.]([^.]+)$!;
+ return @zret;
+}
+
+# Return a list of the stems in a directory.
+# - Directory path.
+sub load_stems {
+ my ($dir) = @_;
+ # Two things to count -- language based files and directories.
+ my %stems;
+ for (glob(File::Spec->catfile($dir, '*'))) {
+ my $name = (File::Spec->splitpath($_))[2];
+ if (-d $_) {
+ $stems{$name} = 1;
+ } elsif (my $stem = (split_content_name($name))[0]) {
+ $stems{$stem} = 1;
+ }
+ }
+ return keys %stems;
+}
+
+# Args
+# - Directory with order file.
+# - Array ref to update with ordering if stem matched.
+# If there is no order file, but only one stem, then an ordering is
+# synthesized.
+# 0 if failed to load order file, non-0 otherwise.
+sub load_ordering {
+ my ($path, $order_ref) = @_;
+ my $zret = FALSE;
+ my $file= File::Spec->catfile($path, ORDER_FILE);
+ if (open my $fh, '<', $file) {
+ local $/; # Grab the entire file
+ my @order = split(/\s+/, <$fh>);
+ # index is special - remove it if present and put it first.
+ @order = grep { ! /^index$/o } @order;
+ unshift(@order, 'index');
+ @$order_ref = @order; # copy over if we found stem.
+ close $fh;
+ $zret = TRUE;
+ } elsif (1 == scalar(my @stems = load_stems($path))) {
+ # If there's only one stem, the order is implied and no explicit file
+ # is required.
+ @$order_ref = @stems;
+ $zret = TRUE;
+ }
+ return $zret;
+}
+
+# This walks the directories up until we hit the top.
+# Accumulate orderings as we go (when we run out, that's the top).
+# Args - Path to content file.
+# Returns array ref of directory chain.
+sub ascend {
+ my ($src_path) = @_;
+ my ($vol, $src_dir, $src_file) = File::Spec->splitpath($src_path);
+ $src_dir =~ s!/+$!!;
+ my @dirs = File::Spec->splitdir($src_dir);
+ my ($stem, $lang, $ext) = split_content_name($src_file);
+ my $rpath = '.'; # path relative to source content file.
+ my @chain; # Ordered list of directory descriptors.
+
+ while (@dirs) {
+ my @order;
+ my $path = File::Spec->catdir(@dirs);
+ # Stop when we can't load an ordering.
+ last unless load_ordering($path, \@order);
+ # Save data that will be useful later.
+ my %entry = (
+ order => \@order,
+ path => $path,
+ rpath => $rpath,
+ stem => $stem
+ );
+ my $var_path = File::Spec->catfile($path, VAR_FILE);
+ $entry{var_file} = $var_path if -r $var_path;
+ push(@chain, \%entry);
+ # Set up for next iteration
+ $rpath = File::Spec->catdir($rpath, '..');
+ $stem = pop @dirs;
+ }
+
+ # Add lang to last element which is the content file.
+ $chain[0]->{lang} = $lang;
+
+ return \@chain;
+}
+
+# Return the index of target in an array, -1 if not found.
+# Args - target to find
+# - list to search (array ref)
+sub index_of {
+ my ($target, $list) = @_;
+ my $idx = 0;
+ for my $item (@$list) {
+ return $idx if $item eq $target;
+ ++$idx;
+ }
+ return -1;
+}
+
# Args
# - Path to prospective order file.
# - Local stem.
-# - Array ref to update with ordering if stem matched.
+# - Array ref to update with ordering.
# Return the index of the stem if found, -1 if not.
-sub order_probe {
+sub probe_ordering {
my ($path, $stem, $order_ref) = @_;
$path = File::Spec->catfile($path, ORDER_FILE);
my $idx = -1; # return, default to fail.
- if (open my $fh, '<', $path) {
- local $/; # Grab the entire file
- my @order = split(/\s+/, <$fh>);
- my $n = scalar @order;
- # Look for our stem and get the index if found.
- $idx = 0;
- ++$idx while $idx < $n and $order[$idx] ne $stem;
- if ($idx < $n) {
- @$order_ref = @order; # copy over if we found stem.
- } else {
- $idx = -1; # Fail.
- }
- close $fh;
+ if (load_ordering($path, $order_ref)) {
+ $idx = index_of($stem, $order_ref);
}
+ warn "Order file '$path' does not contain stem '$stem'\n" if $idx < 0;
return $idx;
}
-# Args
-# - Base directory.
-# - Target stem.
-# - Language tag.
-# Return
-# A relative path to the target.
-sub target_finder {
- my ($path, $prefix, $stem, $lang) = @_;
- my $file;
- my $pattern;
- my @candidates;
- my $abs = File::Spec->catdir($path, $stem);
- if (-d $abs) { # Target is a directory, look inside.
- $pattern = File::Spec->catfile($abs, '*.' . $lang . '.*');
- if ($prefix) {
- $prefix = File::Spec->catdir($prefix, $stem);
+# Shared variable support.
+# Arguments
+# - Directory chain (array ref)
+# - Hash ref to template arguments.
+sub load_vars {
+ my ($chain, $args) = @_;
+ # Load the variables, starting at the top so that lower directories
+ # override.
+ for my $d (reverse @$chain) {
+ read_text_file $d->{var_file}, $args if exists $d->{var_file};
+ }
+ delete $args->{content}; # discard any content.
+}
+
+# Return base file name of target, undef if not found.
+# - Directory path.
+# - Stem
+# - Target language.
+sub probe_content {
+ my ($dir, $stem, $lang) = @_;
+ confess unless $stem and $lang;
+ if (! -r File::Spec->catfile($dir, "$stem.$lang." . SUFFIX)) {
+ $lang = DEFAULT_LANG;
+ if (! -r File::Spec->catfile($dir, "$stem.$lang." . SUFFIX)) {
+ $lang = undef;
+ }
+ }
+ return $lang ? "$stem.$lang.html" : undef;
+}
+
+# Return relative path to the leftmost leaf.
+# - Starting directory.
+# - Initial stem.
+# - Language
+# - Relative path to start.
+sub left_leaf {
+ my ($dir, $stem, $lang, $rpath) = @_;
+ my $zret = ''; # Relative path to target.
+ # Content file for this stem?
+ if (my $file = probe_content($dir, $stem, $lang)) {
+ $zret = File::Spec->catfile($rpath, $file);
+ } elsif (-d (my $path = File::Spec->catdir($dir, $stem))) {
+ $rpath = File::Spec->catdir($rpath, $stem);
+ # Is there ordering data?
+ my @order;
+ if (load_ordering($path, \@order)) {
+ return left_leaf($path, $order[0], $lang, $rpath);
} else {
- $prefix = $stem;
+ warn "Directory '$path' has no order file and is not a singleton stem.\n";
}
- } else { # look in the base directory.
- $pattern = File::Spec->catfile($path, $stem . '.' . $lang . '.*');
+ } else {
+ warn "Failed to find target in language '$lang' or default '"
+ , DEFAULT_LANG, "' for stem '$stem' in directory $path\n";
}
- @candidates = glob($pattern);
+ return $zret;
+}
- if (scalar @candidates) {
- $file = (File::Spec->splitpath($candidates[0]))[2];
- $file =~ s/[.][^.]*$/.html/;
+# Return relative path to the rightmost leaf.
+# - Starting directory.
+# - Initial stem.
+# - Language
+# - Relative path to start.
+sub right_leaf {
+ my ($dir, $stem, $lang, $rpath) = @_;
+ my $zret = ''; # Relative path to target.
+ # Content file for this stem?
+ if (my $file = probe_content($dir, $stem, $lang)) {
+ $zret = File::Spec->catfile($rpath, $file);
+ } elsif (-d (my $path = File::Spec->catdir($dir, $stem))) {
+ $rpath = File::Spec->catdir($rpath, $stem);
+ # Is there ordering data?
+ my @order;
+ if (load_ordering($path, \@order)) {
+ return right_leaf($path, pop @order, $lang, $rpath);
+ } else {
+ warn "Directory '$dir' has no order file and is not a singleton stem.\n";
+ }
} else {
- warn "Could not find file for target '$stem', language '$lang', in '$path'\n";
- $file = 'index.en.html';
+ warn "Failed to find target in language '$lang' or default '"
+ , DEFAULT_LANG, "' for stem '$stem' in directory $path\n";
}
- $file = File::Spec->catfile($prefix, $file) if $prefix;
- return $file;
+ return $zret;
}
+# Args - Directory chain.
# Return a hash that contains navigation bar data.
-# Structural assumptions -
-# The actual file being processed is in a directory that corresponds
-# to the content, with multiple files for different languages.
-# Therefore the orderinging file is one level up and orders the
-# content directories.
-sub nav {
- my $path = shift;
+sub auto_nav {
+ my ($chain) = shift;
my @nav; # return: Array of nav items
- my ($vol, $dirs, $src) = File::Spec->splitpath($path);
- $dirs =~ s!/+$!!; # So freaking annoying! Why do I have to do this?
- my @dirs = File::Spec->splitdir($dirs);
- # Language tag should be the second dotted element.
- my $lang = $src;
- $lang =~ s/^[^.]+[.]//;
- $lang =~ s/[.].*$//;
- my $stem = $src;
- $stem =~ s/[.].*$//;
-
- # Find the ordering file. We check the current directory
- # first. If that doesn't work, use the containing directory name
- # and check the next directory up.
- my @order;
- my $idx = order_probe($dirs, $stem, \@order);
- my $prefix; # Relative path from source file directory to base directory.
- if ($idx < 0) {
- # That didn't work. Try popping up a directory.
- $stem = pop @dirs; # Use directory name as stem.
- $dirs = File::Spec->catdir(@dirs);
- $idx = order_probe($dirs, $stem, \@order);
- $prefix = '..';
- }
-
- if ($idx >= 0) {
- # Look for the top directory.
- # This is the file name. If we popped up to find the ordering,
- # make that adjustment. Then add another parent directory until
- # we find the top file marker.
- my $top_url = 'index.' . $lang . '.html';
- $top_url = File::Spec->catfile($prefix, $top_url) if $prefix;
- while (@dirs) {
- pop @dirs;
- my $pdir = File::Spec->catfile(@dirs);
- my $top_mark = File::Spec->catfile($pdir, TOP_MARKER_FILE);
- last if (-r $top_mark);
- $top_url = File::Spec->catfile('..', $top_url);
- }
- push(@nav, { url => $top_url, text => 'Top' });
+ my $lang = $chain->[0]->{lang};
+ my $prefix; # path relative to source content file.
- push (@nav, {
- url => target_finder($dirs, $prefix, $order[$idx+1], $lang),
- text => 'Next'
- }) if $idx < scalar(@order) -1;
-
- push(@nav, {
- url => target_finder($dirs, $prefix, $order[$idx-1], $lang),
- text => 'Back'
- }) if $idx > 0;
+ # Flags for next and back links.
+ # We don't insert directly because we need to force a specific ordering.
+ my $next_url;
+ my $back_url;
+
+ # Ascend the directory chain, watching for branch points left and right.
+ for my $entry (@$chain) {
+ my $order = $entry->{order};
+ my $idx = index_of($entry->{stem}, $order);
+ if (!$next_url && $idx < scalar(@$order) - 1 ) {
+ $next_url = left_leaf($entry->{path}, $order->[$idx+1], $lang, $entry->{rpath});
+ }
+ if (!$back_url && $idx > 0) {
+ $back_url = right_leaf($entry->{path}, $order->[$idx-1], $lang, $entry->{rpath});
+ }
+ last if ($next_url and $back_url);
}
+
+ my $top = $chain->[$#$chain];
+ my $top_url = File::Spec->catfile($top->{rpath}, probe_content($top->{path}, $top->{order}->[0], $lang));
+ # Put in the nav links, in correct order.
+ push (@nav, { url => $next_url, text => 'Next' }) if $next_url;
+ push (@nav, { url => $back_url, text => 'Back' }) if $back_url;
+ push (@nav, { url => $top_url, text => 'Top' }) if $top_url;
+
return \@nav;
}
@@ -382,8 +447,61 @@ sub parse_links {
return ( \@links , $need_fill );
}
+# Generate the nav link data.
+# Arguments
+# - Directory chain
+# - Template args (hash ref)
+sub nav_links {
+ my ($chain, $args) = @_;
+
+ # Imp Note: DOTIAC is broken and treats an empty array as "true"
+ # when it should be "false". So we must avoid setting the nav link
+ # arg if the list is empty.
+
+ # Process any user supplied nav links.
+ my $explicit; # array ref of nav links from user data.
+ my $fill = 0; # Need to fill generated links from navigation?
+ if ($args->{headers}{navigation}) {
+ ($explicit, $fill) = parse_links($args->{headers}{navigation});
+ }
+ if ($explicit) {
+ # If user has marked nav links for fill from generated data,
+ # find those and fill in the generated values.
+ if ($fill) {
+ # Get the auto navs and then make a hash keyed by text.
+ my $auto_list = auto_nav($chain);
+ my %auto_map = map { $_->{text} => $_ } @$auto_list;
+ # Do the direct fills
+ for (@$explicit) {
+ if (exists $auto_map{$_->{text}} and $_->{url} eq '*') {
+ my $tag = $_->{text};
+ $_->{url} = $auto_map{$tag}->{url};
+ $auto_map{$tag}->{used} = 1;
+ }
+ }
+ # Do it again and do the generic fill, if any.
+ # Need to do generic fill separately so we don't duplicate.
+ my @unused = grep {
+ not exists $auto_map{$_->{text}}{used}
+ } @$auto_list;
+
+ @$explicit = map {
+ $_->{text} eq '*' && $_->{url} eq '*' ? @unused : $_;
+ } @$explicit if @unused;
+
+ # Clean out any navs that were marked for substitution but
+ # didn't get matched.
+ @$explicit = grep { $_->{url} ne '*' } @$explicit;
+ }
+ $args->{nav} = $explicit if @$explicit;
+ } else {
+ my $auto_navs = auto_nav($chain);
+ $args->{nav} = $auto_navs if @$auto_navs;
+ }
+}
+
# Arg: Target file path.
-# Return: List of links
+# Return: List of link objects.
sub langs {
my ($path) = @_;
my @langs; # Return: List of link objects.
Modified: trafficserver/site/branches/ats-cms/templates/single_narrative.html
URL: http://svn.apache.org/viewvc/trafficserver/site/branches/ats-cms/templates/single_narrative.html?rev=1085828&r1=1085827&r2=1085828&view=diff
==============================================================================
--- trafficserver/site/branches/ats-cms/templates/single_narrative.html (original)
+++ trafficserver/site/branches/ats-cms/templates/single_narrative.html Sat Mar 26 23:30:10 2011
@@ -40,7 +40,7 @@
<div class="main">
{% if langs %}
<div class="lang">
- Languages:
+ {{ AltLangText|default:"Languages" }}:
{% for lang in langs %}
<a href="{{lang.url}}" class="lang">{{lang.text}}</a>
{% endfor %}