Skip to content

Commit

Permalink
Update Autoprefixe.js, tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Pronsky committed Sep 15, 2014
1 parent d8ece84 commit 3d0e552
Show file tree
Hide file tree
Showing 6 changed files with 6,378 additions and 6,579 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Autoprefixer PHP
# Autoprefixer PHP [![Build Status](https://travis-ci.org/vladkens/autoprefixer-php.svg?branch=master)](https://travis-ci.org/vladkens/autoprefixer-php)

[Autoprefixer](https://github.com/ai/autoprefixer) is a tool
to parse CSS and add vendor prefixes to CSS rules using values
Expand Down Expand Up @@ -67,7 +67,7 @@ $prefixed = $autoprefixer->compile($css_one);
echo $prefixed;
// If need compile many css in one time. Function return array of compiled CSS.
$prefixed = $autoprefixer->(array($css_one, $css_two));
$prefixed = $autoprefixer->([$css_one, $css_two]);
echo $prefixed[0] . "\n" . $prefixed[1];
// If occurred error in compile time Autoprefixer throw exception named `AutoprefixerException`.
Expand All @@ -83,7 +83,7 @@ try {
// If you want to choose specific browsers
$autoprefixer = new Autoprefixer('last 1 version'); // one rule
// or
$autoprefixer = new Autoprefixer(array('ff > 2', '> 2%', 'ie8')); // many rules
$autoprefixer = new Autoprefixer(['ff > 2', '> 2%', 'ie 8']); // many rules
// or
$autoprefixer->setBrowsers('last 1 version');
// or change browsers on a one iteration
Expand Down
22 changes: 15 additions & 7 deletions lib/Autoprefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Autoprefixer
*/
public function __construct($browsers = null)
{
if (!is_null($browsers)) $this->setBrowsers($browsers);
if (!is_null($browsers)) {
$this->setBrowsers($browsers);
}
}

/**
Expand All @@ -27,8 +29,9 @@ public function __construct($browsers = null)
*/
public function setBrowsers($browsers)
{
if (!is_array($browsers)) $browsers = array($browsers);

if (!is_array($browsers)) {
$browsers = array($browsers);
}
$this->browsers = $browsers;
}

Expand All @@ -40,17 +43,21 @@ public function setBrowsers($browsers)
*/
public function compile($css, $browsers = null)
{
if ($return_string = !is_array($css)) $css = array($css);
if ($return_string = !is_array($css)) {
$css = array($css);
}

$nodejs = proc_open('node ' . __DIR__ . '/vendor/wrap.js',
array(array('pipe', 'r'), array('pipe', 'w')),
$pipes);
$pipes
);

if ($nodejs) {
$this->fwrite_stream($pipes[0],
json_encode(array(
'css' => $css,
'browsers' => !is_null($browsers) ? $browsers : $this->browsers)));
'browsers' => !is_null($browsers) ? $browsers : $this->browsers)
));
fclose($pipes[0]);

$output = stream_get_contents($pipes[1]);
Expand All @@ -68,8 +75,9 @@ public function compile($css, $browsers = null)
}
}

if (strlen($error_messages) > 0)
if (strlen($error_messages) > 0) {
throw new AutoprefixerException($error_messages);
}

return $return_string ? $output[0] : $output;
}
Expand Down
Loading

0 comments on commit 3d0e552

Please sign in to comment.