-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
176 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,19 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 4, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": 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,4 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '0.11' |
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,54 @@ | ||
gulp-dom-src | ||
============ | ||
# gulp-dom-src [![Build Status](https://travis-ci.org/cgross/gulp-dom-src.png?branch=master)](https://travis-ci.org/cgross/gulp-dom-src) | ||
|
||
> Create a gulp stream from script, link, or any set of tags in an HTML file. | ||
## Example | ||
|
||
```js | ||
var gulp = require('gulp'); | ||
var domSrc = require('gulp-dom-src'); | ||
var concat = require('gulp-concat'); | ||
var uglify = require('gulp-uglify'); | ||
|
||
gulp.task('default', function () { | ||
domSrc({ file: 'index.html', selector: 'script', attribute: 'src' }) | ||
.pipe(concat('app.full.min.js')) | ||
.pipe(uglify()) | ||
.pipe(gulp.dest('dist/')); | ||
}); | ||
``` | ||
|
||
## API | ||
|
||
### domSrc(config) | ||
|
||
|
||
#### config.file | ||
|
||
Type: `String` | ||
|
||
The name of the HTML file to read the tags from. | ||
|
||
|
||
#### config.selector | ||
|
||
Type: `String` | ||
|
||
Any valid CSS selector. | ||
|
||
|
||
#### config.attribute | ||
|
||
Type: `String` | ||
|
||
The name of the attribute that contains the file path. Typically `src` for `script` tags and `href` for `link`s. | ||
|
||
|
||
#### config.options | ||
|
||
Type: `Object` | ||
Default: `{}` | ||
|
||
Options passed through to the underlying `vinyl-fs`. Can include options like `read` and `buffer`. | ||
|
||
|
||
Create a gulp stream from script, link, or any set of tags in an HTML file. |
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,20 @@ | ||
var vinylFs = require('vinyl-fs'); | ||
var cheerio = require('cheerio'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
module.exports = function(config){ | ||
|
||
var html = fs.readFileSync(path.join(process.cwd(),config.file),'utf8'); | ||
var $ = cheerio.load(html); | ||
|
||
var files = $(config.selector).map(function(i,elem){ | ||
return $(elem).attr(config.attribute); | ||
}).toArray().filter(function(item){ | ||
return (item !== undefined && item.substring(0,4) !== 'http' && item.substring(0,2) !== '//'); | ||
}).map(function(item){ | ||
return path.join(path.dirname(config.file),item); | ||
}); | ||
|
||
return vinylFs.src(files,config.options || {}); | ||
}; |
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,30 @@ | ||
{ | ||
"name": "gulp-dom-src", | ||
"version": "0.1.0", | ||
"description": "Create a gulp stream from script/link tags in an HTML file.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cgross/gulp-dom-src" | ||
}, | ||
"keywords": [ | ||
"gulpplugin", | ||
"html", | ||
"dom" | ||
], | ||
"author": "Chris Gross", | ||
"license": "MIT", | ||
"dependencies": { | ||
"vinyl-fs": "~0.1.0", | ||
"cheerio": "~0.13.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.17.1", | ||
"should": "~3.1.3", | ||
"through2": "~0.4.1", | ||
"buffer-equal": "0.0.0" | ||
} | ||
} |
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,13 @@ | ||
<html> | ||
<body> | ||
<script src="one.js"></script> | ||
<script> | ||
alert('hello'); | ||
</script> | ||
<script src="two.js"/></script> | ||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script> | ||
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script> | ||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script> | ||
<script src="three.js"/></script> | ||
</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 @@ | ||
one |
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 @@ | ||
three |
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 @@ | ||
two |
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,34 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var should = require('should'); | ||
var domSrc = require('../index'); | ||
var vfs = require('vinyl-fs'); | ||
var through = require('through2'); | ||
|
||
var dataWrap = function(fn) { | ||
return function(data, enc, cb) { | ||
fn(data); | ||
cb(); | ||
}; | ||
}; | ||
|
||
it('should read the script tags src into the stream', function (done) { | ||
|
||
var onEnd = function(){ | ||
buffered.length.should.equal(3); | ||
should.exist(buffered[0].stat); | ||
buffered[0].path.should.equal(path.resolve('test/fixture/one.js')); | ||
buffered[1].path.should.equal(path.resolve('test/fixture/two.js')); | ||
buffered[2].path.should.equal(path.resolve('test/fixture/three.js')); | ||
done(); | ||
}; | ||
|
||
var stream = domSrc({file:'test/fixture/fixture.html',selector:'script',attribute:'src'}); | ||
|
||
var buffered = []; | ||
var bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd); | ||
stream.pipe(bufferStream); | ||
|
||
}); | ||
|
||
|