grunt-yaml
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -49,3 +49,3 @@ /* | ||
'!include': function (node, yaml) { | ||
var data = require('fs').readFileSync(node.value, 'utf-8'); | ||
var data = grunt.file.read(node.value, 'utf-8'); | ||
return yaml.load(data); | ||
@@ -58,2 +58,15 @@ } | ||
] | ||
}, | ||
middleware_options: { | ||
options: { | ||
disableDest: true, | ||
middleware: function(response, json){ | ||
var fs = require('fs'); | ||
grunt.file.write('tmp/middleware_options/response.json', JSON.stringify(response)); | ||
grunt.file.write('tmp/middleware_options/json.json', json); | ||
} | ||
}, | ||
files: { | ||
'tmp/middleware_options/middleware.json': ['test/fixtures/middleware.yml'] | ||
} | ||
} | ||
@@ -60,0 +73,0 @@ }, |
{ | ||
"name": "grunt-yaml", | ||
"description": "Compiles YAML to JSON.", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"homepage": "https://github.com/shiwano/grunt-yaml", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -1,2 +0,2 @@ | ||
# grunt-yaml | ||
# grunt-yaml [![Build Status](https://secure.travis-ci.org/shiwano/grunt-yaml.png?branch=master)](http://travis-ci.org/shiwano/grunt-yaml) | ||
@@ -40,3 +40,3 @@ > Compiles YAML to JSON. | ||
'!include': function (node, yaml) { | ||
var data = require('fs').readFileSync(node.value, 'utf-8'); | ||
var data = grunt.file.read(node.value, 'utf-8'); | ||
return yaml.load(data); | ||
@@ -53,3 +53,24 @@ } | ||
``` | ||
In a situation where you do not want to output a file, but want to manipulate the data on your own, you can provide a middleware function and disable the destination write process: | ||
```js | ||
grunt.initConfig({ | ||
yaml: { | ||
your_target: { | ||
options: { | ||
disableDest: true, // Grunt will not create a config.json as per the destination of the files object | ||
middleware: function(response, json){ | ||
console.log(response); // YAML data | ||
console.log(json); // Stringified JSON | ||
}, | ||
space: 4 | ||
}, | ||
files: { | ||
'config.json': ['config.yml'] | ||
} | ||
}, | ||
}, | ||
}) | ||
``` | ||
### Options | ||
@@ -61,3 +82,3 @@ | ||
A value that specify file pattern to not compile. | ||
A value that specifies file pattern not to compile. | ||
@@ -76,2 +97,14 @@ #### options.space | ||
#### options.middleware | ||
Type: 'function' | ||
Default value: 'function(response, json){}' | ||
A function which provides you an interface to manipulate the YAML before it becomes JSON, or manipulate the JSON after being stringified. | ||
#### options.disableDest | ||
Type: 'Boolean' | ||
Default: 'false' | ||
A boolean flag which will prevent grunt-yaml from creating an output file if you would like to just work with the middleware function. | ||
### Usage Examples | ||
@@ -85,2 +118,3 @@ | ||
## Release History | ||
* 2013-06-26 v0.2.1 Add `middleware` and `disableDest` options. | ||
* 2013-05-10 v0.2.0 Use `files` format. | ||
@@ -87,0 +121,0 @@ * 2013-04-14 v0.1.2 Support for grunt 0.4.0. |
@@ -20,3 +20,5 @@ /* | ||
ignored: null, | ||
space: 2 | ||
space: 2, | ||
middleware: function(){}, | ||
disableDest: false | ||
}); | ||
@@ -44,4 +46,9 @@ var taskDone = this.async(); | ||
var json = JSON.stringify(result, null, options.space); | ||
grunt.file.write(dest, json); | ||
grunt.log.writeln('Compiled ' + src.cyan + ' -> ' + dest.cyan); | ||
if(typeof options.middleware === 'function'){ | ||
options.middleware(result, json); | ||
} | ||
if(!options.disableDest){ | ||
grunt.file.write(dest, json); | ||
grunt.log.writeln('Compiled ' + src.cyan + ' -> ' + dest.cyan); | ||
} | ||
done(); | ||
@@ -48,0 +55,0 @@ }); |
@@ -50,4 +50,18 @@ 'use strict'; | ||
test.done(); | ||
}, | ||
middleware_options: function(test) { | ||
test.ok(fs.existsSync('tmp/middleware_options/middleware.json') === false, 'Enabled disableDest option.'); | ||
var actual = grunt.file.read('tmp/middleware_options/response.json'); | ||
var expected = grunt.file.read('test/expected/middleware_options/response.json'); | ||
test.equal(actual, expected, 'Enabled middleware option.'); | ||
actual = grunt.file.read('tmp/middleware_options/json.json'); | ||
expected = grunt.file.read('test/expected/middleware_options/json.json'); | ||
test.equal(actual, expected, 'Enabled middleware option.'); | ||
test.done(); | ||
} | ||
}; | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14986
22
276
123