-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. Fully tested, but basic first version
- Loading branch information
Showing
10 changed files
with
346 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true, | ||
"laxcomma": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* grunt-penthouse | ||
* https://github.com/carl-erik.kopseng/grunt-penthouse | ||
* | ||
* Copyright (c) 2014 Carl-Erik Kopseng | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
|
||
// Autoload tasks from dependencies | ||
require('load-grunt-tasks')(grunt); | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
|
||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'tasks/*.js', | ||
//'<%= nodeunit.tests %>', | ||
], | ||
options: { | ||
jshintrc: '.jshintrc', | ||
}, | ||
}, | ||
|
||
// Before generating any new files, remove any previously-created files. | ||
clean: { | ||
tests: ['.tmp'], | ||
}, | ||
|
||
// Configuration to be run (and then tested). | ||
penthouse: { | ||
testTask: { | ||
outfile : '.tmp/out.css', | ||
css : 'test/www/main.css', | ||
url : 'http://localhost:9001', | ||
width : 1300, | ||
height : 900 | ||
}, | ||
}, | ||
|
||
// Unit tests. | ||
mochaTest: { | ||
tests: ['test/*test.js'] | ||
}, | ||
|
||
connect: { | ||
server: { | ||
options: { | ||
port: 9001, | ||
base: 'test/www' | ||
} | ||
} | ||
}, | ||
|
||
watch: { | ||
dev: { | ||
files: ['Gruntfile.js', 'package.json','tasks/*.js'], | ||
tasks : ['jshint', 'penthouse'] | ||
}, | ||
|
||
logic : { | ||
files: ['tasks/*.js'], | ||
tasks : ['test'] | ||
}, | ||
|
||
test : { | ||
files: ['test/**'], | ||
tasks : ['test'] | ||
}, | ||
|
||
} | ||
|
||
}); | ||
|
||
// Actually load this plugin's task(s). | ||
grunt.loadTasks('tasks'); | ||
|
||
// Whenever the "test" task is run, first clean the ".tmp" dir, then run this | ||
// plugin's task(s), then test the result. | ||
grunt.registerTask('test', ['clean', 'connect', 'penthouse', 'mochaTest']); | ||
|
||
// By default, lint and run all tests. | ||
grunt.registerTask('default', ['jshint', 'test']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2014 Carl-Erik Kopseng | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,43 @@ | ||
grunt-penthouse | ||
=============== | ||
# grunt-penthouse | ||
> A grunt plugin based on [Penthouse](npmjs.org/package/penthouse) that extracts [critical path css](http://addyosmani.com/blog/tag/critical-path-css/) | ||
A grunt plugin that uses Penthouse to extract critical path css | ||
[](http://badge.fury.io/js/grunt-penthouse) | ||
[](https://travis-ci.org/fatso83/grunt-penthouse) | ||
|
||
## Getting Started | ||
|
||
Install the plugin | ||
|
||
```shell | ||
npm install grunt-penthouse --save-dev | ||
``` | ||
|
||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
|
||
```js | ||
grunt.loadNpmTasks('grunt-penthouse'); | ||
``` | ||
|
||
## The "penthouse" task | ||
|
||
### Overview | ||
In your project's Gruntfile, add a section named `penthouse` to the data object passed into `grunt.initConfig()`. | ||
|
||
### Usage Example | ||
|
||
```js | ||
grunt.initConfig({ | ||
penthouse: { | ||
extract : { | ||
outfile : '.tmp/out.css', | ||
css : './dist/css/full.css', | ||
url : 'http://localhost:9000', | ||
width : 1300, | ||
height : 900 | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
## Release History | ||
None yet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "grunt-penthouse", | ||
"description": "Grunt plugin for extracting critical path css", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/fatso83/grunt-penthouse", | ||
"author": { | ||
"name": "Carl-Erik Kopseng", | ||
"email": "[email protected]", | ||
"url": "http://oligofren.wordpress.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/fatso83/grunt-penthouse.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fatso83/grunt-penthouse/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/fatso83/grunt-penthouse/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"dependencies": { | ||
"penthouse": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-clean": "~0.4.0", | ||
"grunt-contrib-connect": "^0.8.0", | ||
"grunt-contrib-jshint": "~0.6.0", | ||
"grunt-contrib-watch": "^0.6.1", | ||
"grunt-mocha-test": "^0.11.0", | ||
"load-grunt-tasks": "^0.4.0" | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.2" | ||
}, | ||
"keywords": [ | ||
"gruntplugin", | ||
"penthouse", | ||
"critical path css", | ||
"tools", | ||
"css" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* grunt-penthouse | ||
* https://github.com/fatso83/grunt-penthouse | ||
* | ||
* Copyright (c) 2014 Carl-Erik Kopseng | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var penthouse = require('penthouse'), | ||
path = require('path'), | ||
fs = require('fs-extra'); | ||
|
||
module.exports = function(grunt) { | ||
var pretty = function(o) { | ||
return JSON.stringify(o, null, " "); | ||
}; | ||
|
||
grunt.registerMultiTask('penthouse', 'Extracts critical path CSS', function() { | ||
|
||
// we don't check for errors in config, but leave the error reporting to penthouse | ||
var done = this.async(), | ||
options = this.data, | ||
outfile = path.normalize(this.data.outfile), | ||
dir=path.dirname(outfile); | ||
|
||
penthouse( options, function(err, result) { | ||
if(err) { | ||
if(err.msg) grunt.log.errorlns(err.msg); | ||
done(false); | ||
return; | ||
} | ||
|
||
grunt.log.debug(result); | ||
|
||
grunt.file.write(outfile, result, {}); | ||
done(); | ||
}); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Expected to be run after 'grunt penthouse' */ | ||
'use strict'; | ||
|
||
var read = require('fs').readFileSync | ||
, chai = require('chai') | ||
, should = chai.should(); | ||
|
||
chai.config.includeStack = true; | ||
|
||
describe('Basic functionality tests', function () { | ||
|
||
var taskConfig; | ||
|
||
function stub() { } | ||
|
||
before(function() { | ||
// get the config | ||
require(__dirname + '/../Gruntfile.js')({ | ||
loadTasks : stub, | ||
registerTask : stub, | ||
loadNpmTasks : stub, | ||
initConfig : function(config) { | ||
taskConfig = config.penthouse.testTask; | ||
} | ||
}); | ||
}); | ||
|
||
it('should produce a non-empty file', function() { | ||
read(taskConfig.outfile).should.not.be.empty; | ||
}); | ||
|
||
it('should produce a file with the same content as the penthouse module', function(done) { | ||
var penthouse = require('penthouse'); | ||
|
||
penthouse(taskConfig, function(result) { | ||
read(taskConfig.outfile).should.equal.result; | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Server of static files | ||
var express = require('express'); | ||
var app = module.exports = express(); | ||
app.use(express.static(__dirname )); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
<link rel="stylesheet" href="main.css"/> | ||
</head> | ||
<body> | ||
<div id="box1">Box 1 | ||
<div id="box11">Box 1.1</div> | ||
</div> | ||
<div id="box2">Box 2 | ||
<div id="box21">Box 2.1</div> | ||
<div id="box22">Box 2.2</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#box1 { | ||
width : 800px; | ||
height: 400px; | ||
background : red; | ||
} | ||
#box2 { | ||
width : 800px; | ||
height: 400px; | ||
background : blue; | ||
} | ||
|
||
#box21 { | ||
width : 100%; | ||
height: 100px; | ||
background: yellow; | ||
} | ||
|
||
#box22 { | ||
width : 100%; | ||
height: 50px; | ||
padding-top: 200px; | ||
background: green; | ||
} |