grunt-yate
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -33,17 +33,14 @@ /* | ||
yate: { | ||
sample: { | ||
simple: { | ||
files: { | ||
'tmp/hello.js': 'test/fixtures/hello.yate' | ||
'tmp/simple.js': 'test/fixtures/simple.yate' | ||
} | ||
}, | ||
oneToOne: { | ||
files: [ | ||
{ | ||
src: [ 'test/fixtures/multiple/*.yate' ], | ||
dest: 'tmp/', | ||
ext: '.js', | ||
flatten: true, | ||
expand: true | ||
} | ||
] | ||
autorun: { | ||
options: { | ||
autorun: true | ||
}, | ||
files: { | ||
'tmp/autorun.js': 'test/fixtures/autorun.yate' | ||
} | ||
} | ||
@@ -50,0 +47,0 @@ }, |
{ | ||
"name": "grunt-yate", | ||
"description": "Yate compiler plugin", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"homepage": "https://github.com/lapple/grunt-yate", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -40,18 +40,19 @@ # grunt-yate | ||
#### options.iife | ||
Type: `Boolean` | ||
Default value: `true` | ||
Wrap the compiled templates into [IIFE](http://benalman.com/news/2010/11/immediately-invoked-function-expression/). | ||
#### options.runtime | ||
Type: `Boolean` | ||
Default value: `true` | ||
Default value: `false` | ||
Prepend destination file with `runtime.js` library from [yate](https://github.com/pasaran/yate). | ||
#### options.autorun | ||
Type: `Boolean|String` | ||
Default value: `false` | ||
Create autorunning templates. Pass `true` to automatically run `main` module. Pass | ||
a module title to autorun specific module. | ||
#### options.postprocess | ||
Type: `Function` | ||
Define compiled code transformations. For instance, one can create autorunning templates: | ||
Define compiled code transformation or extension. | ||
@@ -63,4 +64,4 @@ ```javascript | ||
postprocess: function(code) { | ||
// Autorun the `main` module. | ||
return code + '\nreturn function(data) { return yr.run("main", data); };'; | ||
// Example: augment particular strings at compile time: | ||
return code.replace('{time}', Date.now()); | ||
} | ||
@@ -75,5 +76,2 @@ } | ||
When using default options each destination file is wrapped into IIFE | ||
and prepended by `runtime.js`. | ||
Compile single file: | ||
@@ -80,0 +78,0 @@ |
@@ -21,5 +21,5 @@ /* | ||
var options = this.options({ | ||
runtime: true, | ||
iife: true, | ||
runtime: false, | ||
autorun: false, | ||
// Default no-op postprocess function. Use `postprocess` | ||
@@ -51,3 +51,2 @@ // to define custom compiled code transformations. | ||
src = options.postprocess(src); | ||
@@ -58,6 +57,8 @@ if (options.runtime) { | ||
if (options.iife) { | ||
src = iife(src); | ||
if (options.autorun) { | ||
src = autorun(src, options.autorun); | ||
} | ||
src = options.postprocess(src); | ||
// Write the destination file. | ||
@@ -75,2 +76,8 @@ grunt.file.write(f.dest, src); | ||
function autorun(code, module) { | ||
var main = typeof module === 'string' ? module : 'main'; | ||
return iife(code + '\nreturn function(data) { return yr.run("' + main + '", data); };'); | ||
} | ||
function iife(code) { | ||
@@ -77,0 +84,0 @@ return '(function(){\n' + code + '\n})()\n'; |
@@ -30,11 +30,20 @@ 'use strict'; | ||
}, | ||
hello: function(test) { | ||
simple: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/hello.js'); | ||
var expected = grunt.file.read('test/expected/hello.js'); | ||
var actual = grunt.file.read('tmp/simple.js').trim(); | ||
var expected = grunt.file.read('test/expected/simple.js').trim(); | ||
test.equal(actual, expected); | ||
test.done(); | ||
}, | ||
autorun: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/autorun.js').trim(); | ||
var expected = grunt.file.read('test/expected/autorun.js').trim(); | ||
test.equal(actual, expected); | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
12832
276
116
1