roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gma...@apache.org
Subject svn commit: r1610764 - in /roller/cmssite/trunk/lib: path.pm view.pm
Date Tue, 15 Jul 2014 17:25:05 GMT
Author: gmazza
Date: Tue Jul 15 17:25:04 2014
New Revision: 1610764

URL: http://svn.apache.org/r1610764
Log:
Updated Roller's CMS scripts to those of Isis'

Modified:
    roller/cmssite/trunk/lib/path.pm
    roller/cmssite/trunk/lib/view.pm

Modified: roller/cmssite/trunk/lib/path.pm
URL: http://svn.apache.org/viewvc/roller/cmssite/trunk/lib/path.pm?rev=1610764&r1=1610763&r2=1610764&view=diff
==============================================================================
--- roller/cmssite/trunk/lib/path.pm (original)
+++ roller/cmssite/trunk/lib/path.pm Tue Jul 15 17:25:04 2014
@@ -3,8 +3,8 @@ package path;
 # taken from django's url.py
 
 our @patterns = (
-	[qr!/glentest.mdtext$!, single_narrative => { template => "test.html" }],
-	[qr!\.mdtext$!, single_narrative => { template => "basic.html" }],
+	[qr!/glentest.mdtext$!, basic => { template => "test.html" }],
+	[qr!\.mdtext$!, basic => { template => "basic.html" }],
 ) ;
 
 # [qr!/sitemap\.html$!, sitemap => { headers => { title => "Sitemap" }} ],

Modified: roller/cmssite/trunk/lib/view.pm
URL: http://svn.apache.org/viewvc/roller/cmssite/trunk/lib/view.pm?rev=1610764&r1=1610763&r2=1610764&view=diff
==============================================================================
--- roller/cmssite/trunk/lib/view.pm (original)
+++ roller/cmssite/trunk/lib/view.pm Tue Jul 15 17:25:04 2014
@@ -1,18 +1,44 @@
 package view;
+use base 'ASF::View'; # see https://svn.apache.org/repos/infra/websites/cms/build/lib/ASF/View.pm
 
+=head1 INTERFACE
 
-# 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.
+Each function within view.pm which will be used for page generation must
+implement a standard interface.
+
+    sub my_view {
+        my %args = @_;
+        ...
+        return ($content, $extension, @optional);
+    }
+
+First, each function must accept labeled parameters.  The only parameter which
+will always be present is "path"; see the documentation in path.pm for the
+"@patterns" array with regards to invocation with additional parameters.
+
+Second, each function must return a list with at least two elements: the first
+element must be the page content, and the second must be a file extention.
+Returning additional elements in the list (as some of the functions below do)
+is optional.
+
+    return ($content, 'html', \%args);
+
+The constraints imposed by this interface may cause difficulties, for example
+when you want to generate both "foo.html" and "foo.pdf".  However, it is
+usually possible to work around such issues with symlinks and dependency
+management in path.pm.
+
+=cut
 
 use strict;
 use warnings;
-use Dotiac::DTL qw/Template *TEMPLATE_DIRS/;
-use Dotiac::DTL::Addon::markup;
-use ASF::Util qw/read_text_file/;
+use Carp;
+use Dotiac::DTL;
+use ASF::Util qw( read_text_file );
+use OpenEJBSiteDotiacFilter;
+use Data::Dumper;
 
-push @TEMPLATE_DIRS, "templates";
+BEGIN { push @Dotiac::DTL::TEMPLATE_DIRS, "templates"; }
 
 # This is most widely used view.  It takes a
 # 'template' argument and a 'path' argument.
@@ -20,39 +46,127 @@ push @TEMPLATE_DIRS, "templates";
 # like foo.page/bar.mdtext will be parsed and
 # passed to the template in the "bar" (hash)
 # variable.
+# Has the same behavior as the above for foo.page/bar.txt
+# files, parsing them into a bar variable for the template.
+# Otherwise presumes the template is the path.
 
-sub single_narrative {
+
+# A "basic" view, which takes 'template' and 'path' parameters.
+# borrowed from openejb
+
+sub basic {
     my %args = @_;
-    my $file = "content$args{path}";
-    my $template = $args{template};
-    $args{path} =~ s/\.mdtext$/\.html/;
-    $args{breadcrumbs} = breadcrumbs($args{path});
+    my $filepath = "content$args{path}";
 
-    read_text_file $file, \%args;
+    print "basic $filepath";
 
-    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};
+    read_text_file($filepath, \%args);
+
+    if(defined $args{indexpage}) {
+      $args{path} = "$args{path}$args{indexpage}";
+    }
+    
+    $args{path} =~ s/\.md(text)?$/\.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;
     }
 
-    return Template($template)->render(\%args), html => \%args;
+    print " - rendering using Dotiac::DTL";
+
+    my $rendered = Dotiac::DTL->new($template_path)->render(\%args);
+
+    print " - complete\n";
+
+    return ($rendered, 'html', \%args);
 }
 
-# Has the same behavior as the above for foo.page/bar.txt
-# files, parsing them into a bar variable for the template.
-# Otherwise presumes the template is the path.
 
-sub news_page {
+sub _breadcrumbs {
+    my $path        = shift;
+    my $base        = shift;
+
+    my $index = "$base/documentation.html";
+    $index =~ s,/+,/,g;
+
+    my @breadcrumbs = (
+        qq|<a href="$index">Docs</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}about.html">\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;
+}
+
+# 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 $template = "content$args{path}";
+    my $file = "content$args{path}";
+    my $template = $args{template};
+    $args{path} =~ s/\.mdtext$/\.html/;
     $args{breadcrumbs} = breadcrumbs($args{path});
 
-    my $page_path = $template;
+    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") {
@@ -64,60 +178,6 @@ sub news_page {
 
     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!/[^/]+$!!;
-    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 .= "$_/";
-        $_ ||= "Roller";
-        push @rv, qq(<a href="$relpath">\u$_</a>);
-    }
-    return join "&nbsp;&raquo&nbsp;", @rv;
-}
-
 1;
 
 =head1 LICENSE
@@ -138,3 +198,5 @@ sub breadcrumbs {
            KIND, either express or implied.  See the License for the
            specific language governing permissions and limitations
            under the License.
+
+



Mime
View raw message