From b73fc748f54dcd987eeeddeb31d282aa1430182b Mon Sep 17 00:00:00 2001 From: "Johannes J. Schmidt" Date: Wed, 21 May 2014 11:54:04 +0200 Subject: [PATCH] provide docuri object in strformat placeholders Closes #18 --- README.md | 14 +++++++++++++- lib/couchmagick-stream.js | 3 +++ package.json | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3212a4..400e88a 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/couchmagick-stream.js b/lib/couchmagick-stream.js index c70bfa4..16e73bf 100644 --- a/lib/couchmagick-stream.js +++ b/lib/couchmagick-stream.js @@ -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, diff --git a/package.json b/package.json index 6c6479e..9a5b42d 100644 --- a/package.json +++ b/package.json @@ -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,