├── test ├── fixtures │ ├── stuff │ │ ├── run.dmc │ │ └── test.dmc │ ├── test.coffee │ ├── test │ │ └── run.jade │ ├── copy │ │ └── example.txt │ ├── pages │ │ ├── about.hbs │ │ ├── home.hbs │ │ └── blog.hbs │ ├── includes │ │ ├── info.hbs │ │ ├── footer.hbs │ │ ├── header.hbs │ │ └── post.hbs │ └── layouts │ │ ├── default.hbs │ │ ├── base.hbs │ │ └── post.hbs └── test.js ├── .gitattributes ├── .jshintrc ├── .verbrc.md ├── .gitignore ├── LICENSE-MIT ├── package.json ├── README.md └── index.js /test/fixtures/stuff/run.dmc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/stuff/test.dmc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/test.coffee: -------------------------------------------------------------------------------- 1 | this is a test -------------------------------------------------------------------------------- /test/fixtures/test/run.jade: -------------------------------------------------------------------------------- 1 | test template -------------------------------------------------------------------------------- /test/fixtures/copy/example.txt: -------------------------------------------------------------------------------- 1 | this is a test -------------------------------------------------------------------------------- /test/fixtures/pages/about.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: About Page 3 | --- 4 | {{> info }} -------------------------------------------------------------------------------- /test/fixtures/pages/home.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: Home Page 3 | --- 4 | {{> info }} -------------------------------------------------------------------------------- /test/fixtures/includes/info.hbs: -------------------------------------------------------------------------------- 1 |
(From info.hbs) - Title: {{site.title}} - {{title}}
-------------------------------------------------------------------------------- /test/fixtures/layouts/default.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | layout: base 3 | --- 4 | {{> header }} 5 | {{ body }} 6 | {{> footer }} -------------------------------------------------------------------------------- /test/fixtures/includes/footer.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | message: Message from the footer 3 | --- 4 |
Footer {{message}}
-------------------------------------------------------------------------------- /test/fixtures/includes/header.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | message: Message from the header 3 | --- 4 |
Header {{message}}
-------------------------------------------------------------------------------- /test/fixtures/layouts/base.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{site.title}} 6 | 7 | 8 | {{body}} 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/pages/blog.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | show-full: false 4 | title: Blog Page 5 | --- 6 | {{> info }} 7 |
8 | {{#each posts}} 9 | {{> post this}} 10 | {{/each}} 11 |
-------------------------------------------------------------------------------- /test/fixtures/includes/post.hbs: -------------------------------------------------------------------------------- 1 |
{{author}}
2 |
{{timestamp}}
3 | {{#if ../show-full}} 4 |
5 | {{content}} 6 |
7 | {{else}} 8 |
9 | {{summary}} 10 |
11 | {{/if}} 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | *.* text eol=lf 3 | *.css text eol=lf 4 | *.html text eol=lf 5 | *.js text eol=lf 6 | *.json text eol=lf 7 | *.less text eol=lf 8 | *.md text eol=lf 9 | *.yml text eol=lf 10 | 11 | *.jpg binary 12 | *.gif binary 13 | *.png binary 14 | *.jpeg binary -------------------------------------------------------------------------------- /test/fixtures/layouts/post.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 |
5 | {{body}} 6 |
7 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esnext": true, 3 | "boss": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "eqnull": true, 7 | "immed": true, 8 | "latedef": true, 9 | "newcap": true, 10 | "noarg": true, 11 | "node": true, 12 | "sub": true, 13 | "undef": true, 14 | "unused": true, 15 | "globals": { 16 | "define": true, 17 | "before": true, 18 | "after": true, 19 | "describe": true, 20 | "it": true 21 | } 22 | } -------------------------------------------------------------------------------- /.verbrc.md: -------------------------------------------------------------------------------- 1 | --- 2 | tags: ['verb-tag-jscomments'] 3 | --- 4 | 5 | # {%= name %} {%= badge("fury") %} 6 | 7 | > {%= description %} 8 | 9 | ## Install 10 | {%= include("install") %} 11 | 12 | ## Add 13 | {%= jscomments("index.js") %} 14 | 15 | ## Author 16 | {%= include("author") %} 17 | 18 | ## License 19 | {%= copyright() %} 20 | {%= license() %} 21 | 22 | *** 23 | 24 | {%= include("footer") %} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.csv 3 | *.dat 4 | *.diff 5 | *.err 6 | *.gz 7 | *.log 8 | *.orig 9 | *.out 10 | *.pid 11 | *.rej 12 | *.seed 13 | *.swo 14 | *.swp 15 | *.vi 16 | *.yo-rc.json 17 | *.zip 18 | *~ 19 | .ruby-version 20 | lib-cov 21 | 22 | # OS or Editor folders 23 | *.esproj 24 | *.sublime-project 25 | *.sublime-workspace 26 | ._* 27 | .cache 28 | .DS_Store 29 | .idea 30 | .project 31 | .settings 32 | .tmproj 33 | nbproject 34 | Thumbs.db 35 | 36 | # Komodo 37 | *.komodoproject 38 | .komodotools 39 | 40 | # grunt-html-validation 41 | validation-status.json 42 | validation-report.json 43 | 44 | # Vendor packages 45 | node_modules 46 | bower_components 47 | vendor 48 | 49 | # General folders and files to ignore 50 | _gh_pages 51 | tmp 52 | temp 53 | TODO.md -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 , contributors. 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "assemble-middleware-add", 3 | "description": "Add files to your Assemble file stream.", 4 | "version": "0.1.1", 5 | "homepage": "https://github.com/assemble/assemble-middleware-add", 6 | "author": { 7 | "name": "Brian Woodward", 8 | "url": "https://github.com/doowb" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/assemble/assemble-middleware-add.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/assemble/assemble-middleware-add/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "https://github.com/assemble/assemble-middleware-add/blob/master/LICENSE-MIT" 21 | } 22 | ], 23 | "keywords": [ 24 | "docs", 25 | "documentation", 26 | "generate", 27 | "generator", 28 | "markdown", 29 | "templates", 30 | "verb" 31 | ], 32 | "main": "index.js", 33 | "engines": { 34 | "node": ">=0.10.0" 35 | }, 36 | "scripts": { 37 | "test": "mocha -R spec" 38 | }, 39 | "devDependencies": { 40 | "verb": "~0.2.6", 41 | "chai": "~1.9.1", 42 | "mocha": "*", 43 | "verb-tag-jscomments": "^0.1.4" 44 | }, 45 | "dependencies": { 46 | "through2": "^0.5.1" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # assemble-middleware-add [![NPM version](https://badge.fury.io/js/assemble-middleware-add.png)](http://badge.fury.io/js/assemble-middleware-add) 3 | 4 | > Add files to your Assemble file stream. 5 | 6 | ## Install 7 | Install with [npm](npmjs.org): 8 | 9 | ```bash 10 | npm i assemble-middleware-add --save-dev 11 | ``` 12 | 13 | ## Add 14 | ### add 15 | 16 | Add files to the current Assemble stream. 17 | 18 | **Usage** 19 | 20 | ```js 21 | var assemble = require('assemble'); 22 | var add = require('assemble-middleware-add')(assemble); 23 | 24 | assemble.src('path/to/pages/*.hbs') 25 | .pipe(assemble.dest('path/to/dest/pages/') 26 | .pipe(add('path/to/posts/*.md')) 27 | .pipe(assemble.dest('path/to/dest/blog/'); 28 | ``` 29 | 30 | * `assemble` {Object}: instance of assemble 31 | * `return` {Function} `addSrc` function to be used to create a stream. 32 | 33 | ## Author 34 | 35 | **Brian Woodward** 36 | 37 | + [github/assemble](https://github.com/assemble) 38 | + [twitter/assemble](http://twitter.com/assemble) 39 | 40 | ## License 41 | Copyright (c) 2014 Brian Woodward, contributors. 42 | Released under the MIT license 43 | 44 | *** 45 | 46 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 30, 2014._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * assemble-middleware-add 3 | * 4 | * Copyright (c) 2014 Brian Woodward, contributors. 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var through = require('through2'); 11 | 12 | 13 | /** 14 | * ## add 15 | * 16 | * Add files to the current Assemble stream. 17 | * 18 | * **Usage** 19 | * 20 | * ```js 21 | * var assemble = require('assemble'); 22 | * var add = require('assemble-middleware-add')(assemble); 23 | * 24 | * assemble.src('path/to/pages/*.hbs') 25 | * .pipe(assemble.dest('path/to/dest/pages/') 26 | * .pipe(add('path/to/posts/*.md')) 27 | * .pipe(assemble.dest('path/to/dest/blog/'); 28 | * ``` 29 | * 30 | * @param {Object} `assemble` instance of assemble 31 | * @return {Function} `addSrc` function to be used to create a stream. 32 | */ 33 | 34 | module.exports = function (assemble) { 35 | 36 | return function add (glob, options) { 37 | 38 | // forget the initial files 39 | return through.obj(function (file, enc, callback) { 40 | callback(); 41 | }, 42 | 43 | // when all the current files are done, 44 | // read in the new files and pass those 45 | // into the current stream (self.push) 46 | function (callback) { 47 | var self = this; 48 | 49 | // use the normal `assemble.src` to ensure 50 | // everything is loaded/read the same way 51 | assemble.src(glob, options) 52 | 53 | // push the new files into the parent stream 54 | .pipe(through.obj(function (file, enc, cb) { 55 | self.push(file); 56 | cb(); 57 | }, 58 | 59 | // let the parent know when this is complete 60 | function (cb) { 61 | callback(); 62 | cb(); 63 | })); 64 | }); 65 | }; 66 | 67 | }; -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var should = require('should'); 4 | var join = require('path').join; 5 | require('mocha'); 6 | 7 | var assemble = require('assemble'); 8 | var add = require('../')(assemble); 9 | 10 | 11 | describe('assemble-middleware-add', function() { 12 | describe('add()', function() { 13 | it('should return a stream', function(done) { 14 | var stream = add(join(__dirname, "./fixtures/*.coffee")); 15 | should.exist(stream); 16 | should.exist(stream.on); 17 | done(); 18 | }); 19 | it('should return a input stream from a flat glob', function(done) { 20 | var stream = assemble.src('!*').pipe(add(join(__dirname, "./fixtures/*.coffee"))); 21 | stream.on('error', done); 22 | stream.on('data', function(file) { 23 | should.exist(file); 24 | should.exist(file.path); 25 | should.exist(file.contents); 26 | join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee")); 27 | String(file.contents).should.equal("this is a test"); 28 | }); 29 | stream.on('end', function() { 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should return a input stream for multiple globs', function(done) { 35 | var globArray = [ 36 | join(__dirname, "./fixtures/stuff/run.dmc"), 37 | join(__dirname, "./fixtures/stuff/test.dmc") 38 | ]; 39 | var stream = assemble.src('!*').pipe(add(globArray)); 40 | 41 | var files = []; 42 | stream.on('error', done); 43 | stream.on('data', function(file) { 44 | should.exist(file); 45 | should.exist(file.path); 46 | files.push(file); 47 | }); 48 | stream.on('end', function() { 49 | files.length.should.equal(2); 50 | files[0].path.should.equal(globArray[0]); 51 | files[1].path.should.equal(globArray[1]); 52 | done(); 53 | }); 54 | }); 55 | 56 | it('should return a input stream for multiple globs, with negation', function(done) { 57 | var expectedPath = join(__dirname, "./fixtures/stuff/run.dmc"); 58 | var globArray = [ 59 | join(__dirname, "./fixtures/stuff/*.dmc"), 60 | '!' + join(__dirname, "./fixtures/stuff/test.dmc"), 61 | ]; 62 | var stream = assemble.src('!*').pipe(add(globArray)); 63 | 64 | var files = []; 65 | stream.on('error', done); 66 | stream.on('data', function(file) { 67 | should.exist(file); 68 | should.exist(file.path); 69 | files.push(file); 70 | }); 71 | stream.on('end', function() { 72 | files.length.should.equal(1); 73 | files[0].path.should.equal(expectedPath); 74 | done(); 75 | }); 76 | }); 77 | 78 | it('should return a input stream with no contents when read is false', function(done) { 79 | var stream = assemble.src('!*').pipe(add(join(__dirname, "./fixtures/*.coffee"), {read: false})); 80 | stream.on('error', done); 81 | stream.on('data', function(file) { 82 | should.exist(file); 83 | should.exist(file.path); 84 | should.not.exist(file.contents); 85 | join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee")); 86 | }); 87 | stream.on('end', function() { 88 | done(); 89 | }); 90 | }); 91 | it('should return a input stream with contents as stream when buffer is false', function(done) { 92 | var stream = assemble.src('!*').pipe(add(join(__dirname, "./fixtures/*.coffee"), {buffer: false})); 93 | stream.on('error', done); 94 | stream.on('data', function(file) { 95 | should.exist(file); 96 | should.exist(file.path); 97 | should.exist(file.contents); 98 | var buf = ""; 99 | file.contents.on('data', function(d) { 100 | buf += d; 101 | }); 102 | file.contents.on('end', function() { 103 | buf.should.equal("this is a test"); 104 | done(); 105 | }); 106 | join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee")); 107 | }); 108 | }); 109 | it('should return a input stream from a deep glob', function(done) { 110 | var stream = assemble.src('!*').pipe(add(join(__dirname, "./fixtures/**/*.jade"))); 111 | stream.on('error', done); 112 | stream.on('data', function(file) { 113 | should.exist(file); 114 | should.exist(file.path); 115 | should.exist(file.contents); 116 | join(file.path,'').should.equal(join(__dirname, "./fixtures/test/run.jade")); 117 | String(file.contents).should.equal("test template"); 118 | }); 119 | stream.on('end', function() { 120 | done(); 121 | }); 122 | }); 123 | it('should return a input stream from a deeper glob', function(done) { 124 | var stream = assemble.src('!*').pipe(add(join(__dirname, "./fixtures/**/*.dmc"))); 125 | var a = 0; 126 | stream.on('error', done); 127 | stream.on('data', function() { 128 | ++a; 129 | }); 130 | stream.on('end', function() { 131 | a.should.equal(2); 132 | done(); 133 | }); 134 | }); 135 | 136 | it('should return a file stream from a flat path', function(done) { 137 | var a = 0; 138 | var stream = assemble.src('!*').pipe(add(join(__dirname, "./fixtures/test.coffee"))); 139 | stream.on('error', done); 140 | stream.on('data', function(file) { 141 | ++a; 142 | should.exist(file); 143 | should.exist(file.path); 144 | should.exist(file.contents); 145 | join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee")); 146 | String(file.contents).should.equal("this is a test"); 147 | }); 148 | stream.on('end', function() { 149 | a.should.equal(1); 150 | done(); 151 | }); 152 | }); 153 | }); 154 | }); 155 | --------------------------------------------------------------------------------