Permalink
Browse files

- PEARify

- Added support for template selection from command line
- Speed tweaks


git-svn-id: http://svn.php.net/repository/pear/packages/PHPDoc/trunk@89945 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent ade8326 commit 8d8cac319e9d0ae68b23b3e8ce21b2d3154985f4 Derick Rethans committed Jul 26, 2002
@@ -119,6 +119,7 @@ function appendToFile($filename, $content, $directory = "") {
* @return boolean
*/
function createFile($filename, $content, $directory = "") {
+
if ("" == $filename || "" == $content) {
$this->err[] = new PhpdocError("No filename or no content given.", __FILE__, __LINE__);
return false;
@@ -299,16 +299,17 @@ function getModulesAndClasses($phpcode) {
function getModuleDoc($phpcode) {
$module = array();
+
+ $rp = '@((//|#).*?$|(/\*\*.*?\*/)|/\*.*?\*/)@ms';
+ $rp2 = "@^.*?(<\?php|<\?|<%|<script\s+language\s*=\s*[\"']php[\"']\s*>)\s*/\*\*(.*?)\*/@s";
+
+/* if (preg_match($this->C_COMPLEX['module_doc'], $phpcode, $regs) ) {*/
+ if (preg_match($rp2, $code = preg_replace ($rp, '\3', $phpcode), $regs) ) {
- if (preg_match($this->C_COMPLEX['module_doc'], $phpcode, $regs) ) {
-
- $start = strlen($regs[0]);
- $end = strpos($phpcode, '*/', $start);
- $remaining = substr($phpcode, $end + 2);
- $doc_comment = substr($phpcode, $start, $end-$start);
+ $doc_comment = $regs[2];
// Do we have OO Code? If not, continue.
- if ( !preg_match($this->PHP_COMPLEX['class'], $remaining) && !preg_match($this->PHP_COMPLEX['class_extends'], $remaining) ) {
+ if ( !preg_match($this->PHP_COMPLEX['class'], $code) && !preg_match($this->PHP_COMPLEX['class_extends'], $code) ) {
// Is there a module tag?
if ( preg_match($this->C_COMPLEX['module_tags'], $doc_comment) ) {
@@ -335,10 +336,10 @@ function getModuleDoc($phpcode) {
// Try the remaining keywords. If one matches it's not a module doc
// assume that the module doc is missing. If none matches assume that
// it's a module doc which lacks the module tags.
- if (preg_match($this->PHP_COMPLEX['function'], $remaining) ||
- preg_match($this->PHP_COMPLEX['use'], $remaining) ||
- preg_match($this->PHP_COMPLEX['const'], $remaining) ||
- preg_match($this->PHP_COMPLEX['var'], $remaining)) {
+ if (preg_match($this->PHP_COMPLEX['function'], $doc_comment) ||
+ preg_match($this->PHP_COMPLEX['use'], $doc_comment) ||
+ preg_match($this->PHP_COMPLEX['const'], $doc_comment) ||
+ preg_match($this->PHP_COMPLEX['var'], $doc_comment)) {
$module = array(
'doc' => '',
@@ -371,6 +372,11 @@ function getModuleDoc($phpcode) {
$remaining = $phpcode;
}
+
+ if (!isset($remaining)) {
+ $rp3 = "@^.*?(<\?php|<\?|<%|<script\s+language\s*=\s*[\"']php[\"']\s*>).*?/\*\*(.*?)\*/@s";
+ $remaining = preg_replace($rp3, "", $phpcode);
+ }
return array($module, $remaining);
} // end func getModuleDoc
@@ -674,3 +680,5 @@ function getVariableTypeAndValue($code, $flag_args = true) {
} // end class PhpdocParserObject
?>
+
+
@@ -425,7 +425,7 @@ function buildComplexRegExps() {
//
// A module can start with comments not relating to the module documentation.
//
- $this->C_COMPLEX["module_doc"] = sprintf("@^%s%s%s%s*?%s/\*\*@is",
+ $this->C_COMPLEX["module_doc"] = sprintf("@^%s%s%s%s*?%s/\*\*@i",
$this->PHP_BASE["space_optional"],
$this->PHP_COMPLEX["php_open_all"],
$this->PHP_BASE["space_optional"],
View
@@ -1,24 +1,24 @@
-#!/usr/bin/php -Cq
+#!/usr/local/bin/php -Cq
<?php
+
/**
* Console script to generate PHPDoc API Docucumentation from the command line
*
-* TODO:
-* - Added template selection support (for templates at rendered/html). Now
-* uses the default
-*
* @author Tomas V.V.Cox <cox@idecnet.com>
+* @author Derick Rethans <d.rethans@jdimedia.nl>
* @version $Id$
*/
/*** CONFIGURATION ***/
-
// Directory with PHPDoc include files
-$phpdoc_include_dir = '/usr/lib/php/PHPDoc';
+$phpdoc_include_dir = '@php_dir@/PHPDoc';
// directory where your source files reside
-$source_files = '/usr/lib/php/';
+$source_files = '@php_dir@';
// save the generated docs here:
-$dest_apidoc_dir = '/usr/doc/pear';
+$dest_apidoc_dir = '@doc_dir@';
+// default template dir:
+$template_dir = '@data_dir@/PHPDoc';
+$template = 'default';
// force the deletion of the target apidocs directory
$dest_apidoc_delete = false;
@@ -31,7 +31,7 @@ require_once 'System.php';
error_reporting(E_ALL ^ E_NOTICE);
$argv = Console_Getopt::readPHPArgv();
-$options = Console_Getopt::getopt($argv, "h?fv:i:s:d:");
+$options = Console_Getopt::getopt($argv, "h?fv:t:e:s:d:");
if (PEAR::isError($options)) {
usage($options);
}
@@ -42,9 +42,6 @@ if (sizeof($options[0]) < 1) {
foreach ($options[0] as $opt) {
$param = $opt[1];
switch($opt[0]) {
- case 'i':
- $phpdoc_include_dir = $param;
- break;
case 's':
// directory where your source files reside
$source_files = $param;
@@ -53,6 +50,14 @@ foreach ($options[0] as $opt) {
// save the generated docs here:
$dest_apidoc_dir = $param;
break;
+ case 't':
+ // template directory:
+ $template_dir = $param;
+ break;
+ case 'e':
+ // template:
+ $template = $param;
+ break;
case 'f':
// force the deletion of the target apidocs directory
$dest_apidoc_delete = true;
@@ -77,6 +82,10 @@ ini_set('max_execution_time', 0);
$phpdoc_include_dir = realpath($phpdoc_include_dir);
define('PHPDOC_INCLUDE_DIR', $phpdoc_include_dir . DIRECTORY_SEPARATOR);
+// Directory with PHPDoc template files
+$template_dir = realpath($template_dir);
+define('PHPDOC_TEMPLATE_DIR', $template_dir . DIRECTORY_SEPARATOR);
+
// Important: set this to the Linebreak sign of your system!
$lnbreak = (OS_WINDOWS) ? "\r\n" : "\n"; // Mac not supported yet
define('PHPDOC_LINEBREAK', $lnbreak);
@@ -107,7 +116,7 @@ $doc->setSourceDirectory($source_files);
$doc->setTarget($dest_apidoc_dir);
// use these templates:
-$doc->setTemplateDirectory(PHPDOC_INCLUDE_DIR . '/renderer/html/default/');
+$doc->setTemplateDirectory($template_dir.'/renderer/html/'. $template);
// source files have one of these suffixes:
$doc->setSourceFileSuffix(array ('php', 'inc'));
@@ -118,14 +127,15 @@ $doc->parse();
// turn xml in to html using templates
$doc->render();
-// Copy the standar files
+// Copy the standard files
$files = array('empty.html', 'index.html', 'phpdoc.css', 'phpdoc.dtd');
$DS = DIRECTORY_SEPARATOR;
$files_prefix = implode($DS, array('renderer', 'html', 'default', 'static'));
foreach($files as $file) {
- copy($phpdoc_include_dir . $DS . $files_prefix . $DS . $file,
+ copy($template_dir . $DS . $files_prefix . $DS . $file,
"$dest_apidoc_dir/$file");
}
+
print "API Docs for $source_files done in $dest_apidoc_dir\n\n";
printf("%d seconds needed\n\n", time() - $start);
@@ -138,9 +148,10 @@ function usage($obj = null)
fputs($stderr,
"\nUsage: phpdoc [-h] [-f] [-i <dir>] [-s <dir>] [-d <dir>]\n".
"Options:\n".
- " -i <dir> directory with the PHPDoc include files\n".
" -s <dir> directory where your source files reside\n".
" -d <dir> destination dir (save the generated docs here)\n".
+ " -t <dir> template dir (path to the templates)\n".
+ " -e <name> template name (default='default')\n".
" -f force the deletion of the destination directory\n".
" -h, -? display help/usage (this message)\n".
"You could also set defaults values editing the header of this script\n".
@@ -149,4 +160,4 @@ function usage($obj = null)
exit;
}
-?>
+?>
View
@@ -195,4 +195,4 @@ function mainPageFooter()
</body>
</html><?PHP
}; // end func
-?>
+?>
@@ -54,7 +54,7 @@ function PhpdocHTMLRendererManager($target, $template, $application, $extension
* @access public
*/
function render($xmlfile, $type) {
-
+
switch (strtolower($type)) {
case "class":
@@ -97,4 +97,4 @@ function finish() {
} // end func finish
} // end class PhpdocHTMLRendererManager
-?>
+?>
@@ -5,17 +5,17 @@
// the default templates
// originally distributed with PHPDoc
-$PHPDOC_templates['default']['static_files_path'] = PHPDOC_INCLUDE_DIR . "renderer/html/default/static/";
-$PHPDOC_templates['default']['path'] = PHPDOC_INCLUDE_DIR . "renderer/html/default/";
+$PHPDOC_templates['default']['static_files_path'] = PHPDOC_TEMPLATE_DIR . "renderer/html/default/static/";
+$PHPDOC_templates['default']['path'] = PHPDOC_TEMPLATE_DIR . "renderer/html/default/";
$PHPDOC_templates['default']['display_name'] = "Default";
$PHPDOC_templates['default']['description'] = "The built in templates that come with PHPDoc. Created by Ulf Wendel";
// add your templates below this line
// timmyg's templates created for enhanced readability
// and css layout control
-$PHPDOC_templates['timmyg']['static_files_path'] = PHPDOC_INCLUDE_DIR . "renderer/html/timmyg/static/";
-$PHPDOC_templates['timmyg']['path'] = PHPDOC_INCLUDE_DIR . "renderer/html/timmyg/";
+$PHPDOC_templates['timmyg']['static_files_path'] = PHPDOC_TEMPLATE_DIR . "renderer/html/timmyg/static/";
+$PHPDOC_templates['timmyg']['path'] = PHPDOC_TEMPLATE_DIR . "renderer/html/timmyg/";
$PHPDOC_templates['timmyg']['display_name'] = "timmyg";
$PHPDOC_templates['timmyg']['description'] = "timmyg's templates created for enhanced readability, and css layout control." .
"Created by timmyg - May be Internet Explorer specific.";

0 comments on commit 8d8cac3

Please sign in to comment.