zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1038682 - in /zookeeper/site: branches/ trunk/ trunk/cgi-bin/ trunk/content/ trunk/lib/ trunk/lib/path.pm trunk/lib/view.pm trunk/templates/ trunk/templates/single_narrative.html
Date Wed, 24 Nov 2010 16:45:36 GMT
Author: joes
Date: Wed Nov 24 16:45:35 2010
New Revision: 1038682

URL: http://svn.apache.org/viewvc?rev=1038682&view=rev
Log:
zookeeper site layout

Added:
    zookeeper/site/branches/
    zookeeper/site/trunk/
    zookeeper/site/trunk/cgi-bin/
    zookeeper/site/trunk/content/
    zookeeper/site/trunk/lib/
    zookeeper/site/trunk/lib/path.pm   (with props)
    zookeeper/site/trunk/lib/view.pm   (with props)
    zookeeper/site/trunk/templates/
    zookeeper/site/trunk/templates/single_narrative.html   (with props)

Added: zookeeper/site/trunk/lib/path.pm
URL: http://svn.apache.org/viewvc/zookeeper/site/trunk/lib/path.pm?rev=1038682&view=auto
==============================================================================
--- zookeeper/site/trunk/lib/path.pm (added)
+++ zookeeper/site/trunk/lib/path.pm Wed Nov 24 16:45:35 2010
@@ -0,0 +1,37 @@
+package path;
+use ASF::Value;
+
+# taken from django's url.py
+
+our @patterns = (
+
+    [qr!\.mdtext$!, single_narrative => { template => "single_narrative.html" }],
+);
+
+
+# for specifying interdependencies between files
+
+#our %dependencies = (
+#    "/dev/sitemap.html" => [ grep s!^content!!, glob "content/dev/*.mdtext" ],
+#);
+
+1;
+
+=head1 LICENSE
+
+           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.

Propchange: zookeeper/site/trunk/lib/path.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: zookeeper/site/trunk/lib/view.pm
URL: http://svn.apache.org/viewvc/zookeeper/site/trunk/lib/view.pm?rev=1038682&view=auto
==============================================================================
--- zookeeper/site/trunk/lib/view.pm (added)
+++ zookeeper/site/trunk/lib/view.pm Wed Nov 24 16:45:35 2010
@@ -0,0 +1,123 @@
+package view;
+
+#
+# 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 Dotiac::DTL qw/Template/;
+use Dotiac::DTL::Addon::markup;
+use ASF::Util qw/read_text_file/;
+use File::Temp qw/tempfile/;
+use LWP::Simple;
+
+push @Dotiac::DTL::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 $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};
+        }
+    }
+
+    return Dotiac::DTL::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 Dotiac::DTL::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;
+}
+
+1;
+
+=head1 LICENSE
+
+           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.

Propchange: zookeeper/site/trunk/lib/view.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: zookeeper/site/trunk/templates/single_narrative.html
URL: http://svn.apache.org/viewvc/zookeeper/site/trunk/templates/single_narrative.html?rev=1038682&view=auto
==============================================================================
--- zookeeper/site/trunk/templates/single_narrative.html (added)
+++ zookeeper/site/trunk/templates/single_narrative.html Wed Nov 24 16:45:35 2010
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+  <head>
+    <title>{{ headers.title }}</title>
+  </head>
+
+  <body>
+    <h1>{{ headers.title }}</h1>
+
+    <div id="content">{{ content|markdown }}</div>
+
+  </body>
+</html>

Propchange: zookeeper/site/trunk/templates/single_narrative.html
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message