You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by br...@apache.org on 2014/01/14 18:20:45 UTC

svn commit: r1558117 - in /hive/cms/trunk: content/index.mdtext lib/view.pm

Author: brock
Date: Tue Jan 14 17:20:44 2014
New Revision: 1558117

URL: http://svn.apache.org/r1558117
Log:
NEW WEBSITE: Fixing links and adding view module

Modified:
    hive/cms/trunk/content/index.mdtext
    hive/cms/trunk/lib/view.pm

Modified: hive/cms/trunk/content/index.mdtext
URL: http://svn.apache.org/viewvc/hive/cms/trunk/content/index.mdtext?rev=1558117&r1=1558116&r2=1558117&view=diff
==============================================================================
--- hive/cms/trunk/content/index.mdtext (original)
+++ hive/cms/trunk/content/index.mdtext Tue Jan 14 17:20:44 2014
@@ -4,11 +4,11 @@ The Apache Hive ™ data warehouse s
 
 ## Getting Started
 
-Check out the [Getting Started Guide](GETTING_STARTED) on the [Hive wiki](HIVE_WIKI).
+Check out the [Getting Started Guide][GETTING_STARTED] on the [Hive wiki][HIVE_WIKI].
 
 ## Getting Involved
 
-Hive is an open source volunteer project under the Apache Software Foundation. Previously it was a subproject of [Apache Hadoop](APACHE_HADOOP), but has now graduated to become a top-level project of its own. We encourage you to learn about the project and contribute your expertise. Here are some starter links:
+Hive is an open source volunteer project under the Apache Software Foundation. Previously it was a subproject of [Apache Hadoop][APACHE_HADOOP], but has now graduated to become a top-level project of its own. We encourage you to learn about the project and contribute your expertise. Here are some starter links:
 
   * Give us feedback: What can we do better?
   * Join the mailing list: Meet the community.

Modified: hive/cms/trunk/lib/view.pm
URL: http://svn.apache.org/viewvc/hive/cms/trunk/lib/view.pm?rev=1558117&r1=1558116&r2=1558117&view=diff
==============================================================================
--- hive/cms/trunk/lib/view.pm (original)
+++ hive/cms/trunk/lib/view.pm Tue Jan 14 17:20:44 2014
@@ -1,5 +1,209 @@
 package view;
-use base 'ASF::View'; # see https://svn.apache.org/repos/infra/websites/cms/build/lib/ASF/View.pm
+
+# BUILD CONSTRAINT:  all views must return $content, $extension.
+# additional return values (as seen below) are optional.  However,
+# careful use of symlinks and dependency management in path.pm can
+# resolve most issues with this constraint.
+
+use strict;
+use warnings;
+use integer;
+use Dotiac::DTL qw/Template *TEMPLATE_DIRS/;
+use Dotiac::DTL::Addon::markup;
+use ASF::Util qw/read_text_file shuffle/;
+use File::Temp qw/tempfile/;
+
+push our @TEMPLATE_DIRS, "templates";
+
+# This is most widely used view.  It takes a
+# 'template' argument and a 'path' argument.
+# Assuming the path ends in foo.mdtext, any files
+# like foo.page/bar.mdtext will be parsed and
+# passed to the template in the "bar" (hash)
+# variable.
+
+sub single_narrative {
+    my %args = @_;
+    my %styleargs = @_;
+    my $file = "content$args{path}";
+    my $template = $args{template};
+    $args{path} =~ s/\.mdtext$/\.html/;
+    $args{breadcrumbs} = breadcrumbs($args{path});
+
+    read_text_file $file, \%args;
+
+    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};
+        }
+    }
+    
+    $args{content} = sort_tables($args{content});
+    $args{sidenav} = 1;
+
+    my $style_path = $file;
+    $style_path =~ s/\.[^.]+$/.style/;
+    if (-f $style_path) {
+	read_text_file $style_path, \%styleargs;
+	$args{scriptstyle} = $styleargs{content};
+    }
+
+    return Template($template)->render(\%args), html => \%args;
+}
+
+# This view is used to wrap html.  It takes a
+# 'template' argument and a 'path' argument.
+# Assuming the path ends in foo.html, any files
+# like foo.page/bar.mdtext will be parsed and
+# passed to the template in the "bar" (hash)
+# variable.
+
+sub html_page {
+    my %args = @_;
+    my %styleargs = @_;
+    my $file = "content$args{path}";
+    my $template = $args{template};
+    $args{breadcrumbs} = breadcrumbs($args{path});
+
+    read_text_file $file, \%args;
+
+    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};
+        }
+    }
+
+    $args{header} = `sed -n '/<head>/,/<\\/head>/p' ${file} | sed -e '1s/.*<head>//' -e 's/<\\/head>.*//'`;
+    $args{content} = `sed -n '/<body>/,/<\\/body>/p' ${file} | sed -e '1s/.*<body>//' -e "s/<\\/body>.*//"`;
+
+    return Template($template)->render(\%args), html => \%args;
+}
+
+sub sitemap {
+    my %args = @_;
+    my $template = "content$args{path}";
+    $args{breadcrumbs} .= breadcrumbs($args{path});
+    my $dir = $template;
+    $dir =~ s!/[^/]+$!!;
+    opendir my $dh, $dir or die "Can't opendir $dir: $!\n";
+    my %data;
+    for (map "$dir/$_", grep $_ ne "." && $_ ne ".." && $_ ne ".svn", readdir $dh) {
+        if (-f and /\.mdtext$/) {
+            my $file = $_;
+            $file =~ s/^content//;
+            no warnings 'once';
+            for my $p (@path::patterns) {
+                my ($re, $method, $args) = @$p;
+                next unless $file =~ $re;
+                my $s = view->can($method) or die "Can't locate method: $method\n";
+                my ($content, $ext, $vars) = $s->(path => $file, %$args);
+                $file =~ s/\.mdtext$/.$ext/;
+                $data{$file} = $vars;
+                last;
+            }
+        }
+    }
+
+    my $content = "";
+
+    for (sort keys %data) {
+        $content .= "- [$data{$_}->{headers}->{title}]($_)\n";
+        for my $hdr (grep /^#/, split "\n", $data{$_}->{content}) {
+            $hdr =~ /^(#+)\s+([^#]+)?\s+\1\s+\{#([^}]+)\}$/ or next;
+            my $level = length $1;
+            $level *= 4;
+            $content .= " " x $level;
+            $content .= "- [$2]($_#$3)\n";
+        }
+    }
+    $args{content} = $content;
+    return Template($template)->render(\%args), html => \%args;
+}
+
+sub breadcrumbs {
+    my @path = split m!/!, shift;
+    pop @path;
+    my @rv;
+    my $relpath = "";
+    for (@path) {
+        $relpath .= "$_/";
+        $_ ||= "Home";
+        push @rv, qq(<a href="$relpath">\u$_</a>);
+    }
+    return join "&nbsp;&raquo&nbsp;", @rv;
+}
+
+# arbitrary number of tables supported, but only one col per table may be sorted
+sub sort_tables {
+    my @orig = split /\n/, shift, -1;
+    my @out;
+    while (defined(local $_ = shift @orig))  {
+        push @out, $_;
+        /^(\|[ :23456vn^-]+)+\|$/ or next;
+        my($data, $col, $direction, $cur, $numeric, $grps);
+        $cur = 0;
+        while (/\|([ :23456vn^-]+)/g) {
+            $data = $1;
+	    # check for number of row/column groups. There is certainly a better way.
+            $grps = 2 if $data =~ tr/2/2/;
+            $grps = 3 if $data =~ tr/3/3/;
+            $grps = 4 if $data =~ tr/4/4/;
+            $grps = 5 if $data =~ tr/5/5/;
+            $grps = 6 if $data =~ tr/6/6/;
+            # check for numeric sort
+            $numeric = 1 if $data =~ tr/n/n/;
+            # check for sort
+            if ($data =~ tr/v/v/) {
+                $col = $cur;
+                $direction = -1;
+                last;
+            }
+            elsif ($data =~ tr/^/^/) {
+                $col = $cur;
+                $direction = 1;
+                last;
+            }
+            $cur++;
+        }
+        unless (defined $col or defined $grps) { # no special reorganization - simply output
+            push @out, shift @orig while @orig and $orig[0] =~ /^\|/;
+            next;
+        }
+        my @rows;
+        push @rows, [split /\s*\|\s*/, shift(@orig), -1]
+            while @orig and $orig[0] =~ /^\|/;
+        shift @$_, pop @$_ for @rows; # dump empty entries at ends
+        if (defined $col) {  # perform sort
+            @rows = $numeric
+                ? sort { $a->[$col] <=> $b->[$col] } @rows
+                : sort { $a->[$col] cmp $b->[$col] } @rows;
+            @rows = reverse @rows if $direction == -1;
+        }
+        if (defined $grps) {  # row-column groups
+            my($nrows,$icol,$jrow,$row);
+            $nrows = ($#rows / $grps) + 1; # requires use integer
+            for ($jrow = 0; $jrow < $nrows; $jrow++ ) {
+                $row = "| ";
+                for ($icol = $jrow; $icol <= $#rows; $icol += $nrows ) {
+                    $row .= join(" | ", @{$rows [$icol]} ) . " |";
+                }
+                push @out, $row;
+            }
+        }
+        else {
+            push @out, map "| " . join(" | ", @$_) . " |", @rows;
+        }
+    }
+    return join "\n", @out;
+}
 
 1;