Author: cbrisson Date: Tue Jun 26 15:21:38 2018 New Revision: 1834438 URL: http://svn.apache.org/viewvc?rev=1834438&view=rev Log: [site] Preprocessing filter to load source files in code blocks
Modified: velocity/site/cms/trunk/content/css/site.css velocity/site/cms/trunk/lib/path.pm velocity/site/cms/trunk/lib/view.pm Modified: velocity/site/cms/trunk/content/css/site.css URL: http://svn.apache.org/viewvc/velocity/site/cms/trunk/content/css/site.css?rev=1834438&r1=1834437&r2=1834438&view=diff ============================================================================== --- velocity/site/cms/trunk/content/css/site.css (original) +++ velocity/site/cms/trunk/content/css/site.css Tue Jun 26 15:21:38 2018 @@ -282,7 +282,6 @@ pre, code { color: darkgray; font-style: italic; - text-decoration: strike-though; } /* tables */ Modified: velocity/site/cms/trunk/lib/path.pm URL: http://svn.apache.org/viewvc/velocity/site/cms/trunk/lib/path.pm?rev=1834438&r1=1834437&r2=1834438&view=diff ============================================================================== --- velocity/site/cms/trunk/lib/path.pm (original) +++ velocity/site/cms/trunk/lib/path.pm Tue Jun 26 15:21:38 2018 @@ -6,11 +6,14 @@ package path; # invoked to generate the page, and a hashref of named parameters which will # be passed to the view subroutine. +# CB TODO - pre/post processing should be triggered by the {{tags}} present in the file + our @patterns = ( [qr"^/(?:index|news|who-we-are)\.mdtext$", standard => { template => "single_narrative.html", postprocessing => 1 }], [qr"^/(?:engine/.*/changes)\.mdtext$", standard => { template => "single_narrative.html", postprocessing => 1, extralogo => '/engine/devel/images/velocity-logo.png' }], [qr"^/engine/.*\.mdtext", standard => { template => "single_narrative.html", extralogo => '/engine/devel/images/velocity-logo.png' }], [qr"^/(?:tools/.*/changes)\.mdtext$", standard => { template => "single_narrative.html", postprocessing => 1, extralogo => '/tools/devel/images/velocitytools.png' }], + [qr"FeedTool\.mdtext$", standard => { template => "single_narrative.html", preprocessing => 1, extralogo => '/tools/devel/images/velocitytools.png' }], [qr"^/tools/.*\.mdtext", standard => { template => "single_narrative.html", extralogo => '/tools/devel/images/velocitytools.png' }], [qr"^/rss/news.rss", rss => {} ], [qr"\.mdtext$", standard => { template => "single_narrative.html" }], Modified: velocity/site/cms/trunk/lib/view.pm URL: http://svn.apache.org/viewvc/velocity/site/cms/trunk/lib/view.pm?rev=1834438&r1=1834437&r2=1834438&view=diff ============================================================================== --- velocity/site/cms/trunk/lib/view.pm (original) +++ velocity/site/cms/trunk/lib/view.pm Tue Jun 26 15:21:38 2018 @@ -46,6 +46,40 @@ sub changes_report unlink $filename; return $summary . $changes; } +sub source_file +{ + my $url = "http://svn.apache.org/repos/asf/velocity/" . shift; + my $content = get $url; + + $content = "" if not $content; + + # hack to fix non-utf8 chars + utf8::encode($content); + + # extension gives lexer used for code highlighting + if ($url =~ /\.([a-z]+)$/i) + { + my $accepted = "java properties xml vm vtl vhtml"; + my $ext = lc $1; + if (index($accepted, $ext) != -1) + { + $ext =~ s/vm|vtl|vhtml/velocity/; + $content = ":::$ext\n$content"; + } + } + + # indent as block of code + $content =~ s/^/ /smg; + + # filename gives block title + if ($url =~ /(\w+\.[a-z]+)$/) + { + my $filename = $1; + $content = "\n\n### [$filename]($url)\n\n$content"; + } + + return $content; +} sub team() { my $xml = get "http://svn.apache.org/repos/asf/velocity/maven/trunk/pom/pom.xml"; @@ -63,6 +97,22 @@ sub team() return $pmc . $commiters . $emeriti; } +# pre-processing sub +sub preprocess { + my $text = shift; + my @params = shift; + while($text =~ /\{\{\w+(?:\([^(){}]*\))?\}\}/) + { + my ($before, $tag, $after) = ($`, $&, $'); + $tag =~ s/^\{\{|\}\}$//g; + $tag =~ m/(\w+)(?:\(([^()]*)\))?/; + my ($method, $args) = ($1, $2); + my $replacement = &{\&{$method}}($args) or debug "could not find tag sub $tag"; + $text = $before . $replacement . $after; + } + return $text; +} + # post-processing sub sub postprocess { my $text = shift; @@ -121,7 +171,7 @@ sub standard { ? Template($args{content})->render(\%args) : $args{content}); - + $args{content} = preprocess($args{content}) if $args{preprocessing}; my $processed = Template($template)->render(\%args); $processed = postprocess($processed, 0) if $args{postprocessing}; return $processed, html => \%args;