User Tools

Site Tools


products:stewcss:util

Table of Contents

Utilities

Now that we have a complete style sheet, we can run some utilities to help us along.

Note you can grab your own compressed and minified css off your site for this as well.

Identifiers

There are CSS parser and we should probably investigate. But this was fast and easy, I stole it from http://stackoverflow.com/questions/10654654/extract-css-classes-and-ids-from-source-with-php

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Grab contents of css file
$file = file_get_contents('./theme/frontend/mytheme/style/mytheme/css/auto.css');

//Strip out everything between { and }
$pattern_one = '/(?<=\{)(.*?)(?=\})/s';

//Match any and all selectors (and pseudos)
$pattern_two = '/[\.|#][\w]([:\w]+?)+/';

//Run the first regex pattern on the input
$stripped = preg_replace($pattern_one, '', $file);

//Variable to hold results
$selectors = array();

//Run the second regex pattern on $stripped input
$matches = preg_match_all($pattern_two, $stripped, $selectors);

$result = array_unique($selectors[0]);
asort($result);
//Show the results
echo '<pre>';
foreach($result as $i => $m)
{
    echo '<br>' . $m;
}
//print_r(array_unique($selectors[0]));
//echo '<pre>';

die('<hr>');

The output is shown here. Now we can use this with sed/awk to discover which are never used.

Colors

Somewhere I have a utility to extract colors from CSS. Find that and include it here.

It was with V2 utilities I think….

products/stewcss/util.txt · Last modified: 2015/01/10 08:51 by steward