Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (42 sloc) 1.554 kb
7fde3760 »
2011-06-29 added css support via csstidy with a custom wrapper, also moved files…
1 <?php
2
3 /**
4 * Wrapper for the PHP version of CSS Tidy to allow it to accept command line arguments.
5 *
87b5bafe »
2011-06-30 mentioning php5-cli in the readme for the CSS Tidy wrapper.
6 * (I tried the linux version but I couldn't get the binary to work or the source to compile without errors..)
7fde3760 »
2011-06-29 added css support via csstidy with a custom wrapper, also moved files…
7 *
8 * Requires php5-cli to work:
9 * sudo aptitude install php5-cli
10 *
11 * Copyright Nathan Friedly - http://nfriedly.com
12 *
13 * MIT License
14 **/
15
16 if(!isset($argv[2])){
17 exit("usage:\n$ php $argv[0] source.css destination.css\n");
18 }
19
20 // fire up css tidy
f1d8f310 »
2011-06-30 moved the csstidy wrapper out of lib/ and updated the readme.
21 require('lib/csstidy-1.3/class.csstidy.php');
7fde3760 »
2011-06-29 added css support via csstidy with a custom wrapper, also moved files…
22 $css = new csstidy();
23
24 // put all settings on "no shenanigans" mode
25 $css->set_cfg('remove_bslash',false);
26 $css->set_cfg('compress_colors',false);
27 $css->set_cfg('compress_font-weight',false);
28 $css->set_cfg('lowercase_s',false);
29 $css->set_cfg('optimise_shorthands',0);
30 $css->set_cfg('remove_last_;',false);
31 $css->set_cfg('case_properties',0);
32 $css->set_cfg('sort_properties',false);
33 $css->set_cfg('sort_selectors',false);
34 $css->set_cfg('merge_selectors',0);
35 $css->set_cfg('discard_invalid_properties',false);
36 $css->set_cfg('preserve_css',true);
37 $css->set_cfg('timestamp',false);
38
39 $css->load_template('low_compression');
40
41 // read in the source file
42 $source_css = file_get_contents($argv[1]) or die("Error reading source file $argv[1]\n");
43
44 //echo "source css: \n\n" . substr($source_css,0,300) . "...\n\n";
45
46 $css->parse($source_css);
47
48 // and spit out the results
49 $result = $css->print->plain();
50
51 //echo "parsed css: \n\n" . substr($result,0,300) . "...\n\n";
52
53 file_put_contents($argv[2], $result) or die ("Error writing to destination file $argv[2]\n");
Something went wrong with that request. Please try again.