PHP Classes
elePHPant
Icontem

XCS Parser: Parse and compress XCSS files

Recommend this page to a friend!
  Info   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2008-01-21 (8 years ago) RSS 2.0 feedNot enough user ratingsTotal: 442 All time: 5,926 This week: 1,546Up
Version License PHP version Categories
xcsparser 0.1BSD License5PHP 5, Text processing
Description Author

This class can be used to parse and compress regular and extended Cascading Style Sheet (XCSS) definitions.

It can parse XCSS definitions and process them by evaluating macros and expressions, including external XCSS files, evaluating the rules of inherited styles, and processing comments that start with // .

The class can generate regular CSS definitions from the processed XCSS files. The processed CSS definitions may be compressed by removing white spaces, or formatted to be prettified and human readable.

Innovation Award
PHP Programming Innovation award nominee
February 2008
Number 5


Prize: One downloadable copy of PhpED Professional
CSS is used to define the details of presentation of Web site pages, hopefully keeping separate the definition of content from the presentation details. However, CSS does not always provide the level of control over presentation details that Web designers wish.

XCSS is an extension of the CSS standards that allows using more complex definitions that involve macros and expressions.

This class implements a PHP parser that can evaluate XCSS definitions and generate regular CSS, so any PHP site can benefit from XCSS possibilities without waiting for browsers that support.

Manuel Lemos
Picture of Ve Bailovity
Name: Ve Bailovity <contact>
Classes: 5 packages by
Country: Serbia and Montenegro Serbia and Montenegro
Innovation award
Innovation award
Nominee: 4x

Details
ABOUT
^^^^^

XcsParser is a XCS/CSS parsing and compression class for PHP5.
XCS stands for "eXtended Cascading Stylesheet".
"Extended", because XCS introduces several new concepts
and shorthands to CSS standard:
    1) Global variables (e.g. '!foregroundColor = #333;');
    2) Simple arythmetic operations on variables, and/or
       integer constants ("simple" means only 2 operands allowed).
       (e.g. '!width = !columnWidth * !numberOfColumns;')
       (e.g. '!width = !columnWidth * 4;')
    3) Complex expression handling, if allowed
       (e.g. '!date = expr(date("Y:m:d"));')
    4) Inline file inclusion, if allowed. This is different
       from normal CSS file inclusion, as it is performed
       in place (i.e. server-side), instead of client-side.
       (e.g. '@require(variable_defines.css);')
    5) Creating new CSS definitions by extending the
       existing rules
       (e.g. '.smalltext{font-size:0.8em} .smallredtext extends(.smalltext){color:red}')
    6) Line comments syntax with '// ... '
       (e.g. 'width: 120px; // this is a comment')

Of course, XCS syntax is optional, and the class can be used
for basic CSS prettyfying/compression alone. Depending on
compression flag set, the class will eiher:
    1) Leave your CSS as-is.
    2) Remove duplicated properties, alphabetize them
       and, optionally, alphabetize rules as well.
    3) Like 2), but will also strip any duplicated
       newlines.
    4) Like 3), but will also strip any CSS comments and
       zap all whitespaces to a single ' '.

The class requires PHP5, and will not work with PHP4.

All overridable `private` members are declared `protected`, so
one could easily extend the class to meet her particular needs
(e.g. to pre-populate options and flags in order to avoid
in-script option setting). By changing internal regexen, one
could also tweak XCS syntax to her liking. For more on this,
see included examples.

Included example scripts:
../examples/basic.php - Basic usage example.
../examples/static.php - Static loader usage example.
../examples/inherit.php - Class inheritance usage example.
../examples/noexpr.php - Forbidden `expr()` syntax example.
../examples/norequire.php - Forbidden `@require()` syntax example.
../examples/compression.php - Various compression/prettyfying examples.
../examples/syntax.php - XCS syntax changing advanced examples.


AUTHOR AND LICENSE IFORMATION
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

My name is Ve Bailovity, and you can reach me at
malatestapunk@gmail.com. If you find a bug or need help
of any kind, please don't hesitate to do so.

I don't really know much about legal stuff. Use this as
you see fit. For more info and an exception to this,
see 'LICENSE.txt' file included with the release.
  Files folder image Files  
File Role Description
Files folder imageetc (4 files)
Files folder imageexamples (7 files)
Files folder imagelib (1 file)
Accessible without login Plain text file LICENSE.txt Lic. Q&A on fair use
Accessible without login Plain text file README.txt Doc. Read this first

  Files folder image Files  /  etc  
File Role Description
  Accessible without login Plain text file advanced_syntax_1.css Data Advanced syntax (dollar) test style
  Accessible without login Plain text file advanced_syntax_2.css Data Advanced syntax (percent) test style
  Accessible without login Plain text file defines.css Data Basic test style - defines the values in style.css
  Accessible without login Plain text file style.css Data Main test style

  Files folder image Files  /  examples  
File Role Description
  Plain text file basic.php Example A basic test/demo file for XcsParser class
  Plain text file compression.php Example Compression test/demo file for XcsParser class
  Plain text file inherit.php Example Inheritance test/demo file for XcsParser class
  Plain text file noexpr.php Example Forbidden expressions statements test/demo file
  Plain text file norequire.php Example Forbidden external files access test/demo file
  Plain text file static.php Example Static loader test/demo file for XcsParser class.
  Plain text file syntax.php Example Advanced syntax changing test/demo file for XcsParser class

  Files folder image Files  /  lib  
File Role Description
  Plain text file XcsParser_class.php Class Main class file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:442
This week:0
All time:5,926
This week:1,546Up