svn: /phd/trunk/phpdotnet/phd/ BuildOptionsParser.php Config.php Package/Generic/BigXHTML.php Package/Generic/ChunkedXHTML.php
Package/Generic/XHTML.php

From: Date: Thu, 17 Sep 2009 14:00:21 +0000
Subject: svn: /phd/trunk/phpdotnet/phd/ BuildOptionsParser.php Config.php Package/Generic/BigXHTML.php Package/Generic/ChunkedXHTML.php
Package/Generic/XHTML.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4938@lists.php.net to get a copy of this message
moacir Thu, 17 Sep 2009 14:00:21 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=288407 Log: Adding the --css option - Fixing bugs #47406 and #48264 - For chunked formats the css files will be copied in outputdir/format/styles/ and linked with <link> - For non chunked formats the css will be written with <style> Bugs: http://bugs.php.net/47406 (Open) Add support for external css http://bugs.php.net/48264 (Verified) No style for HTML version of php docs Changed paths: U phd/trunk/phpdotnet/phd/BuildOptionsParser.php U phd/trunk/phpdotnet/phd/Config.php U phd/trunk/phpdotnet/phd/Package/Generic/BigXHTML.php U phd/trunk/phpdotnet/phd/Package/Generic/ChunkedXHTML.php U phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php Modified: phd/trunk/phpdotnet/phd/BuildOptionsParser.php =================================================================== --- phd/trunk/phpdotnet/phd/BuildOptionsParser.php 2009-09-17 13:18:06 UTC (rev 288406) +++ phd/trunk/phpdotnet/phd/BuildOptionsParser.php 2009-09-17 14:00:21 UTC (rev 288407) @@ -24,6 +24,7 @@ "version" => "V", // Print out version information "help" => "h", // Print out help "package:" => "P:", // The package of formats + "css:" => "C:", // External CSS ); } @@ -212,6 +213,9 @@ } public function option_c($k, $v) { + if ($k == "C") { + return $this->option_css($k, $v); + } $this->option_color($k, $v); } public function option_color($k, $v) @@ -234,6 +238,15 @@ trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); } } + public function option_css($k, $v) { + $styles = array(); + foreach((array)$v as $key => $val) { + if (!in_array($val, $styles)) { + $styles[] = $val; + } + } + Config::set_css($styles); + } /** * Prints out the current PhD and PHP version. Modified: phd/trunk/phpdotnet/phd/Config.php =================================================================== --- phd/trunk/phpdotnet/phd/Config.php 2009-09-17 13:18:06 UTC (rev 288406) +++ phd/trunk/phpdotnet/phd/Config.php 2009-09-17 14:00:21 UTC (rev 288407) @@ -36,6 +36,7 @@ "package" => array( "Generic", ), + 'css' => array(), ); public static function init(array $a) { Modified: phd/trunk/phpdotnet/phd/Package/Generic/BigXHTML.php =================================================================== --- phd/trunk/phpdotnet/phd/Package/Generic/BigXHTML.php 2009-09-17 13:18:06 UTC (rev 288406) +++ phd/trunk/phpdotnet/phd/Package/Generic/BigXHTML.php 2009-09-17 14:00:21 UTC (rev 288407) @@ -36,6 +36,10 @@ public function header() { $root = Format::getRootIndex(); + $style = ''; + foreach ((array)$this->stylesheets as $css) { + $style .= "<style type=\"text/css\">\n" . $css . "\n</style>\n"; + } return <<<HEADER <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @@ -43,6 +47,7 @@ <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>{$root["ldesc"]}</title> +{$style} </head> <body> HEADER; @@ -74,9 +79,12 @@ if ($val) { if (!is_resource($this->getFileStream())) { $filename = Config::output_dir() . strtolower($this->getFormatName()) . '.' . $this->getExt(); + $this->postConstruct(); + if (Config::css()) { + $this->fetchStylesheet(); + } $this->setFileStream(fopen($filename, "w+")); fwrite($this->getFileStream(), $this->header()); - $this->postConstruct(); } } break; Modified: phd/trunk/phpdotnet/phd/Package/Generic/ChunkedXHTML.php =================================================================== --- phd/trunk/phpdotnet/phd/Package/Generic/ChunkedXHTML.php 2009-09-17 13:18:06 UTC (rev 288406) +++ phd/trunk/phpdotnet/phd/Package/Generic/ChunkedXHTML.php 2009-09-17 14:00:21 UTC (rev 288407) @@ -78,6 +78,9 @@ v("Can't create output directory", E_USER_ERROR); } } + if (Config::css()) { + $this->fetchStylesheet(); + } break; case Render::VERBOSE: v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); @@ -90,6 +93,11 @@ $lang = Config::language(); $root = Format::getRootIndex(); + $cssLinks = ''; + foreach ((array)$this->stylesheets as $css) { + $cssLinks .= " <link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"styles/".$css."\" />\n"; + } + $prev = $next = $parent = array("href" => null, "desc" => null); if ($parentId = $this->getParent($id)) { @@ -112,6 +120,7 @@ <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>'.(($title != $root["ldesc"]) ? $root["ldesc"].': ' : "").$title.'</title> +'.$cssLinks.' </head> <body> <table width="100%"> Modified: phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php =================================================================== --- phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php 2009-09-17 13:18:06 UTC (rev 288406) +++ phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php 2009-09-17 14:00:21 UTC (rev 288407) @@ -432,6 +432,8 @@ 'dbhtml' => 'PI_DBHTMLHandler', ); + protected $stylesheets = array(); + public function __construct() { parent::__construct(); $this->registerPIHandlers($this->pihandlers); @@ -514,6 +516,41 @@ return $retval; } + protected function fetchStylesheet() { + if (!$this->isChunked()) { + foreach ((array)Config::css() as $css) { + if ($style = file_get_contents($css)) { + $this->stylesheets[] = $style; + } else { + v(sprintf("Stylesheet %s not fetched.", $css), E_USER_WARNING); + } + } + return; + } + $stylesDir = $this->getOutputDir(); + if (!$stylesDir) { + $stylesDir = Config::output_dir(); + } + $stylesDir .= 'styles/'; + if (file_exists($stylesDir)) { + if (!is_dir($stylesDir)) { + v("The styles/ directory is a file?", E_USER_ERROR); + } + } else { + if (!mkdir($stylesDir)) { + v("Can't create the styles/ directory.", E_USER_ERROR); + } + } + foreach ((array)Config::css() as $css) { + $basename = basename($css); + $dest = md5(substr($css, 0, -strlen($basename))) . '-' . $basename; + if (@copy($css, $stylesDir . $dest)) { + $this->stylesheets[] = $dest; + } else { + v(sprintf('Impossible to copy the %s file.', $css), E_USER_WARNING); + } + } + } /* Functions format_* */ public function format_suppressed_tags($open, $name, $attrs, $props) {

« previous php.doc.cvs (#4938) next »