Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 #120

Merged
merged 21 commits into from
Jan 4, 2018
Merged

v4 #120

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["env", { "targets": { "node": 4 } }]
["env", { "targets": { "node": 6 } }]
]
}
8 changes: 1 addition & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"extends": "airbnb-base",
"extends": ["airbnb-base", "prettier"],
"env": {
"node": true
},
"rules": {
"semi": 0,
"arrow-parens": 0,
"comma-dangle": 0,
"function-paren-newline": 0
}
}
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ cache:
notifications:
email: false
node_js:
- "8"
- "6"
- "4"
- "8"
before_install:
- if [[ `npm -v` != 5* ]]; then npm install -g npm@5; fi
- npm install -g greenkeeper-lockfile@1
Expand Down
107 changes: 43 additions & 64 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,141 +1,120 @@
3.0.1 - August 2, 2017
----------------------
### 4.0.0 - January 4, 2018
* breaking: dropped node 4 support
* breaking: the filename property is no longer set automatically, use https://github.com/MoOx/metalsmith-filenames
* removed metalsmith-engine-jstransformer for ease of maintenance

### 4.0.0-alpha.2 - October 7, 2017
* update metalsmith-engine-jstransformer to 1.0.0-alpha.2

### 4.0.0-alpha.1 - October 7, 2017
* update metalsmith-engine-jstransformer to 1.0.0-alpha.1

### 3.0.1 - August 2, 2017
* update metalsmith-engine-jstransformer to 0.1.2

3.0.0 - July 26, 2017
---------------------
### 3.0.0 - July 26, 2017
* dropped support for iojs and node 0.12
* allow arrays for pattern option as well

2.0.1 - January 1, 2017
-----------------------
### 2.0.1 - January 1, 2017
* correct publishing mistake

2.0.0 - January 1, 2017
-----------------------
### 2.0.0 - January 1, 2017
* abstract templating, allows user to choose which engine to use for rendering (breaking change)

2.0.0-beta.1 - September 11, 2016
-------------------------------
### 2.0.0-beta.1 - September 11, 2016
* switch to jstransformers for rendering (breaking change)

1.4.4 - May 3, 2016
-------------------
### 1.4.4 - May 3, 2016
* normalize partial name for windows

1.4.3 - February 11, 2016
-------------------------
### 1.4.3 - February 11, 2016
* add rename option
* prevent path issue on windows

1.3.3 - January 27, 2016
------------------------
### 1.3.3 - January 27, 2016
* update consolidate and lodash.omit

1.3.2 - October 17, 2015
------------------------
### 1.3.2 - October 17, 2015
* update fs-readdir-recursive

1.3.1 - August 6, 2015
----------------------
### 1.3.1 - August 6, 2015
* pass unrecognised `partials` options to consolidate

1.3.0 - August 6, 2015
----------------------
### 1.3.0 - August 6, 2015
* add swig include test
* add error handling for unrecognised engines
* code style, dependency and readme updates
* add partials option and test

1.2.1 - July 23, 2015
---------------------
### 1.2.1 - July 23, 2015
* update swig

1.2.0 - July 23, 2015
---------------------
### 1.2.0 - July 23, 2015
* update dependencies
* update and add badges

1.1.1 - July 20, 2015
---------------------
### 1.1.1 - July 20, 2015
* is-utf8 should be a dependency
* add eslint
* add release badge

1.1.0 - July 19, 2015
---------------------
### 1.1.0 - July 19, 2015
* update tests
* ignore binary files
* add travis ci and david dm badges to readme
* add gitattributes and editorconfig to repo

1.0.1 - November 22, 2014
-----------------------
### 1.0.1 - November 22, 2014
* change name to metalsmith-in-place

1.0.0 - November 18, 2014
-----------------------
### 1.0.0 - November 18, 2014
* render files in-place by default
* remove `default`, `directory` and `inPlace`

0.6.0 - October 3, 2014
-----------------------
### 0.6.0 - October 3, 2014
* fix to use `path` for metalsmith `1.0.0`

0.5.2 - July 9, 2014
--------------------
### 0.5.2 - July 9, 2014
* fix breaking binary files

0.5.1 - June 11, 2014
---------------------
### 0.5.1 - June 11, 2014
* fix race condition with stringify file contents

0.5.0 - April 29, 2014
----------------------
### 0.5.0 - April 29, 2014
* pass in options to consolidate.js

0.4.0 - April 2, 2014
---------------------
### 0.4.0 - April 2, 2014
* add `default` option

0.3.0 - March 10, 2014
----------------------
### 0.3.0 - March 10, 2014
* add `inPlace` option
* change `pattern` option to just filter

0.2.1 - March 10, 2014
----------------------
### 0.2.1 - March 10, 2014
* fix bug in matching pattern logic

0.2.0 - March 8, 2014
---------------------
### 0.2.0 - March 8, 2014
* add rendering files in place with a `pattern`

0.1.0 - March 5, 2014
---------------------
### 0.1.0 - March 5, 2014
* add `string` engine convenience

0.0.6 - February 7, 2014
------------------------
### 0.0.6 - February 7, 2014
* fix `directory` option bug

0.0.5 - February 7, 2014
------------------------
### 0.0.5 - February 7, 2014
* stringify `contents` on the original file data

0.0.4 - February 6, 2014
------------------------
### 0.0.4 - February 6, 2014
* switch to `extend` from `defaults` to avoid cloning
* add debug statements

0.0.3 - February 6, 2014
------------------------
### 0.0.3 - February 6, 2014
* fix to use buffers

0.0.2 - February 5, 2014
------------------------
### 0.0.2 - February 5, 2014
* mix in metadata

0.0.1 - February 4, 2014
------------------------
### 0.0.1 - February 4, 2014
:sparkles:
77 changes: 24 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

> A metalsmith plugin for rendering templates to html

This plugin allows you to render various templating languages to html. It uses
file extensions to infer which templating engine to use. So files ending in
`.md` will be processed as markdown, `.hbs` as handlebars, etc. You can even
chain transformations by appending multiple extensions, which will be processed
right-to-left.
This plugin allows you to render various templating languages to html. It uses file extensions to
infer which templating engine to use. So files ending in `.md` will be processed as markdown, `.hbs`
as handlebars, etc. You can even chain transformations by appending multiple extensions, which will
be processed right-to-left.

```
$ npm install metalsmith-in-place
Expand All @@ -23,9 +22,9 @@ For support questions please use [stack overflow][stackoverflow-url] or our

## Example

You can use `metalsmith-in-place` with metalsmith's [Javascript API](https://github.com/segmentio/metalsmith#api)
or the [CLI](https://github.com/segmentio/metalsmith#cli). For this example
we'll use the cli:
You can use `metalsmith-in-place` with metalsmith's
[Javascript API](https://github.com/segmentio/metalsmith#api) or the
[CLI](https://github.com/segmentio/metalsmith#cli). For this example we'll use the cli:

### 1. Install metalsmith and metalsmith-in-place:

Expand All @@ -35,16 +34,15 @@ $ npm install --save metalsmith metalsmith-in-place

### 2. Install appropriate jstransformers

Under the hood this plugin uses
[jstransformers](https://github.com/jstransformers/jstransformer)
to render your html. Since there are over a 100 jstransformers we don't install
them automatically, so you'll also need to install the appropriate
jstransformers.
Under the hood this plugin uses [jstransformers](https://github.com/jstransformers/jstransformer)
to render your html. Since there are over a 100 jstransformers we don't install them automatically,
so you'll also need to install the appropriate jstransformers.

For example, to render markdown you would install [jstransformer-markdown](https://github.com/jstransformers/jstransformer-markdown).
To render handlebars you would install [jstransformer-handlebars](https://github.com/jstransformers/jstransformer-handlebars).
See the [jstransformer organisation](https://github.com/jstransformers) for all
available jstransformers and [this dictionary](https://github.com/jstransformers/inputformat-to-jstransformer/blob/master/dictionary.json)
For example, to render markdown you would install [jstransformer-markdown](https://github.com/jstransformers/jstransformer-markdown). To render
handlebars you would install
[jstransformer-handlebars](https://github.com/jstransformers/jstransformer-handlebars). See the
[jstransformer organisation](https://github.com/jstransformers) for all available jstransformers and
[this dictionary](https://github.com/jstransformers/inputformat-to-jstransformer/blob/master/dictionary.json)
to see which extensions map to which jstransformer.

In this case we'll use handlebars, so we'll install jstransformer-handlebars:
Expand All @@ -55,8 +53,8 @@ $ npm install --save jstransformer-handlebars

### 3. Configure metalsmith

We'll create a metalsmith.json configuration file and a handlebars file for
metalsmith-in-place to process:
We'll create a metalsmith.json configuration file and a handlebars file for metalsmith-in-place to
process:

`./metalsmith.json`

Expand Down Expand Up @@ -99,17 +97,17 @@ Which will output the following file:

## Options

* `engineOptions`: optional. Use this to pass options to the jstransformer
that's rendering your templates. The default is `{}`.
* `engineOptions`: optional. Use this to pass options to the jstransformer that's rendering your
templates. The default is `{}`.

* `pattern`: optional. By default this plugin tries to process all files. If you
encounter problems use this option to filter. Only files that match this pattern
will be processed. Accepts a string or an array of strings. The default is `**`.
* `pattern`: optional. By default this plugin tries to process all files. If you encounter problems
use this option to filter. Only files that match this pattern will be processed. Accepts a string or
an array of strings. The default is `**`.

### `engineOptions`

Use this to pass options to the jstransformer that's rendering your templates.
So this `metalsmith.json`:
Use this to pass options to the jstransformer that's rendering your templates. So this
`metalsmith.json`:

```json
{
Expand Down Expand Up @@ -147,33 +145,6 @@ Would only process files within the `./src/blog` folder, because the pattern is
relative to your source folder. See [multimatch](https://github.com/sindresorhus/multimatch)
for further details.

## Options for developers of this plugin

These options are only for developers of this plugin. You don't need to touch
this for normal use, so only use this option if you know what you're doing.

* `engine`: optional. Select the engine that will be used for processing files.
The default is [metalsmith-engine-jstransformer](https://github.com/superwolff/metalsmith-engine-jstransformer),
but any compatible engine can be used. To select a different engine you must use
metalsmith's [Javascript API](https://github.com/segmentio/metalsmith#api) like
so:

```javascript
var metalsmith = require('metalsmith')
var inPlace = require('metalsmith-in-place')
var CustomEngine = require('./custom-engine')

metalsmith(__dirname)
.use(inPlace({
engine: CustomEngine
}))
.build(function(err){
if (err) throw err;
});
```

This would use the custom engine to process files.

## Credits

* [Ian Storm Taylor](https://github.com/ianstormtaylor) for creating [metalsmith-templates](https://github.com/segmentio/metalsmith-templates), on which this plugin was based
Expand Down
12 changes: 2 additions & 10 deletions lib/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`metalsmith-in-place should catch errors from the engine 1`] = `"Default error from ErrorEngine"`;
exports[`metalsmith-in-place should return an error for an invalid pattern 1`] = `"invalid pattern, the pattern option should be a string or array."`;

exports[`metalsmith-in-place should throw an error for an engine with an invalid render property 1`] = `"invalid engine, the render property should be a function."`;

exports[`metalsmith-in-place should throw an error for an engine without a render method 1`] = `"invalid engine, the engine instance should have a render method."`;

exports[`metalsmith-in-place should throw an error for an invalid engine 1`] = `"invalid engine, the engine should be a constructor."`;

exports[`metalsmith-in-place should throw an error for an invalid pattern 1`] = `"invalid pattern, the pattern option should be a string or array."`;

exports[`metalsmith-in-place should throw an error for invalid options 1`] = `"invalid options, this plugin expects a single options object."`;
exports[`metalsmith-in-place should return an error when there are no valid files to process 1`] = `"no files to process, check whether you have a jstransformer installed."`;
15 changes: 15 additions & 0 deletions lib/get-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const jstransformer = require('jstransformer')
const toTransformer = require('inputformat-to-jstransformer')

const cache = {}

module.exports = function getTransformer(ext) {
if (ext in cache) {
return cache[ext]
}

const transformer = toTransformer(ext)
cache[ext] = transformer ? jstransformer(transformer) : false

return cache[ext]
}
Loading