File tree Expand file tree Collapse file tree 10 files changed +176
-3
lines changed
Expand file tree Collapse file tree 10 files changed +176
-3
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "node" : true ,
3+ "esnext" : true ,
4+ "bitwise" : true ,
5+ "camelcase" : true ,
6+ "curly" : true ,
7+ "eqeqeq" : true ,
8+ "immed" : true ,
9+ "indent" : 4 ,
10+ "newcap" : true ,
11+ "noarg" : true ,
12+ "quotmark" : " single" ,
13+ "regexp" : true ,
14+ "undef" : true ,
15+ "unused" : true ,
16+ "strict" : true ,
17+ "trailing" : true ,
18+ "smarttabs" : true
19+ }
Original file line number Diff line number Diff line change 1+ language : node_js
2+ node_js :
3+ - ' 0.10'
4+ - ' 0.11'
Original file line number Diff line number Diff line change 1- gulp-dom-src
2- ============
1+ # gulp-dom-src [ ![ Build Status] ( https://travis-ci.org/cgross/gulp-dom-src.png?branch=master )] ( https://travis-ci.org/cgross/gulp-dom-src )
2+
3+ > Create a gulp stream from script, link, or any set of tags in an HTML file.
4+
5+ ## Example
6+
7+ ``` js
8+ var gulp = require (' gulp' );
9+ var domSrc = require (' gulp-dom-src' );
10+ var concat = require (' gulp-concat' );
11+ var uglify = require (' gulp-uglify' );
12+
13+ gulp .task (' default' , function () {
14+ domSrc ({ file: ' index.html' , selector: ' script' , attribute: ' src' })
15+ .pipe (concat (' app.full.min.js' ))
16+ .pipe (uglify ())
17+ .pipe (gulp .dest (' dist/' ));
18+ });
19+ ```
20+
21+ ## API
22+
23+ ### domSrc(config)
24+
25+
26+ #### config.file
27+
28+ Type: ` String `
29+
30+ The name of the HTML file to read the tags from.
31+
32+
33+ #### config.selector
34+
35+ Type: ` String `
36+
37+ Any valid CSS selector.
38+
39+
40+ #### config.attribute
41+
42+ Type: ` String `
43+
44+ The name of the attribute that contains the file path. Typically ` src ` for ` script ` tags and ` href ` for ` link ` s.
45+
46+
47+ #### config.options
48+
49+ Type: ` Object `
50+ Default: ` {} `
51+
52+ Options passed through to the underlying ` vinyl-fs ` . Can include options like ` read ` and ` buffer ` .
53+
354
4- Create a gulp stream from script, link, or any set of tags in an HTML file.
Original file line number Diff line number Diff line change 1+ var vinylFs = require ( 'vinyl-fs' ) ;
2+ var cheerio = require ( 'cheerio' ) ;
3+ var fs = require ( 'fs' ) ;
4+ var path = require ( 'path' ) ;
5+
6+ module . exports = function ( config ) {
7+
8+ var html = fs . readFileSync ( path . join ( process . cwd ( ) , config . file ) , 'utf8' ) ;
9+ var $ = cheerio . load ( html ) ;
10+
11+ var files = $ ( config . selector ) . map ( function ( i , elem ) {
12+ return $ ( elem ) . attr ( config . attribute ) ;
13+ } ) . toArray ( ) . filter ( function ( item ) {
14+ return ( item !== undefined && item . substring ( 0 , 4 ) !== 'http' && item . substring ( 0 , 2 ) !== '//' ) ;
15+ } ) . map ( function ( item ) {
16+ return path . join ( path . dirname ( config . file ) , item ) ;
17+ } ) ;
18+
19+ return vinylFs . src ( files , config . options || { } ) ;
20+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " gulp-dom-src" ,
3+ "version" : " 0.1.0" ,
4+ "description" : " Create a gulp stream from script/link tags in an HTML file." ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " mocha"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " https://github.com/cgross/gulp-dom-src"
12+ },
13+ "keywords" : [
14+ " gulpplugin" ,
15+ " html" ,
16+ " dom"
17+ ],
18+ "author" : " Chris Gross" ,
19+ "license" : " MIT" ,
20+ "dependencies" : {
21+ "vinyl-fs" : " ~0.1.0" ,
22+ "cheerio" : " ~0.13.1"
23+ },
24+ "devDependencies" : {
25+ "mocha" : " ~1.17.1" ,
26+ "should" : " ~3.1.3" ,
27+ "through2" : " ~0.4.1" ,
28+ "buffer-equal" : " 0.0.0"
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ < html >
2+ < body >
3+ < script src ="one.js "> </ script >
4+ < script >
5+ alert ( 'hello' ) ;
6+ </ script >
7+ < script src ="two.js "/> </ script>
8+ < script src = "//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js" > </ script >
9+ < script src ="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js "> </ script >
10+ < script src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js "> </ script >
11+ < script src ="three.js "/> </ script>
12+ </body>
13+ </html>
Original file line number Diff line number Diff line change 1+ one
Original file line number Diff line number Diff line change 1+ three
Original file line number Diff line number Diff line change 1+ two
Original file line number Diff line number Diff line change 1+ var path = require ( 'path' ) ;
2+ var fs = require ( 'fs' ) ;
3+ var should = require ( 'should' ) ;
4+ var domSrc = require ( '../index' ) ;
5+ var vfs = require ( 'vinyl-fs' ) ;
6+ var through = require ( 'through2' ) ;
7+
8+ var dataWrap = function ( fn ) {
9+ return function ( data , enc , cb ) {
10+ fn ( data ) ;
11+ cb ( ) ;
12+ } ;
13+ } ;
14+
15+ it ( 'should read the script tags src into the stream' , function ( done ) {
16+
17+ var onEnd = function ( ) {
18+ buffered . length . should . equal ( 3 ) ;
19+ should . exist ( buffered [ 0 ] . stat ) ;
20+ buffered [ 0 ] . path . should . equal ( path . resolve ( 'test/fixture/one.js' ) ) ;
21+ buffered [ 1 ] . path . should . equal ( path . resolve ( 'test/fixture/two.js' ) ) ;
22+ buffered [ 2 ] . path . should . equal ( path . resolve ( 'test/fixture/three.js' ) ) ;
23+ done ( ) ;
24+ } ;
25+
26+ var stream = domSrc ( { file :'test/fixture/fixture.html' , selector :'script' , attribute :'src' } ) ;
27+
28+ var buffered = [ ] ;
29+ var bufferStream = through . obj ( dataWrap ( buffered . push . bind ( buffered ) ) , onEnd ) ;
30+ stream . pipe ( bufferStream ) ;
31+
32+ } ) ;
33+
34+
You can’t perform that action at this time.
0 commit comments