Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added penthouse timeout option #140

Merged
merged 3 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ critical.generate({
// Extract inlined styles from referenced stylesheets
extract: true,

// Complete Timeout for Operation
timeout: 30000,

// Prefix for asset directory
pathPrefix: '/MySubfolderDocrot',

Expand Down Expand Up @@ -219,6 +222,7 @@ critical.generate({
| inlineImages | `boolean` | `false` | Inline images
| assetPaths | `array` | `[]` | List of directories/urls where the inliner should start looking for assets
| maxImageFileSize | `integer` | `10240`| Sets a max file size (in bytes) for base64 inlined images
| timeout | `integer` | `30000`| Sets a maximum timeout for the operation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The column separators should be aligned with the others.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

friendly ping on this @leogdion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. let me know if there is anything else.

| pathPrefix | `string` | `/` | Path to prepend CSS assets with. You *must* make this path absolute if you are going to be using critical in multiple target files in disparate directory depths. (eg. targeting both `/index.html` and `/admin/index.html` would require this path to start with `/` or it wouldn't work.)
| include | `array` | `[]` | Force include css rules. See [`penthouse#usage`](https://github.com/pocketjoso/penthouse#usage-1).
| ignore | `array` | `[]` | Ignore css rules. See [`filter-css`](https://github.com/bezoerb/filter-css) for usage examples.
Expand Down
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var help = [
' --include RegExp, @type or selector to include',
' --maxFileSize Sets a max file size (in bytes) for base64 inlined images',
' --assetPaths Directories/Urls where the inliner should start looking for assets.',
' --timeout Sets the maximum timeout (in milliseconds) for the operation (defaults to 30000 ms).',
' ----------------------------------------------------------------------.',
' Deprecated - use "--inline" to retrieve the modified HTML',
' critical source.html --inline > dest.html',
Expand Down Expand Up @@ -81,6 +82,9 @@ cli.flags = _.reduce(cli.flags, function (res, val, key) {
case 'maxfilesize':
res.maxFileSize = val;
break;
case 'timeout':
res.timeout = val;
break;
case 'assetpaths':
case 'assetPaths':
if (_.isString(val)) {
Expand Down
1 change: 1 addition & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function generate(opts) {
url: file.getPenthouseUrl(opts, server.port),
css: csspath,
forceInclude: opts.include || [],
timeout: opts.timeout,
maxEmbeddedBase64Length: opts.maxImageFileSize || 10240,
// viewport width
width: dimensions.width,
Expand Down
16 changes: 16 additions & 0 deletions test/02-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ describe('Module - generate', function () {
}, assertCritical(target, expected, done));
});

it('should throw an error on timeout', function (done) {
var target = '.include.css';

critical.generate({
base: 'fixtures/',
src: 'generate-default.html',
timeout: 1,
dest: target,
width: 1300,
height: 900
}, function (err) {
assert.instanceOf(err, Error);
done();
});
});

it('should generate critical-path CSS with query string in file name', function (done) {
var expected = read('expected/generate-default.css');
var target = '.critical.css';
Expand Down