Login   Register  
PHP Classes
elePHPant
Icontem

File: example_CSSTree.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Weis  >  CSS Tree Class  >  example_CSSTree.php  >  Download  
File: example_CSSTree.php
Role: Example script
Content type: text/plain
Description: an example
Class: CSS Tree Class
Parse CSS files into a tree data structure
Author: By
Last change: Changed the name of the file to load to example.css, which is the one that comes with the class. There is an error thrown ('false' return vallue), if the selected element does not exist, so I added a check for this (always do checks...).
Date: 2006-01-17 06:19
Size: 1,730 bytes
 

Contents

Class file image Download
<?php

include("CSSTree.inc.php");

// dummy data 
$ddata=array("border"=>"1px solid black");
$ddata2=array("border"=>"2px solid silver");

// cssfile to read from 
$cssfile='example.css';

// init the tree (Tree.inc.php), available from:
// http://www.phpclasses.org/browse/package/2817.html

$null=null;
$tree = new CSSTree($null,"");

// parse the css-file and generate tree structure 
$tree=&$tree->parseFile($cssfile);
echo 
'<h2>File content</h2>';
echo 
'<pre>';
include(
$cssfile);
echo 
'</pre>';


// get a child by its name 
echo ' selecting an item by name... <br> ';
$item=&$tree->getChildByName('P');
// check if this is existent, if not, false is return value 
if ($item){
    echo 
' properties of selected item '.
                
$item->tagname.': '.
                
$item->renderCSSProperties();
    echo 
'<br>';
    
// add a property
    
$item->setProperty('color''black');
}

// lets have a look at the structure 
echo '<pre>';
$tree->echoStructure();
echo 
'</pre>';

// add some childs
$tmp=&$tree->addChild('custom1',$ddata);
$tmp=&$tmp->addChild('custom2',$ddata2);

echo 
'<h2>______echoStructure()_____</h2>';
echo 
'<pre>';
echo 
$tree->echoStructure();
echo 
'</pre>';

echo 
'<h2>_____renderCSSProperties______</h2>';
echo 
'<p>This is what you need for tags (&lt;div style=""&gt;)</p>';
echo 
'<pre>';
echo 
$tmp->renderCSSProperties();
echo 
'</pre>';

echo 
'<h2>_____renderCSS()______</h2>';
echo 
'<p>This is what you need in the header section &lt;style&gt;</p>';
echo 
'<pre>';
echo 
$tmp->renderCSS();
echo 
'</pre>';

echo 
'<h2>______renderCSSAll()_____</h2>';
echo 
'<p>This is what you need in a css-file</p>';
echo 
'<pre>';
echo 
$tree->renderCSSAll();
echo 
'</pre>';


?>