Author: joes
Date: Wed Mar 19 12:10:53 2014
New Revision: 1579200

URL: http://svn.apache.org/r1579200
Log:
sketch snippet preprocessor support

Modified:
    thrift/cms-site/trunk/lib/path.pm

Modified: thrift/cms-site/trunk/lib/path.pm
URL: 
http://svn.apache.org/viewvc/thrift/cms-site/trunk/lib/path.pm?rev=1579200&r1=1579199&r2=1579200&view=diff
==============================================================================
--- thrift/cms-site/trunk/lib/path.pm (original)
+++ thrift/cms-site/trunk/lib/path.pm Wed Mar 19 12:10:53 2014
@@ -2,6 +2,7 @@ package path;
 use YAML::XS;
 use File::Find;
 use Cwd;
+use ASF::Util qw/read_text_file/;
 use strict;
 use warnings;
 
@@ -10,7 +11,8 @@ my $conf = Load(join "", <DATA>);
 our @patterns = (
     [qr!^/sitemap\.html$!, sitemap => { conf => $conf, headers => { title => 
"Sitemap" } }],
     [qr!/index\.html$!,    sitemap => { conf => $conf, headers => { title => 
"Index" } }],
-    [qr/\.md(?:text)?$/, single_narrative => {
+    [qr/\.md(?:text)?$/, thrift_preprocessor => {
+        view     => 'single_narrative',
         conf     => $conf,
         template => 'default.html',
         memo     => {}, # maintain a page generation cache
@@ -41,6 +43,30 @@ find({ wanted => sub {
            }
        }, no_chdir => 1 }, cwd() . "/content");
 
+sub thrift_preprocessor {
+    my %args = @_;
+    my $file = "content$args{path}";
+    return @{$args{memo}->{$file}} if exists $args{memo} and exists 
$args{memo}->{$file};
+    read_text_file $file, \%args;
+    delete $args{header};
+
+    my $key = "_a";
+    my $url_template = $args{conf}->{snippet_url};
+    $args{content} =~ s{\[XXXsnippet:([^\]]+)\]}
+                       {
+                           my $template = $1;
+                           my %a = map split /=/, split /:/, $template;
+                           $args{$key} = ASF::Value::Snippet->new(template => 
$url_template, %a);
+                           $key++ . ".list.$a{index}";
+                       }ge;
+
+    my @rv = view->can($args{view})->(%args);
+    $args{memo}->{$file} = \@rv if exists $args{memo};
+    return @rv;
+}
+
+
+
 1;
 
 
@@ -55,6 +81,7 @@ git_repo: "https://git-wip-us.apache.org
 release_url: "https://dist.apache.org/repos/dist/release/thrift";
 mirror_url: "http://www.apache.org/dyn/closer.cgi?path=";
 jira_url: "http://issues.apache.org/jira/browse/THRIFT";
+snippet_url: "http://git-wip-us.apache.org/XXX";
 
 current_release: "0.9.1"
 current_release_date: "2013-08-21"


Reply via email to