|
1 | | -# php-css-lint |
2 | | -CSS Linter for PHP |
| 1 | +# Php CSS Lint |
| 2 | + |
| 3 | +[](https://travis-ci.org/neilime/ansi-escapes-to-html) |
| 4 | +[](https://packagist.org/packages/neilime/ansi-escapes-to-html) |
| 5 | +[](https://packagist.org/packages/neilime/ansi-escapes-to-html) |
| 6 | +[](https://coveralls.io/github/neilime/ansi-escapes-to-html?branch=master) |
| 7 | + |
| 8 | +_Php CSS Lint_ is a php script that lint css files and strings : |
| 9 | + |
| 10 | +```bash |
| 11 | +=========================================================== |
| 12 | + |
| 13 | + ____ _ ____ ____ ____ _ _ _ |
| 14 | + | _ \| |__ _ __ / ___/ ___/ ___| | | (_)_ __ | |_ |
| 15 | + | |_) | '_ \| '_ \ | | \___ \___ \ | | | | '_ \| __| |
| 16 | + | __/| | | | |_) | | |___ ___) |__) | | |___| | | | | |_ |
| 17 | + |_| |_| |_| .__/ \____|____/____/ |_____|_|_| |_|\__| |
| 18 | + |_| |
| 19 | +
|
| 20 | +=========================================================== |
| 21 | +
|
| 22 | +# Lint file "/path/to/css/file.css"... |
| 23 | + => File "/path/to/css/file.css" is not valid : |
| 24 | +
|
| 25 | + - Unknown CSS property "bordr-top-style" (line: 8, char: 20) |
| 26 | + - Unexpected char ":" (line: 15, char: 5) |
| 27 | +``` |
| 28 | +
|
| 29 | +# Helping Project |
| 30 | +
|
| 31 | +If this project helps you reduce time to develop and/or you want to help the maintainer of this project, you can make a donation, thank you. |
| 32 | +<a href='https://pledgie.com/campaigns/33252'><img alt='Click here to lend your support to: php-css-lint and make a donation at pledgie.com !' src='https://pledgie.com/campaigns/33252.png?skin_name=chrome' border='0' ></a> |
| 33 | +
|
| 34 | +# Contributing |
| 35 | +
|
| 36 | +If you wish to contribute to this project, please read the [CONTRIBUTING.md](CONTRIBUTING.md) file. |
| 37 | +NOTE : If you want to contribute don't hesitate, I'll review any PR. |
| 38 | +
|
| 39 | +# Requirements |
| 40 | +
|
| 41 | +Name | Version |
| 42 | +-----|-------- |
| 43 | +[php](https://secure.php.net/) | >=5.3.3 |
| 44 | +
|
| 45 | +# Installation |
| 46 | +
|
| 47 | +## Main Setup |
| 48 | +
|
| 49 | +### With composer (the faster way) |
| 50 | +
|
| 51 | +1. Add this project in your composer.json: |
| 52 | +
|
| 53 | + ```json |
| 54 | + "require": { |
| 55 | + "neilime/php-css-lint": "1.*@stable" |
| 56 | + } |
| 57 | + ``` |
| 58 | +
|
| 59 | +2. Now tell composer to download __ANSI escapes to Html__ by running the command: |
| 60 | +
|
| 61 | + ```bash |
| 62 | + $ php composer.phar update |
| 63 | + ``` |
| 64 | +
|
| 65 | +### By cloning project (manual) |
| 66 | +
|
| 67 | +1. Clone this project into your `./vendor/` directory. |
| 68 | +
|
| 69 | +# Usage |
| 70 | +
|
| 71 | +## As a bin script |
| 72 | +
|
| 73 | +### Display man page |
| 74 | +
|
| 75 | +In a terminal, execute : |
| 76 | +```bash |
| 77 | +bin/php-css-lint |
| 78 | +``` |
| 79 | +
|
| 80 | +Result : |
| 81 | +```bash |
| 82 | +=========================================================== |
| 83 | +
|
| 84 | + ____ _ ____ ____ ____ _ _ _ |
| 85 | + | _ \| |__ _ __ / ___/ ___/ ___| | | (_)_ __ | |_ |
| 86 | + | |_) | '_ \| '_ \ | | \___ \___ \ | | | | '_ \| __| |
| 87 | + | __/| | | | |_) | | |___ ___) |__) | | |___| | | | | |_ |
| 88 | + |_| |_| |_| .__/ \____|____/____/ |_____|_|_| |_|\__| |
| 89 | + |_| |
| 90 | + |
| 91 | +=========================================================== |
| 92 | + |
| 93 | +Usage : |
| 94 | +------------------------------------------------------------ |
| 95 | +Lint a CSS file : |
| 96 | +scripts/php-css-lint css_file_path_to_lint.css |
| 97 | +------------------------------------------------------------ |
| 98 | +``` |
| 99 | + |
| 100 | +### Lint a file |
| 101 | + |
| 102 | +In a terminal, execute : |
| 103 | +```bash |
| 104 | +bin/php-css-lint /path/to/css/file.css |
| 105 | +``` |
| 106 | + |
| 107 | +Result : |
| 108 | +```bash |
| 109 | +=========================================================== |
| 110 | + |
| 111 | + ____ _ ____ ____ ____ _ _ _ |
| 112 | + | _ \| |__ _ __ / ___/ ___/ ___| | | (_)_ __ | |_ |
| 113 | + | |_) | '_ \| '_ \ | | \___ \___ \ | | | | '_ \| __| |
| 114 | + | __/| | | | |_) | | |___ ___) |__) | | |___| | | | | |_ |
| 115 | + |_| |_| |_| .__/ \____|____/____/ |_____|_|_| |_|\__| |
| 116 | + |_| |
| 117 | +
|
| 118 | +=========================================================== |
| 119 | +
|
| 120 | +# Lint file "/path/to/css/file.css"... |
| 121 | + => File "/path/to/css/file.css" is not valid : |
| 122 | +
|
| 123 | + - Unknown CSS property "bordr-top-style" (line: 8, char: 20) |
| 124 | + - Unexpected char ":" (line: 15, char: 5) |
| 125 | +``` |
| 126 | +
|
| 127 | +## In a php script |
| 128 | +
|
| 129 | +### Composer autoloading |
| 130 | +
|
| 131 | +```php |
| 132 | +// Composer autoloading |
| 133 | +if (!file_exists($sComposerAutoloadPath = __DIR__ . '/vendor/autoload.php')) { |
| 134 | + throw new \RuntimeException('Composer autoload file "' . $sComposerAutoloadPath . '" does not exist'); |
| 135 | +} |
| 136 | +if (false === (include $sComposerAutoloadPath)) { |
| 137 | + throw new \RuntimeException('An error occured while including composer autoload file "' . $sComposerAutoloadPath . '"'); |
| 138 | +} |
| 139 | +``` |
| 140 | +
|
| 141 | +### Initialize Css Linter |
| 142 | +
|
| 143 | +```php |
| 144 | +$cssLinter = new \CssLint\Linter(); |
| 145 | +``` |
| 146 | +
|
| 147 | +### Lint string |
| 148 | +
|
| 149 | +```php |
| 150 | +if($cssLinter->lintString(' |
| 151 | +.button.drodown::after { |
| 152 | + display: block; |
| 153 | + width: 0; |
| 154 | +}') === true){ |
| 155 | + echo 'Valid!'; |
| 156 | +} |
| 157 | +else { |
| 158 | + echo 'Not Valid :('; |
| 159 | + var_dump($cssLinter->getErrors()); |
| 160 | +} |
| 161 | +``` |
| 162 | +
|
| 163 | +### Lint file |
| 164 | +
|
| 165 | +```php |
| 166 | +if($cssLinter->lintFile('path/to/css/file.css') === true){ |
| 167 | + echo 'Valid!'; |
| 168 | +} |
| 169 | +else { |
| 170 | + echo 'Not Valid :('; |
| 171 | + var_dump($cssLinter->getErrors()); |
| 172 | +} |
| 173 | +``` |
0 commit comments