grunt-yate
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "grunt-yate", | ||
"description": "Yate compiler plugin", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/lapple/grunt-yate", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -16,3 +16,3 @@ # grunt-yate | ||
```js | ||
```javascript | ||
grunt.loadNpmTasks('grunt-yate'); | ||
@@ -26,3 +26,3 @@ ``` | ||
```js | ||
```javascript | ||
grunt.initConfig({ | ||
@@ -52,12 +52,31 @@ yate: { | ||
Prepend destination file with `lib/runtime.js` library from Yate. | ||
Prepend destination file with `runtime.js` library from [yate](https://github.com/pasaran/yate). | ||
#### options.postprocess | ||
Type: `Function` | ||
Define compiled code transformations. For instance, one can create autorunning templates: | ||
```javascript | ||
grunt.initConfig({ | ||
yate: { | ||
options: { | ||
postprocess: function(code) { | ||
// Autorun the `main` module. | ||
return code + '\nreturn function(data) { return yr.run("main", data); };'; | ||
} | ||
} | ||
// ... | ||
} | ||
}); | ||
``` | ||
### Usage Examples | ||
When using default options all destination files will be wrapped into IIFE and each will | ||
be prepended by `lib/runtime.js` from Yate. | ||
When using default options each destination file is wrapped into IIFE | ||
and prepended by `runtime.js`. | ||
Compile single file: | ||
```js | ||
```javascript | ||
grunt.initConfig({ | ||
@@ -68,4 +87,4 @@ yate: { | ||
'templates/compiled/index.js': [ | ||
'templates/src/index.js', | ||
'templates/src/blocks/*.js' | ||
'templates/src/index.yate', | ||
'templates/src/blocks/*.yate' | ||
] | ||
@@ -77,5 +96,5 @@ } | ||
Compile multiple files, using one to one mapping: | ||
Compile multiple files, using one-to-one mapping: | ||
```js | ||
```javascript | ||
grunt.initConfig({ | ||
@@ -82,0 +101,0 @@ yate: { |
@@ -19,6 +19,12 @@ /* | ||
grunt.registerMultiTask('yate', 'Yate compiler plugin', function() { | ||
// Merge task-specific and/or target-specific options with these defaults. | ||
var options = this.options({ | ||
runtime: true, | ||
iife: true | ||
iife: true, | ||
// Default no-op postprocess function. Use `postprocess` | ||
// to define custom compiled code transformations. | ||
postprocess: function(code) { | ||
return code; | ||
} | ||
}); | ||
@@ -28,2 +34,3 @@ | ||
this.files.forEach(function(f) { | ||
// Building compiled templates. | ||
@@ -45,3 +52,3 @@ var src = f.src.filter(function(filepath) { | ||
src = autorun(src); | ||
src = options.postprocess(src); | ||
@@ -65,3 +72,3 @@ if (options.runtime) { | ||
function runtime(code) { | ||
return grunt.file.read(path.resolve(yateFolder, 'runtime.js')) + '\n' + code; | ||
return grunt.file.read(path.join(yateFolder, 'runtime.js')) + '\n' + code; | ||
} | ||
@@ -73,6 +80,2 @@ | ||
function autorun(code) { | ||
return code + '\nreturn function(data) { return yr.run("main", data); };'; | ||
} | ||
}; |
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
36119
882
118