Skip to content

Commit

Permalink
Merge branch 'master' into laravel-54
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristoffer Alfheim authored Mar 6, 2017
2 parents 99f8c98 + 7732ddc commit b48bae0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/CriticalCssServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ protected function registerAppBindings()
$generator->setOptions(
$app['config']->get('criticalcss.width'),
$app['config']->get('criticalcss.height'),
$app['config']->get('criticalcss.ignore')
$app['config']->get('criticalcss.ignore'),
$app['config']->get('criticalcss.timeout', 30000)
);

return $generator;
Expand Down
17 changes: 13 additions & 4 deletions src/CssGenerators/CriticalGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class CriticalGenerator implements CssGeneratorInterface
/** @var array */
protected $ignore;

/** @var int|null */
protected $timeout;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -61,17 +64,19 @@ public function setCriticalBin($critical)
/**
* Set optional options for Critical.
*
* @param int $width
* @param int $height
* @param array $ignore
* @param int $width
* @param int $height
* @param array $ignore
* @param int|null $timeout
*
* @return void
*/
public function setOptions($width = 900, $height = 1300, array $ignore = [])
public function setOptions($width = 900, $height = 1300, array $ignore = [], $timeout = null)
{
$this->width = $width;
$this->height = $height;
$this->ignore = $ignore;
$this->timeout = $timeout;
}

/**
Expand All @@ -92,6 +97,10 @@ public function generate($uri, $alias = null)
'--minify',
]);

if (!is_null($this->timeout)) {
$builder->add('--timeout='.$this->timeout);
}

foreach ($this->css as $css) {
$builder->add('--css='.$css);
}
Expand Down
3 changes: 0 additions & 3 deletions src/HtmlFetchers/LaravelHtmlFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class LaravelHtmlFetcher implements HtmlFetcherInterface
/** @var \Illuminate\Contracts\Foundation\Application */
protected $app = null;

/** @var \Closure */
protected $appMaker;

/**
* Create a new instance.
*
Expand Down
31 changes: 22 additions & 9 deletions src/config/criticalcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

return [

/*
|--------------------------------------------------------------------------
| Routes
Expand All @@ -29,7 +29,7 @@
| parameters filled out.) Make sure the request won't 404.
|
*/

'routes' => [
// 'static/route', // In Blade: `@criticalCss('static/route')`
// 'users/profile' => 'users/1', // In Blade: `@criticalCss('users/profile')`
Expand All @@ -45,7 +45,7 @@
| The file is relative to the public path, i.e., `public_path($css)`.
|
*/

'css' => ['css/app.css', 'css/app2.css'],

/*
Expand All @@ -56,7 +56,7 @@
| Width and height of the target viewport.
|
*/

'width' => 1300,
'height' => 900,

Expand All @@ -70,7 +70,7 @@
| @see https://github.com/bezoerb/filter-css
|
*/

'ignore' => [
// Removes @font-face blocks
// '@font-face',
Expand All @@ -90,7 +90,7 @@
| The directory which the generated critical-path CSS is stored.
|
*/

'storage' => 'critical-css',

/*
Expand All @@ -105,7 +105,7 @@
| Remember to run `php artisan view:clear` after re-disabling this.
|
*/

'pretend' => env('CRITICALCSS_PRETEND', false),

/*
Expand All @@ -118,7 +118,7 @@
| If your app is running on Laravel 5.0, this must be disabled.
|
*/

'blade_directive' => true,

/*
Expand All @@ -131,7 +131,20 @@
| installed globally, you may simply use 'critical'.
|
*/

'critical_bin' => base_path('node_modules/.bin/critical'),

/*
|--------------------------------------------------------------------------
| Timeout
|--------------------------------------------------------------------------
|
| Sets a maximum timeout, in milliseconds, for the CSS generation of a route.
| This parameter is passed to the Critical executable.
| Default value is 30000.
|
*/

'timeout' => 30000,

];
1 change: 1 addition & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ConfigTest extends TestCase
'pretend' => 'string',
'blade_directive' => 'bool',
'critical_bin' => 'string',
'timeout' => 'integer',
];

public function testConfigIsOk()
Expand Down

0 comments on commit b48bae0

Please sign in to comment.