mandatory = true; $componentOption->shorthelp = "The name of the component."; $params->registerOption( $componentOption ); $targetOption = new ezcConsoleOption( 't', 'target', ezcConsoleInput::TYPE_STRING ); $targetOption->mandatory = true; $targetOption->shorthelp = "The directory to where the generated documentation should be written."; $params->registerOption( $targetOption ); $versionOption = new ezcConsoleOption( 'v', 'version', ezcConsoleInput::TYPE_STRING ); $versionOption->mandatory = true; $versionOption->shorthelp = "The version of the component that should be read. E.g. trunk, 1.0rc1, etc."; $params->registerOption( $versionOption ); $versionOption = new ezcConsoleOption( 'r', 'release', ezcConsoleInput::TYPE_STRING ); $versionOption->mandatory = true; $versionOption->shorthelp = "The release of the components we're building this tutorial for."; $params->registerOption( $versionOption ); // Process console parameters try { $params->process(); } catch ( ezcConsoleOptionException $e ) { print( $e->getMessage(). "\n" ); print( "\n" ); echo $params->getSynopsis() . "\n"; foreach ( $params->getOptions() as $option ) { echo "-{$option->short}, --{$option->long}\t {$option->shorthelp}\n"; } echo "\n"; exit(); } $component = $params->getOption( 'component' )->value; $version = $params->getOption( 'version' )->value; $release = $params->getOption( 'release' )->value; if ( $version == 'trunk' ) { $componentDir = "trunk/$component"; } else { $componentDir = "releases/$component/$version"; } $output = getRstOutput( $componentDir ); $output = removeHeaderFooter( $output ); $output = addNewHeader( $component, $output, $release ); $output = addExampleLineNumbers( $output ); $output = addLinks( $component, $output, $version ); $output = addNewFooter( $output ); $targetDir = $params->getOption( 'target' )->value; file_put_contents( "$targetDir/introduction_$component.html", $output ); // Copying images and files `mkdir -p $targetDir/img`; `cp $componentDir/docs/img/*.* $targetDir/img/ 2>/dev/null`; `mkdir -p $targetDir/files`; `cp $componentDir/docs/files/*.* $targetDir/files/ 2>/dev/null`; function getRstOutput( $componentDir ) { $fileName = "$componentDir/docs/tutorial.txt"; $output = shell_exec( "rst2html $fileName" ); return $output; } function removeHeaderFooter( $output ) { ini_set( 'pcre.backtrack_limit', 10000000 ); $output = preg_replace( '@.*?@ms', '', $output ); $output = preg_replace( '@

eZ components - [A-Za-z]+

@i', '', $output ); $output = preg_replace( '@<\/body>.*@ms', '', $output ); return $output; } function addNewFooter( $output ) { return $output . "\n". "
Last updated: ". date( 'D, d M Y' ) . "
"; } function addNewHeader( $component, $output, $version ) { $outputHeader = <<$component [ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]
FOO; return $outputHeader . $output; } function addLinks( $component, $output, $version ) { // $base = "http://ez.no/doc/components/view/$version/(file)/$component/"; $base = "$component/"; $output = preg_replace_callback( '@(ezc[A-Z][a-zA-Z0-9]+)::([A-Za-z0-9_]+)@', 'callBackFormatClassStaticMethodLink', $output ); $output = preg_replace_callback( '@(?)(ezc[A-Z][a-zA-Z0-9]+)@', 'callBackFormatClassLink', $output ); $output = preg_replace_callback( '@(ezc[A-Z][a-zA-Z0-9]+)::\$([A-Za-z0-9]+)@', 'callBackFormatClassVarLink', $output ); $output = preg_replace_callback( "@(ezc[A-Z][a-zA-Z0-9]+)::([A-Za-z0-9_]+)(?=\()@", 'callBackFormatClassStaticMethodLink', $output ); $output = preg_replace_callback( "@(ezc[A-Z][a-zA-Z0-9]+)-(>|\>)([A-Za-z0-9_]+)(?=\()@", 'callBackFormatClassDynamicMethodLink', $output ); $output = preg_replace_callback( "@(ezc[A-Z][a-zA-Z0-9]+)::([A-Z_]+)\\b@", 'callBackFormatClassConstantLink', $output ); $output = preg_replace_callback( "@(?])(ezc[A-Z][a-zA-Z0-9]+)@", 'callBackFormatClassLink', $output ); $output = preg_replace_callback( "@(?<=)(ezc[A-Z][a-zA-Z0-9]+)@", 'callBackFormatClassLink', $output ); $output = preg_replace_callback( "@(?<=
)(ezc[A-Z][a-zA-Z0-9]+)@", 'callBackFormatClassLink', $output ); $output = preg_replace_callback( "@()(ezc[A-Z][a-zA-Z0-9]+)(\()@", 'callbackFormatClassDynamicMethodCodeLink', $output ); $output = preg_replace_callback( "@(ezc[A-Z][a-zA-Z]+)(::)([A-Z_]+)@", 'callBackFormatClassConstantCodeLink', $output ); $output = preg_replace_callback( "@()(ezc[A-Z][a-zA-Z0-9]+)()@", 'callBackFormatClassCodeLink', $output ); $output = preg_replace_callback( "@()(ezc[A-Z][a-zA-Z0-9]+)(::)([A-Za-z]+)()@", 'callBackFormatClassStaticMethodCodeLink', $output ); $output = preg_replace_callback( "@()(ezc[A-Z][a-zA-Z0-9]+Exception)(\ \\$)@", 'callBackFormatExceptionClassCodeLink', $output ); return $output; } function callBackFormatExceptionClassCodeLink( $args ) { $component = ezctutBase::getClassComponent( $args[2] ); return "{$args[1]}{$args[2]}{$args[3]}"; } function callBackFormatClassStaticMethodCodeLink( $args) { $component = ezctutBase::getClassComponent( $args[2] ); return "{$args[1]}{$args[2]}::{$args[4]}{$args[5]}"; } function callBackFormatClassCodeLink( $args ) { $component = ezctutBase::getClassComponent( $args[2] ); return "{$args[1]}{$args[2]}{$args[3]}"; } function callBackFormatClassConstantCodeLink( $args ) { $component = ezctutBase::getClassComponent( $args[1] ); return "{$args[1]}::{$args[3]}"; } function callbackFormatClassDynamicMethodCodeLink( $args ) { $component = ezctutBase::getClassComponent( $args[2] ); return "{$args[1]}{$args[2]}{$args[3]}"; } function callBackFormatClassVarLink( $args ) { $component = ezctutBase::getClassComponent( $args[1] ); return "{$args[0]}"; } function callBackFormatClassStaticMethodLink( $args ) { $component = ezctutBase::getClassComponent( $args[1] ); return "{$args[0]}"; } function callBackFormatClassDynamicMethodLink( $args ) { $component = ezctutBase::getClassComponent( $args[1] ); return "{$args[0]}"; } function callBackFormatClassConstantLink( $args ) { $component = ezctutBase::getClassComponent( $args[1] ); return "{$args[0]}"; } function callBackFormatClassLink( $args ) { $component = ezctutBase::getClassComponent( $args[1] ); return "{$args[0]}"; } function addExampleLineNumbers( $output ) { return preg_replace_callback( '@
(.+?)<\/pre>@ms', 'callbackAddLineNumbers', $output );
}

$lineNr = 0;

function callbackAddLineNr( $args )
{
    global $lineNr;

    $nrString = str_replace( ' ', ' ', sprintf( '%3d', $lineNr ) );
    if ( $lineNr == 0 )
    {
        $val = '';
    }
    else
    {
        $val = $nrString . ". {$args[1]}\n";
    }
    $lineNr++;
    return $val;
}

function callbackAddLineNumbers( $args )
{
    global $lineNr;

    $lineNr = 0;
    
    if ( strstr( $args[1], '<?php' ) !== false )
    {
        file_put_contents( "/tmp/foo2.php", trim( html_entity_decode( $args[1] ) ) );
        `pygmentize -o /tmp/foo3.html /tmp/foo2.php`;
        $contents = file( "/tmp/foo3.html" );
        // strip out BS at start and end
        $contents[0] = str_replace( '
', '', $contents[0] );
        unset( $contents[count( $contents ) - 1] );
        $listing = <<
 
ENDT;
        foreach ( $contents as $line )
        {
            $listing .= "
  • {$line}
  • "; } $listing .= "\n"; return $listing; } else { return $args[0]; } }