You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2014/12/11 18:21:14 UTC

svn commit: r1644706 - in /incubator/tamaya/site/trunk/lib: path.pm view.pm

Author: anatole
Date: Thu Dec 11 17:21:14 2014
New Revision: 1644706

URL: http://svn.apache.org/r1644706
Log:
TAMAYA-21: Initial page setup, added missing templates.

Modified:
    incubator/tamaya/site/trunk/lib/path.pm
    incubator/tamaya/site/trunk/lib/view.pm

Modified: incubator/tamaya/site/trunk/lib/path.pm
URL: http://svn.apache.org/viewvc/incubator/tamaya/site/trunk/lib/path.pm?rev=1644706&r1=1644705&r2=1644706&view=diff
==============================================================================
--- incubator/tamaya/site/trunk/lib/path.pm (original)
+++ incubator/tamaya/site/trunk/lib/path.pm Thu Dec 11 17:21:14 2014
@@ -1,40 +1,49 @@
-package path;
-
-# taken from django's url.py
-
-our @patterns = (
-	[qr!\.md(?:text)?$!, single_narrative => { template => "single_narrative.html" }],
-
-	[qr!/sitemap\.html$!, sitemap => { headers => { title => "Sitemap" }} ],
-
-) ;
-
-
-# for specifying interdependencies between files
-
-our %dependencies = (
-    "/sitemap.html" => [ grep s!^content!!, glob("content/*.mdtext"), glob "content/*.md" ],
-);
-
-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.
-
-
+package path;
+
+use DS;
+
+# taken from django's url.py
+
+our @patterns = (
+
+  [qr!^/index\.html$!, interpreted => { template => "tamaya-markdown.html" }],
+  [qr!^/contributors\.html$!, interpreted => {
+        headers => { title => "Contributors", css => "contributors.css" },
+        template => "tamaya-markdown.html",
+        contributors => DS->contributors
+      }
+  ],
+
+	[qr!\.md(text)?$!, basic => { template => "tamaya-markdown.html" }],
+
+	[qr!/sitemap\.html$!, sitemap => { headers => { title => "Sitemap" }} ],
+) ;
+
+# for specifying interdependencies between files
+
+our %dependencies = (
+    "/sitemap.html" => [ grep s!^content!!, glob "content/*.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.
+
+

Modified: incubator/tamaya/site/trunk/lib/view.pm
URL: http://svn.apache.org/viewvc/incubator/tamaya/site/trunk/lib/view.pm?rev=1644706&r1=1644705&r2=1644706&view=diff
==============================================================================
--- incubator/tamaya/site/trunk/lib/view.pm (original)
+++ incubator/tamaya/site/trunk/lib/view.pm Thu Dec 11 17:21:14 2014
@@ -1,23 +1,214 @@
-package view;
-use base 'ASF::View'; # see https://svn.apache.org/repos/infra/websites/cms/build/lib/ASF/View.pm
-
-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.
+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 *TEMPLATE_DIRS/;
+use Dotiac::DTL::Addon::markup;
+use Dotiac::DTL::Value;
+use Dotiac::DTL::Filter;
+use XML::Simple;
+use Data::Dumper;
+use Text::Markdown qw( markdown );
+use ASF::Util qw/read_text_file/;
+
+push @TEMPLATE_DIRS, "templates";
+
+
+sub interpreted {
+    my %args = @_;
+    my $template = "content$args{path}";
+
+    print "interpreted -> $template\n";
+
+    $args{breadcrumbs} = breadcrumbs($args{path});
+
+    my $page_path = $template;
+
+    $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 Template($template)->render(\%args), html => \%args;
+}
+
+# A "basic" view, which takes 'template' and 'path' parameters.
+
+sub basic {
+    my %args = @_;
+    my $filepath = "content$args{path}";
+
+    print "basic $filepath";
+
+    read_text_file($filepath, \%args);
+
+    $args{path} =~ s/\.mdtext$/\.html/;
+    $args{base} = _base($args{path});
+    $args{breadcrumbs} = _breadcrumbs($args{path}, $args{base});
+
+    my $template_path = "templates/$args{template}";
+    my @includes = ($args{content} =~ m/{include:([^ ]+?)}/g);
+
+    foreach my $include (@includes) {
+
+        next unless ( -e "content/$include");
+
+        my %a = ();
+
+        read_text_file("content/$include", \%a);
+        my $text = $a{content};
+        $args{headers}{title} = $a{headers}{title} unless $args{headers}{title};
+
+        # If the file to be included is in a child directory, resolve all the links
+        # in the included content to be relative to this document
+        if ($include =~ m,/,) {
+            my $ipath = $include;
+            $ipath =~ s,/[^/]*$,,;
+            $text =~ s,(\[[^[]+])\(([^/][^)]+)\),$1($ipath/$2),g;
+        }
+
+        $args{content} =~ s/{include:$include}/$text/g;
+    }
+
+    print " - rendering";
+
+    my $rendered = Dotiac::DTL->new($template_path)->render(\%args);
+
+    print " - complete\n";
+
+    return ($rendered, 'html', \%args);
+}
+
+
+sub sitemap {
+    my %args = @_;
+    my $template = "content$args{path}";
+    $args{breadcrumbs} .= breadcrumbs($args{path});
+    my $dir = $template;
+    $dir =~ s!/[^/]+$!!;
+    my %data;
+    for (map "content$_", @{$path::dependencies{$args{path}}}) {
+        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;
+}
+
+sub _breadcrumbs {
+    my $path        = shift;
+    my $base        = shift;
+
+    my $index = "$base/index.html";
+    $index =~ s,/+,/,g;
+
+    my @breadcrumbs = (
+        qq|<a href="$index">Home</a>|,
+    );
+    my @path_components = split( m!/!, $path );
+    pop @path_components;
+
+    my $relpath = $base;
+
+
+    for (@path_components) {
+        $relpath .= "$_/";
+        $relpath =~ s,/+,/,g;
+        next unless $_;
+
+        my @names = split("-", $_);
+        my $name = "";
+        for my $n (@names) {
+            $name .= ucfirst($n) . " ";
+        }
+        $name =~ s/ *$//;
+        push @breadcrumbs, qq(<a href="$relpath">\u$name</a>);
+    }
+    return join "&nbsp;&raquo&nbsp;", @breadcrumbs;
+}
+
+sub _base {
+    my $path        = shift;
+
+    my @path_components = split( m!/!, $path );
+    pop @path_components;
+    pop @path_components;
+
+    my $rel = "./";
+
+    for (@path_components) {
+        $rel .= "../";
+    }
+
+    return $rel;
+}
+
+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.