Skip to content

Commit

Permalink
partial merge of f98b3fd
Browse files Browse the repository at this point in the history
1 new functionnality :
- ability to pass a default media to print that will be used to encapsulate free selectors.
This functionnality can be used to concatenate severals css files with different media attributes
even if they contains @media inside
  • Loading branch information
Cerdic committed Nov 14, 2010
1 parent 653b982 commit 2cc3277
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion class.csstidy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Florian Schmitz (floele at gmail dot com) 2005-2007
* @author Brett Zamir (brettz9 at yahoo dot com) 2007
* @author Nikolay Matsievsky (speed at webo dot name) 2009-2010
* @author Cedric Morin (cedric at yterium dot com) 2010
*/
/**
* Defines ctype functions if required
Expand Down Expand Up @@ -67,7 +68,7 @@
* An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
* @version 1.3
* @version 1.3.1
*/
class csstidy {

Expand Down
29 changes: 20 additions & 9 deletions class.csstidy_print.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2007
* @author Brett Zamir (brettz9 at yahoo dot com) 2007
* @author Cedric Morin (cedric at yterium dot com) 2010
*/

/**
Expand All @@ -36,7 +37,7 @@
*
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
* @version 1.0
* @version 1.0.1
*/
class csstidy_print {

Expand Down Expand Up @@ -87,23 +88,25 @@ function _reset() {

/**
* Returns the CSS code as plain text
* @param string $default_media default @media to add to selectors without any @media
* @return string
* @access public
* @version 1.0
*/
function plain() {
$this->_print(true);
function plain($default_media='') {
$this->_print(true, $default_media);
return $this->output_css_plain;
}

/**
* Returns the formatted CSS code
* @param string $default_media default @media to add to selectors without any @media
* @return string
* @access public
* @version 1.0
*/
function formatted() {
$this->_print(false);
function formatted($default_media='') {
$this->_print(false, $default_media);
return $this->output_css;
}

Expand Down Expand Up @@ -155,17 +158,18 @@ function formatted_page($doctype='xhtml1.1', $externalcss=true, $title='', $lang
/**
* Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain
* @param bool $plain plain text or not
* @param string $default_media default @media to add to selectors without any @media
* @access private
* @version 2.0
*/
function _print($plain = false) {
function _print($plain = false, $default_media='') {
if ($this->output_css && $this->output_css_plain) {
return;
}

$output = '';
if (!$this->parser->get_cfg('preserve_css')) {
$this->_convert_raw_css();
$this->_convert_raw_css($default_media);
}

$template = & $this->template;
Expand Down Expand Up @@ -303,10 +307,11 @@ function _seeknocomment($key, $move) {

/**
* Converts $this->css array to a raw array ($this->tokens)
* @param string $default_media default @media to add to selectors without any @media
* @access private
* @version 1.0
*/
function _convert_raw_css() {
function _convert_raw_css($default_media='') {
$this->tokens = array();

foreach ($this->css as $medium => $val) {
Expand All @@ -315,7 +320,10 @@ function _convert_raw_css() {
if (intval($medium) < DEFAULT_AT) {
$this->parser->_add_token(AT_START, $medium, true);
}

elseif ($default_media) {
$this->parser->_add_token(AT_START, $default_media, true);
}

foreach ($val as $selector => $vali) {
if ($this->parser->get_cfg('sort_properties'))
ksort($vali);
Expand All @@ -332,6 +340,9 @@ function _convert_raw_css() {
if (intval($medium) < DEFAULT_AT) {
$this->parser->_add_token(AT_END, $medium, true);
}
elseif ($default_media) {
$this->parser->_add_token(AT_END, $default_media, true);
}
}
}

Expand Down

0 comments on commit 2cc3277

Please sign in to comment.