baucis-decorator-file
Advanced tools
Comparing version 1.0.0 to 1.0.1
10
index.js
@@ -34,5 +34,3 @@ 'use strict'; | ||
'/:name.:id.'+actualKey, | ||
'/:id.'+actualKey, | ||
'/eval/:name.:id.'+actualKey, // bit of a hack here to allow ES6 | ||
'/eval/:id.'+actualKey // polyfill to "hide" eval'd code | ||
'/:id.'+actualKey | ||
]; | ||
@@ -111,3 +109,5 @@ | ||
.join(''); | ||
// TODO: add some `field` that might specify default? | ||
var defaults = { | ||
@@ -132,2 +132,2 @@ jsx: "import React from 'react';\n" | ||
return defaults[key] || ''; | ||
} | ||
} |
{ | ||
"name": "baucis-decorator-file", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Allows properties to be exposed as files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# baucis-decorator-file | ||
Allows properties to be exposed as files. | ||
## Install | ||
``` | ||
npm install baucis-decorators baucis-decorator-file --save | ||
``` | ||
## Usage | ||
Add the decorator and it will add the functionality to any properties containing a `file` field set to some `mime-type`. For the following example, you could GET the `jsx` as a file via something like `/api/components/123.jsx` or `/api/components/my-component.123.jsx`. | ||
## Example | ||
`controllers/Component.js` | ||
```js | ||
var baucis = require('baucis'); | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
var extend = require('deep-extend'); | ||
var ResourceProps = require('../props/Resource.js'); | ||
var ResourceController = require('../controllers/Resource.js'); | ||
var ComponentProps = extend({}, ResourceProps); | ||
ComponentProps.jsx = { | ||
type: String, | ||
file: 'text/jsx' | ||
}; | ||
var ComponentSchema = new Schema(ComponentProps); | ||
var ComponentModel = mongoose.model('Component', ComponentSchema); | ||
var ComponentController = baucis.rest('Component'); | ||
var decorators = require('baucis-decorators'); | ||
// decorate controller | ||
decorators.add.call(ComponentController, [ | ||
'baucis-decorator-file', // checks each property for any `file` fields and adds functionality accordingly | ||
ResourceController // `ComponentController` will inherit all of `ResourceController`'s decorators | ||
]); | ||
/** | ||
* Expose controller. | ||
*/ | ||
module.exports = ComponentController; |
7002
6
46