provide docuri object in strformat placeholders

Closes #18
pull/20/head
Johannes J. Schmidt 11 years ago
parent d30350fae3
commit b73fc748f5

@ -97,9 +97,15 @@ Content-Type of the resulting attachment. Default is `image/jpeg`.
### `id`
The document id where the version is stored. Defaults to `{id}/{version}`.
Can have the following placeholders:
Can have the following [strformat placeholders](https://github.com/fhellwig/strformat):
* `id` - the original doc id
* `parts` - array of the id splitted at `/`
* `docuri` - [docuri](https://github.com/jo/docuri) parsed id object:
* `docuri.type` - index part of docuri
* `docuri.id` - id part of docuri
* `docuri.subtype` - subtype part of docuri
* `docuri.version` - version part of docuri
* `docuri.index` - index part of docuri
* `version` - name of the version
### `name`
@ -108,6 +114,12 @@ The attachment name of the version. Default is `{basename}-{version}{extname}`.
Can have placeholders:
* `id` - the original doc id
* `parts` - array of the id splitted at `/`
* `docuri` - [docuri](https://github.com/jo/docuri) parsed id object:
* `docuri.type` - index part of docuri
* `docuri.id` - id part of docuri
* `docuri.subtype` - subtype part of docuri
* `docuri.version` - version part of docuri
* `docuri.index` - index part of docuri
* `version` - name of the version
* `name` - original attachment name, eg `this/is/my-image.jpg`
* `extname` - file extenstion of the original attachment name, eg `.jpg`

@ -9,6 +9,7 @@ var _ = require('highland');
var async = require('async');
var nano = require('nano');
var strformat = require('strformat');
var docuri = require('docuri');
// TODO: emit all documents, also filtered one, to enable checkpointing
@ -256,11 +257,13 @@ module.exports = function couchmagick(url, options) {
// construct target doc
var id = strformat(version.id, {
id: data.doc._id,
docuri: docuri.parse(data.doc._id),
parts: data.doc._id.split('/'),
version: key
});
var name = strformat(version.name, {
id: data.doc._id,
docuri: docuri.parse(data.doc._id),
parts: data.doc._id.split('/'),
version: key,

@ -1,6 +1,6 @@
{
"name": "couchmagick",
"version": "2.0.0",
"version": "2.1.0",
"description": "Run ImageMagicks `convert` on CouchDB documents.",
"main": "index.js",
"preferGlobal": true,

Loading…
Cancel
Save