Skip to content

Commit

Permalink
added plop.load documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
amwmedia committed Nov 18, 2016
1 parent ae42926 commit 587060a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ module.exports = function (plop) {
# Other Plop Methods/Attributes
These methods and attributes are available off the `plop` object. They are mostly used by plop internally, but some can come in handy when you're doing something a little more custom.

#### plop.load(targets, [config], [include]) - [see details](plop-load.md)
- targets {String | Array<String>}
- config {Object}
- include {Object}

loads generators, helpers and/or partials from another plopfile or npm module

#### plop.renderString(template, data)
- template {String}
- data {Object}
Expand All @@ -192,7 +199,7 @@ Gets a generator config object by name.
#### plop.getGeneratorList()
Gets an array of generator names and descriptions.

#### plop.getPlopfilePath
#### plop.getPlopfilePath()
Returns the absolute path to the plopfile in use.

#### plop.inquirer
Expand Down
76 changes: 76 additions & 0 deletions plop-load.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
plop.load
=========

`plop.load` can be used to load generators, helpers, and partials from a other plopfiles that are in your project or on NPM (`plop-pack`). Example code below.

### plop.load([targets](#targets), [[config](#config)], [[include](#include)])

#### targets
- **type:** `String` or `Array<String>`
- **required**

`targets` is the location or locations of the plopfile(s) to be loaded. These locations can be file paths (absolute or relative to the current plopfile) or the node module name of the `plop-pack` that should be loaded.

#### config
- **type:** `Object`
- **optional**

`config` is an object that can be passed to the plopfile or `plop-pack` when they are run. This allows the consumer of the plopfile or `plop-pack` to configure certain aspects of its functionality. To know what properties should be in this object, see the documentation provided by the author.

#### include
- **type:** `Object`
- **default:** `{ generators:true, helpers:false, partials:false }`
- **optional**

`include` is an object that can contain 3 properties (`generators`, `helpers` and `partials`). Each of these properties should have an [`IncludeDefinition`](#IncludeDefinition) as its value. Most of the time this object is not needed because the plopfile or `plop-pack` is able to specify a default [`IncludeDefinition`](#IncludeDefinition) to be used.

#### Interface `IncludeDefinition`
- **Boolean:** `true` will include all assets, `false` will include non of them.
- **Array:** a list of asset names that should be included. any assets that don't match a name in this list will be skipped.
- **Object:** the include object allows the consumer to rename assets when for use in their own plopfile. the property name in this object is the asset name, the value is the name that will be given to the asset when loaded.

## Examples
*load via a path*
```javascript
// loads all 5 generators, no helpers or partials (even if they exist)
plop.load('./plopfiles/component.js');
```
*load via a path with a custom include config*
```javascript
// loads all helpers, no generators or partials (even if they exist)
plop.load('./plopfiles/component.js', {}, { helpers: true });
```
*load via a path with a limited include*
```javascript
// loads only the "header" helper, no generators or partials (even if they exist)
plop.load('./plopfiles/component.js', {}, { helpers: ['header'] });
```
*load via a path with config object*
```javascript
// the component.js module will receive the config object and do something
// example: it could use it to alter which templates it will use (es6)
// and prefix all generator names with 'foo'
plop.load('./plopfiles/component.js', { es6: true, namePrefix: 'foo' });
```
*load via [npm module](https://www.npmjs.com/package/plop-pack-fancy-comments)*
> this module [configures a default include definition](https://github.com/amwmedia/plop-pack-fancy-comments/blob/master/index.js#L13)
```javascript
// loads all 3 helpers
plop.load('plop-pack-fancy-comments');
};
```
*load via npm module with a renaming include config*
```javascript
// loads only the header helper, no generators or partials (even if they exist)
// within the plopfile and templates, the "header" helper is referenced as "title"
plop.load('plop-pack-fancy-comments', {}, { helpers: {'js-header': 'titleComment'} });
```
*load via npm module AND path*
```javascript
// uses the default include config for each item
plop.load([
'plop-pack-fancy-comments',
'./plopfiles/component.js'
]);
```

0 comments on commit 587060a

Please sign in to comment.