Skip to content

Commit

Permalink
-Cleaner pseudo selector regex
Browse files Browse the repository at this point in the history
  • Loading branch information
codenothing committed Dec 29, 2010
1 parent 764f6a6 commit 1be4e8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
5 changes: 3 additions & 2 deletions changelog
Expand Up @@ -6,7 +6,7 @@

# Compressor Additions
- Configuration Modes
- pseduo-space, add space between pseduo selectors and comman/brace for ie6
- pseduo-space, add space between pseduo selectors and comma/brace for ie6
- removing leading 0 of a decimal, 0.633px -> .633px
- handling all At Rules (charsets,media,imports,font-family,etc..)
- handling ms filter paths
Expand All @@ -17,5 +17,6 @@

# Codebase Changes
- Converted to subclass architecture, more modular.
- Using JSON based sandbox spec for focused unit tests.
- Using JSON based sandbox specs for focused unit tests.
- Helper conversion definitions(long2hex, hex2short) are now in JSON based files.
- Added benchmark/regression testing
18 changes: 4 additions & 14 deletions src/lib/Selectors.php
Expand Up @@ -22,7 +22,8 @@
* @param (regex) rcomma: looks for an unescaped comma character
* @param (regex) rspace: looks for an unescaped space character
* @param (regex) rid: looks for an unescaped hash character
* @param (array) pseudos: Contains pattterns and replacments to space out pseudo selectors
* @param (regex) rpseudo: Add space after first-letter|line pseudo selector
* --- when it occurs before comma or rule set
*/
private $Control;
private $token = '';
Expand All @@ -36,18 +37,7 @@
private $rcomma = "/(?<!\\\),/";
private $rspace = "/(?<!\\\)\s/";
private $rid = "/(?<!\\\)#/";
private $pseudos = array(
'patterns' => array(
"/\:first-(letter|line)[,]/i",
"/ /",
"/:first-(letter|line)$/i",
),
'replacements' => array(
":first-$1 ,",
" ",
":first-$1 ",
)
);
private $rpseudo = "/:first-(letter|line)(,|$)/i";

/**
* Stash a reference to the controller on each instantiation
Expand Down Expand Up @@ -228,7 +218,7 @@ private function repeats( $selector ) {
* @param (string) selector: CSS Selector
*/
private function pseudoSpace( $selector ) {
return preg_replace( $this->pseudos['patterns'], $this->pseudos['replacements'], $selector );
return preg_replace( $this->rpseudo, ":first-$1 $2", $selector );
}

/**
Expand Down
4 changes: 4 additions & 0 deletions unit/sandbox/Selectors.json
Expand Up @@ -135,6 +135,10 @@
"params": [ "a:first-letter,a,b" ],
"expect": "a:first-letter ,a,b"
},
"first-letter comma exists": {
"params": [ "a:first-letter ,a,b" ],
"expect": "a:first-letter ,a,b"
},
"first-line tree": {
"params": [ "a:first-line>a" ],
"expect": "a:first-line>a"
Expand Down

0 comments on commit 1be4e8c

Please sign in to comment.