incubator-zeta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [zeta-commits] svn commit: r1035167 - in /incubator/zetacomponents/website/var/scripts: ./ highlight_source.php htdocs_ignore.grep
Date Mon, 15 Nov 2010 07:47:21 GMT
Author: toby
Date: Mon Nov 15 07:47:21 2010
New Revision: 1035167

URL: http://svn.apache.org/viewvc?rev=1035167&view=rev
Log:
- Added: Basic script to highlight source and add line numbers.
- Added: Missed grep for reverting empty changes to docs.
# Sorry for that.

Added:
    incubator/zetacomponents/website/var/scripts/
    incubator/zetacomponents/website/var/scripts/highlight_source.php
    incubator/zetacomponents/website/var/scripts/htdocs_ignore.grep

Added: incubator/zetacomponents/website/var/scripts/highlight_source.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/website/var/scripts/highlight_source.php?rev=1035167&view=auto
==============================================================================
--- incubator/zetacomponents/website/var/scripts/highlight_source.php (added)
+++ incubator/zetacomponents/website/var/scripts/highlight_source.php Mon Nov 15 07:47:21
2010
@@ -0,0 +1,121 @@
+<?php
+
+if ( !isset( $argv[1] ) )
+{
+    die( "Missing doc version.\n" );
+}
+
+$version = $argv[1];
+
+$docBase = dirname( __FILE__ ) . "/../../htdocs/documentation/";
+$docDir  = "{$docBase}/{$version}";
+
+if ( !file_exists( $docDir ) || !is_dir( $docDir ) )
+{
+    die( "Doc dir '{$docDir}' does not exist.\n" );
+}
+
+$docUri = "/zetacomponents/documentation/{$version}";
+
+ini_set( 'highlight.string', '#335533' );
+ini_set( 'highlight.keyword', '#0000FF' );
+ini_set( 'highlight.default', '#000000' );
+ini_set( 'highlight.comment', '#007700' );
+
+$files = array_merge(
+    glob( "{$docDir}/*.html" ),
+    array_filter(
+        glob( "{$docDir}/*/*.html" ),
+        function ( $file )
+        {
+            return strpos( $file, 'phpdoc' ) === false;
+        }
+    )
+);
+
+foreach ( $files as $file )
+{
+    if ( preg_match( '(' . preg_quote( $docDir ) . '/([^\./]+))', $file, $matches ) <
1 )
+    {
+        die( "Could not parse file name '{$file}'." );
+    }
+    $component = $matches[1];
+
+    $content = file_get_contents( $file );
+    $content = addExampleLineNumbers( $content );
+    $content = addLinks( $docUri, $component, $content );
+
+    file_put_contents( $file, $content );
+}
+
+/*
+$content = file_get_contents( $file );
+*/
+
+function addLinks( $docUri, $component, $output )
+{
+    $base = "$docUri/$component/phpdoc/";
+
+    $output = preg_replace( '@(ezc[A-Z][a-zA-Z0-9]+)::\$([A-Za-z0-9]+)@', "<a href='{$base}\\1.html#\$\\2'>\\0</a>",
$output );
+    $output = preg_replace( "@(ezc[A-Z][a-zA-Z0-9]+)::([A-Za-z0-9_]+)(?=\()@", "<a href='{$base}\\1.html#\\2'>\\0</a>",
$output );
+    $output = preg_replace( "@(ezc[A-Z][a-zA-Z0-9]+)-(>|\&gt;)([A-Za-z0-9_]+)(?=\()@",
"<a href='{$base}\\1.html#\\3'>\\0</a>", $output );
+    $output = preg_replace( "@(ezc[A-Z][a-zA-Z0-9]+)::([A-Z_]+)\\b@", "<a href='{$base}\\1.html#const\\2'>\\0</a>",
$output );
+    $output = preg_replace( "@(?<![/>])(ezc[A-Z][a-zA-Z0-9]+)@", "<a href='{$base}\\1.html'>\\0</a>",
$output );
+    $output = preg_replace( "@(<span style=\"color: #[0-9A-F]+\">)(ezc[A-Z][a-zA-Z0-9]+)(</span><span
style=\"color: #[0-9A-F]+\">\()@", "\\1<a href='{$base}\\2.html'>\\2</a>\\3",
$output );
+    $output = preg_replace( "@(ezc[A-Z][a-zA-Z]+)(</span><span style=\"color: #[0-9A-F]+\">::</span><span
style=\"color: #[0-9A-F]+\">)([A-Z_]+)@", "<a href='{$base}\\1.html#const\\3'>\\1::\\3</a>",
$output );
+    $output = preg_replace( "@(<span style=\"color: #[0-9A-F]+\">)(ezc[A-Z][a-zA-Z0-9]+)(</li>)@",
"\\1<a href='{$base}\\2.html'>\\2</a>\\3", $output );
+    $output = preg_replace( "@(<span style=\"color: #[0-9A-F]+\">)(ezc[A-Z][a-zA-Z0-9]+)(</span><span
style=\"color: #[0-9A-Z]+\">::</span><span style=\"color: #[0-9A-F]+\">)([A-Za-z]+)(</span>)@",
"\\1<a href='{$base}\\2.html#\\4'>\\2::\\4</a>\\5", $output );
+    $output = preg_replace( "@(<span style=\"color: #[0-9A-F]+\">)(ezc[A-Z][a-zA-Z0-9]+Exception)(\&nbsp;\\$)@",
"\\1<a href='{$base}\\2.html'>\\2</a>\\3", $output );
+    return $output;
+}
+
+function addExampleLineNumbers( $output )
+{
+    return preg_replace_callback( '@<code[^>]*>(.+?)<\/code>@ms', 'callbackAddLineNumbers',
$output );
+}
+
+function callbackAddLineNr( $args )
+{
+    return sprintf(
+        "<li>%s</li>\n",
+        $args[1]
+    );
+}
+
+function callbackAddLineNumbers( $args )
+{
+    if ( strstr( $args[0], '&lt;?php' ) !== false )
+    {
+        $highlighted = highlight_string( html_entity_decode( $args[1] ), true );
+
+        // Replace starting <code><span...> with <ol class="code">
+        $highlighted = preg_replace( '@^<code><span style="color: #000000">@Ds',
'<ol class="code">', $highlighted );
+
+        // Move all <br /> outside of highlighting <span />
+        do
+        {
+            $highlighted = preg_replace(
+                '@(<span style="color: #[0-9A-F]+">)([^<]*)((<br />)+)(.*?)(</span>)@ms',
+                '\1\2\6\3\1\5\6',
+                $highlighted,
+                -1,
+                $count
+            );
+        } while ( $count > 0 );
+
+        // Remove empty highlighting <span>
+        $highlighted = preg_replace( '@<span style="color: #[0-9A-F]+"></span>@',
'', $highlighted );
+
+        // Replace ending </span></code> with </ol>
+        $highlighted = preg_replace( '@</span>\\s*</code>$@Ds', "</ol>",
$highlighted );
+
+        // Replace manual line breaks by wrapping in <li>
+        $highlighted = preg_replace_callback( '@(.*?)<br />@', "callbackAddLineNr",
$highlighted );
+
+        return $highlighted;
+    } else {
+        return $args[0];
+    }
+}
+
+?>

Added: incubator/zetacomponents/website/var/scripts/htdocs_ignore.grep
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/website/var/scripts/htdocs_ignore.grep?rev=1035167&view=auto
==============================================================================
--- incubator/zetacomponents/website/var/scripts/htdocs_ignore.grep (added)
+++ incubator/zetacomponents/website/var/scripts/htdocs_ignore.grep Mon Nov 15 07:47:21 2010
@@ -0,0 +1,7 @@
+^@@.*@@$
+<meta
+<pubDate>
+<lastBuildDate>
+<author>
+^[+-][[:space:]]\+by[[:space:]]
+^[+-][[:space:]]\+on[[:space:]]



Mime
View raw message