├── .travis.yml ├── .gitattributes ├── .gitignore ├── .jshintrc ├── utils.js ├── .editorconfig ├── test.js ├── .verb.md ├── LICENSE ├── package.json ├── index.js └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - "stable" 3 | - "0.10" 4 | - "0.12" 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.sublime-* 3 | _gh_pages 4 | bower_components 5 | node_modules 6 | npm-debug.log 7 | actual 8 | test/actual 9 | temp 10 | tmp 11 | TODO.md 12 | vendor 13 | .idea 14 | benchmark 15 | coverage 16 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": false, 3 | "boss": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "eqnull": true, 7 | "esnext": true, 8 | "immed": true, 9 | "latedef": false, 10 | "laxcomma": false, 11 | "mocha": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "node": true, 15 | "sub": true, 16 | "undef": true, 17 | "unused": true 18 | } 19 | -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Lazily required module dependencies 5 | */ 6 | 7 | var utils = require('lazy-cache')(require); 8 | 9 | /** 10 | * Trick browserify into recognizing lazy-cached modules 11 | */ 12 | 13 | var fn = require; 14 | require = utils; 15 | require('is-regex'); 16 | require('mixin-deep', 'merge'); 17 | require('emitter-only', 'only'); 18 | require = fn; 19 | 20 | /** 21 | * Expose utils 22 | */ 23 | 24 | module.exports = utils; 25 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | 16 | [{,test/}{actual,fixtures}/**] 17 | trim_trailing_whitespace = false 18 | insert_final_newline = false 19 | 20 | [templates/**] 21 | trim_trailing_whitespace = false 22 | insert_final_newline = false 23 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var path = require('path'); 5 | var assert = require('assert'); 6 | var App = require('templates'); 7 | var reloadViews = require('./'); 8 | var app; 9 | 10 | describe('reloadViews()', function() { 11 | beforeEach(function () { 12 | app = new App(); 13 | app.use(reloadViews()); 14 | }); 15 | 16 | it('should reload a collection when options are defined', function () { 17 | app.create('pages', {cwd: 'foo/bar'}); 18 | app.page('a.html', {content: '...'}); 19 | 20 | assert(app.pages); 21 | assert(app.pages.options); 22 | assert(app.pages.options.cwd === 'foo/bar'); 23 | app.option('cwd', 'a/b/c'); 24 | assert(app.pages.options.cwd === 'a/b/c'); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | # {%= name %} {%= badge("fury") %} 2 | 3 | > {%= description %} 4 | 5 | ## Install 6 | {%= include("install-npm", {save: true}) %} 7 | 8 | ## Usage 9 | 10 | This initializes event listeners to listen for events that indicate if something needs to be re-initialized based on user options. The result is that views are reloaded whenever settings are changed. 11 | 12 | ```js 13 | var reloadViews = require('{%= name %}'); 14 | var assemble = require('assemble'); 15 | 16 | var app = assemble(); 17 | app.use(reloadViews()); 18 | ``` 19 | 20 | ## Related projects 21 | {%= related(verb.related.list) %} 22 | 23 | ## Running tests 24 | {%= include("tests") %} 25 | 26 | ## Contributing 27 | {%= include("contributing") %} 28 | 29 | ## Author 30 | {%= include("author") %} 31 | 32 | ## License 33 | {%= copyright() %} 34 | {%= license() %} 35 | 36 | *** 37 | 38 | {%= include("footer") %} 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "assemble-reload-views", 3 | "description": "Assemble instance plugin that reloads views when options are updated or when another plugin is loaded.", 4 | "version": "0.1.1", 5 | "homepage": "https://github.com/jonschlinkert/assemble-reload-views", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/assemble-reload-views", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/assemble-reload-views/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js", 14 | "utils.js" 15 | ], 16 | "main": "index.js", 17 | "engines": { 18 | "node": ">=0.10.0" 19 | }, 20 | "scripts": { 21 | "test": "mocha" 22 | }, 23 | "dependencies": { 24 | "emitter-only": "^0.1.0", 25 | "is-regex": "^1.0.3", 26 | "lazy-cache": "^0.2.3", 27 | "mixin-deep": "^1.1.3" 28 | }, 29 | "devDependencies": { 30 | "mocha": "*", 31 | "templates": "^0.3.1" 32 | }, 33 | "keywords": [ 34 | "assembleplugin", 35 | "plugin" 36 | ], 37 | "verb": { 38 | "related": { 39 | "list": [ 40 | "assemble-render-file", 41 | "assemble-streams", 42 | "assemble-loader", 43 | "assemble" 44 | ] 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * assemble-reload-views 3 | * 4 | * Copyright (c) 2015, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var utils = require('./utils'); 11 | 12 | /** 13 | * reload view collections when plugins are loaded 14 | * or options are defined by the user. 15 | */ 16 | 17 | module.exports = function (pattern) { 18 | return function (app) { 19 | if (!this.only) { 20 | this.mixin('only', utils.only.bind(this)); 21 | } 22 | 23 | this.only('reloadViews', 'option', function (key) { 24 | if (isMatch(pattern)(key)) { 25 | reloadViews(app, key); 26 | } 27 | }); 28 | 29 | this.only('reloadViews', 'use', function () { 30 | reloadViews(app); 31 | }); 32 | }; 33 | }; 34 | 35 | function reloadViews(app, key) { 36 | for (var name in app.views) { 37 | if (app.views.hasOwnProperty(name)) { 38 | var views = app.views[name]; 39 | 40 | if (!key || typeof app[name][key] !== 'function') { 41 | app.create(name, utils.merge({}, app[name].options, app.options)); 42 | app[name].addViews(views); 43 | } 44 | } 45 | } 46 | } 47 | 48 | function isMatch(val) { 49 | if (Array.isArray(val)) { 50 | return function (key) { 51 | return val.indexOf(key) !== -1; 52 | }; 53 | } 54 | 55 | if (utils.isRegex(val)) { 56 | return function (key) { 57 | return val.test(key); 58 | }; 59 | } 60 | 61 | return function noop() { 62 | return true; 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # assemble-reload-views [![NPM version](https://badge.fury.io/js/assemble-reload-views.svg)](http://badge.fury.io/js/assemble-reload-views) 2 | 3 | > Assemble instance plugin that reloads views when options are updated or when another plugin is loaded. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/) 8 | 9 | ```sh 10 | $ npm i assemble-reload-views --save 11 | ``` 12 | 13 | ## Usage 14 | 15 | This initializes event listeners to listen for events that indicate if something needs to be re-initialized based on user options. The result is that views are reloaded whenever settings are changed. 16 | 17 | ```js 18 | var reloadViews = require('assemble-reload-views'); 19 | var assemble = require('assemble'); 20 | 21 | var app = assemble(); 22 | app.use(reloadViews()); 23 | ``` 24 | 25 | ## Related projects 26 | 27 | * [assemble](https://www.npmjs.com/package/assemble): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… [more](https://www.npmjs.com/package/assemble) | [homepage](http://assemble.io) 28 | * [assemble-loader](https://www.npmjs.com/package/assemble-loader): Assemble plugin (0.6+) for loading globs of views onto custom view collections. Also works with… [more](https://www.npmjs.com/package/assemble-loader) | [homepage](https://github.com/jonschlinkert/assemble-loader) 29 | * [assemble-render-file](https://www.npmjs.com/package/assemble-render-file): Assemble plugin for rendering views in a vinyl pipeline. | [homepage](https://github.com/jonschlinkert/assemble-render-file) 30 | * [assemble-streams](https://www.npmjs.com/package/assemble-streams): Assemble plugin that adds convenience methods for working with streams, like `toStream`, which pushes a… [more](https://www.npmjs.com/package/assemble-streams) | [homepage](https://github.com/jonschlinkert/assemble-streams) 31 | 32 | ## Running tests 33 | 34 | Install dev dependencies: 35 | 36 | ```sh 37 | $ npm i -d && npm test 38 | ``` 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/assemble-reload-views/issues/new). 43 | 44 | ## Author 45 | 46 | **Jon Schlinkert** 47 | 48 | + [github/jonschlinkert](https://github.com/jonschlinkert) 49 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 50 | 51 | ## License 52 | 53 | Copyright © 2015 Jon Schlinkert 54 | Released under the MIT license. 55 | 56 | *** 57 | 58 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 10, 2015._ --------------------------------------------------------------------------------