Now all modules are in core modules folder

This commit is contained in:
Manuel Cillero 2017-08-08 12:14:45 +02:00
parent 5ba1cdfa0b
commit 05b6a91b0c
1907 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,263 @@
Class CSSCompression
====================
Below is a description of all public access points to the compressor.
const *bool* VERSION
--------------------
Release version
const *bool* DATE
-----------------
Release Date
const *bool* DEV
----------------
Signifies development mode. When true, back door access to all subclasses is enabled. Should always be false in production.
const *bool* TOKEN
------------------
Special marker that gets injected and removed into the stylesheet during compression. Change this if it exists in your sheet.
public static *array* defaults
------------------------------
Default settings for every instance.
const *int* READ_MAX, const *int* READ_MED, const *int* READ_MIN, const *int* READ_NONE
---------------------------------------------------------------------------------------
Readability constants. Tells what format to return the css back after compression.
Getters
=======
This is the list of readable vars on any given instance
- *string* **css**: Contains the compressed result of the last compression ran.
- *string* **mode**: Contains the current mode of the instance
- *array* **options**: Contains the complete array of currently defined options
- *array* **stats**: Contains the result stats of the last compression ran.
- *string* **(option-name)**: Contains the value of that option **name**.
Usage:
// Print out compressed css
echo $CSSC->css;
// Print out the current mode
echo $CSSC->mode;
// Print out list of options
print_r( $CSSC->options );
// Print out result stats
print_r( $CSSC->stats );
// Print out a single options value
echo $CSSC->readability;
Setters
=======
Currently, you can only directly set options
- *string* **options**, *array* **value**: Merge an array of options with the current defaults
- *string* **name**, *mixed* **value**: Set the option **name** with the **value**.
Usage:
// Merge a custom set of options into the defined set
// Remember that it doesn't set, just merges
$CSSC->options = array( 'readability' => CSSCompression::READ_MAX, 'organize' => true );
// Set a single options value
$CSSC->readability = CSSCompression::READ_MAX;
$CSSC->organize = true;
public function __construct( [ *mixed* $css = NULL, *mixed* $options = NULL ] )
-------------------------------------------------------------------------------
Builds the subclasses first, then does one of the following
- Passing a single string argument that is the name of a mode, sets the mode for this instance.
- Passing a single array of options argument will merge those with the defaults for this instance.
- Passing a single long string argument, that is not the name of a mode, will run compression with the defaults set.
- Passing a long string argument, and a mode name argument, sets the mode's options, and then runs compression on the css string.
- Passing a long string argument, and an array of options argument, merges those with default options, and runs compression on the css string.
Usage:
// Create an instance in 'sane' mode
$CSSC = new CSSCompression( 'sane' );
// Create an instance with a custom set of options
$CSSC = new CSSCompression( array( 'readability' => CSSCompression::READ_MAX ) );
// Creates a new instance, then runs compression on the css passed
$CSSC = new CSSCompression( $css );
echo $CSSC->css;
// Creates a new instance in 'sane' mode, then runs compression on the css passed
$CSSC = new CSSCompression( $css, 'sane' );
echo $CSSC->css;
// Creates a new instance with a custom set of options, then runs compression on the css passed
$CSSC = new CSSCompression( $css, array( 'readability' => CSSCompression::READ_MAX ) );
echo $CSSC->css;
*array* public function mode( *string* $mode = NULL )
-----------------------------------------------------
Sets the mode of the instance.
// Set this instance to 'sane' mode
$CSSC->mode( 'sane' );
*array* public static function modes( [ *mixed* $mode = NULL, *array* $config = NULL ] )
----------------------------------------------------------------------------------------
Mode configuration, any one of the following combination of arguments is allowed
- Passing no arguments returns the entire array of modes.
- Passing only a string mode argument returns that modes configuration.
- Passing a string mode argument, and an array config argument sets that config to the mode.
- Passing a single array argument merges a set of modes into the configured set
Usage:
// Returns the entire list of modes
$modes = CSSCompression::modes();
// Returns 'sane' mode configuration
$sane = CSSCompression::modes( 'sane' );
// Add 'rose' mode to the list of modes
CSSCompression::modes( 'rose', array( 'organize' => false, 'readability' => CSSCompression::READ_MAX ) );
// Add 'rose' and 'blue' mode configurations to set of modes
CSSCompression::modes(array(
'rose' => array( 'organize' => false, 'readability' => CSSCompression::READ_MAX ),
'blue' => array( 'rm-multi-define' => false, 'readability' => CSSCompression::READ_NONE )
));
**NOTE:** When an instance configures itself to a mode, it sets every option to true, and expects the mode configuration to tell it what is false.
*mixed* public function option( [ *mixed* $name = NULL, *mixed* $value = NULL ] )
---------------------------------------------------------------------------------
Custom option handling, any one of the following may happen
- Passing no arguments returns the entire array of options currently set.
- Passing only a string name argument returns the value for that option.
- Passing a single array argument merges those into the current options of the instance.
- Passing a string name argument, and a value argument sets the value to it's corresponding option name.
Usage:
// Get the entire options array for this instance
$options = $CSSC->option();
// Get the current readability value for this instance
$readability = $CSSC->option( 'readability' );
// Merge a set of options into the current instance
$CSSC->option( array( 'organize' => false, 'readability' => CSSCompression::READ_MAX ) );
// Set the readability of the current object to full
$CSSC->option( 'readability', CSSCompression::READ_MAX );
*string* public function compress( *string* $css = NULL, [ *mixed* $options = NULL ] )
--------------------------------------------------------------------------------------
Compresses the given string with the given options/mode. $options can be the name of a mode, or an array of options.
// Compress the css passed
$compressed = $CSSC->comrpess( $css );
// Compress the css in 'sane' mode
$compressed = $CSSC->comrpess( $css, 'sane' );
// Compress the css with a custom set of options
$compressed = $CSSC->comrpess( $css, array( 'readability' => CSSCompression::READ_MAX ) );
*string* public static function express( *string* $css = NULL, [ *mixed* $options = NULL ] )
--------------------------------------------------------------------------------------------
Use's it's own singleton instance to return compressed css sheets. $options can be the name of a mode, or an array of options.
// Compress the css passed
$compressed = CSSCompression::express( $css );
// Compress the css in 'sane' mode
$compressed = CSSCompression::express( $css, 'sane' );
// Compress the css with a custom set of options
$compressed = CSSCompression::express( $css, array( 'readability' => CSSCompression::READ_MAX ) );
*bool* public function reset()
------------------------------
Cleans out compression instance, all of it's subclasses, and resets options back to their defaults.
// Reset this instance to it's defaults
$CSSC->reset();
*bool* public function flush()
------------------------------
Cleans out class vars.
// Flush out compression variables
$CSSC->flush();
*object* public static function getInstance( [ *string* name = NULL ] )
-----------------------------------------------------------------------
Returns a singleton instance of the compressor
// Get a singleton instance
$CSSC = CSSCompression::getInstance();
// Get the stored 'rose' singleton instance
$CSSC = CSSCompression::getInstance( 'rose' );
*array* public static function getJSON( *string* $file )
--------------------------------------------------------
Pulls the contents of the $file, does some quick comment stripping, then returns a json decoded hash. Mainly for internal use.
$json = CSSCompression::getJSON( "/path/to/my/file.json" );

View file

@ -0,0 +1,63 @@
Contribute
==========
This project is always in dire need of help in any form, I only have 2 rules:
- All sandboxed tests must pass.
For nix users: From the root directory, run 'make test'
For windows users: Run 'php unit/start.inc'
- Tab character indentations
I don't care if you like 2,3,4,8,16 spaced indentation, just make sure it's a tab character and not spaces.
make test
---------
This command will run all sandboxed tests to check that most functions run the way they should.
make test-focus
---------------
This command runs a focused test on a single function for development. Open up unit/focus.inc for configuration.
make test-file
--------------
This command runs a focused test on a single file. Make sure the original resides in unit/sheets/original/ and the expected
output resides in unit/sheets/expected/. Open up unit/file.inc for configuration
make test-all
-------------
This command runs all sandboxed tests, as well as double compressions on any stylesheets in benchmark src. Doesn't always pass,
but is a helpful check to see that most compression is done the first time around.
make test-regression [ VERSION=temp ]
--------------------------------
The regression command takes an optional assignment which will do testing against the given version. Defaults is to the last run test.
make benchmark
--------------
This command runs the benchmark process. This will create a new temp directory for regression testing and comparison.
make clean
----------
This command removes all generated files used for comparisons and benchmarks.
unit/sandbox/
-------------
The sandbox directory contains json files for focused tests used in unit testing.

View file

@ -0,0 +1,234 @@
Options
=======
Here's a few different ways to set options.
// Set an array of options
$options = array( 'color-long2hex' => false, 'readability' => CSSCompression::READ_MAX );
// Pass directly into express compression
$compressed = CSSCompression::express( $css, $options );
// Create an instance based on the predefined set of options
$CSSC = new CSSCompression( $options );
// Set a batch of options on an instance
$CSSC->option( $options );
// Set a single option on an instance
$CSSC->option( 'readability', CSSCompression::READ_MAX );
// Or, if you just want to read an option
$readability = $CSSC->option( 'readability' );
// Also, you can look at the current options
$options = $CSSC->option();
color-long2hex
--------------
Converts long color names to short hex names
- *aliceblue -> #f0f8ff*
color-rgb2hex
-------------
Converts rgb colors to hex
- *rgb(159,80,98) -> #9F5062, rgb(100%) -> #FFFFFF*
color-hex2shortcolor
--------------------
Converts long hex codes to short color names, Only works on latest browsers, careful when using.
- *#f5f5dc -> beige*
color-hex2shorthex
------------------
Converts long hex codes to short hex codes
- *#44ff11 -> #4f1*
color-hex2safe
--------------------
Converts long hex codes to safe CSS Level 1 color names.
- *#f00 -> red*
fontweight2num
--------------
Converts font-weight names to numbers
- *bold -> 700*
format-units
------------
Removes zero decimals and 0 units
- *15.0px -> 15px || 0px -> 0*
lowercase-selectors
-------------------
Lowercases html tags from list
- *BODY -> body*
attr2selector
-------------
Converts class and id attributes to their shorthand counterparts
- *div[id=blah][class=blah] -> div#blah.blah*
strict-id
---------
Promotes nested id's to the front of the selector
- *body > div#elem p -> #elem p*
pseudo-space
------------
Add space after :first-letter and :first-line pseudo selectors, for ie6
- *a:first-line{ -> a:first-line {*
directional-compress
--------------------
Compresses single defined multi-directional properties
- *margin: 15px 25px 15px 25px -> margin:15px 25px*
organize
--------
Combines multiply defined selectors and details
- *p{color:blue;} p{font-size:12pt} -> p{color:blue;font-size:12pt;}*
- *p{color:blue;} a{color:blue;} -> p,a{color:blue;}*
csw-combine
-----------
Combines color/style/width properties
- *border-style:dashed;border-color:black;border-width:4px; -> border:4px dashed black*
auralcp-combine
---------------
Combines cue/pause properties
- *cue-before: url(before.au); cue-after: url(after.au) -> cue:url(before.au) url(after.au)*
mp-combine
----------
Combines margin/padding directionals
- *margin-top:10px;margin-right:5px;margin-bottom:4px;margin-left:1px; -> margin:10px 5px 4px 1px;*
border-combine
--------------
Combines border directionals
- *border-top|right|bottom|left:1px solid black -> border:1px solid black*
font-combine
------------
Combines font properties
- *font-size:12pt; font-family: arial; -> font:12pt arial*
background-combine
------------------
Combines background properties
- *background-color: black; background-image: url(bgimg.jpeg); -> background:black url(bgimg.jpeg)*
list-combine
------------
Combines list-style properties
- *list-style-type: round; list-style-position: outside -> list-style:round outside*
border-radius-combine
---------------------
Combines border-radius properties
{
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
-> { border-radius: 10px; }
unnecessary-semicolons
----------------------
Removes the last semicolon of a rule set
- *{margin: 2px; color: blue;} -> {margin: 2px; color: blue}*
rm-multi-define
---------------
Removes multiple declarations within the same rule set
- *{color:black;font-size:12pt;color:red;} -> {color:red;font-size:12pt;}*
add-unknown
-----------
Adds unknown artifacts to a comment block at the top of output.
readability
-----------
Readability of Compressed Output.
CSSCompression::READ_MAX; // Maximum readability
CSSCompression::READ_MED; // Medium readability
CSSCompression::READ_MIN; // Minimum readability
CSSCompression::READ_NONE; // No readability