Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-contrib-jade

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-contrib-jade - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

test/expected/amd/jade.js

44

docs/jade-options.md

@@ -13,1 +13,45 @@ # Options

Sets the data passed to `jade` during template compilation. Any data can be passed to the template (including `grunt` templates).
## comileDebug
Type: `Boolean`
Set `compileDebug: fase` to remove `jade` debug instructions in javascript templates.
## namespace
Type: `String` `false`
Default: 'JST'
The namespace in which the precompiled templates will be assigned. *Use dot notation (e.g. App.Templates) for nested namespaces or false for no namespace wrapping.* When false with `amd` option set `true`, templates will be returned directly from the AMD wrapper.
Example:
```js
options: {
namespace: 'MyApp.Templates'
}
```
## amd
Type: `Boolean`
default: `false`
Wraps the output file with an AMD define function and returns the compiled template namespace unless namespace has been explicitly set to false in which case the template function will be returned directly.
```js
define(function() {
//...//
returns this['[template namespace]'];
});
```
## processName
Type: `function`
This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.
```js
options: {
processName: function(filename) {
return filename.toUpperCase();
}
}
```

@@ -46,2 +46,39 @@ /*

}
},
compile_amd: {
files: {
'tmp/amd/jade.js': ['test/fixtures/jade.jade'],
'tmp/amd/jade2.js': ['test/fixtures/jade2.jade'],
'tmp/amd/jadeInclude.js': ['test/fixtures/jadeInclude.jade'],
'tmp/amd/jadeTemplate.js': ['test/fixtures/jadeTemplate.jade']
},
options: {
client: true,
amd: true,
namespace: false,
compileDebug: false,
data: {
test: true,
year: '<%= grunt.template.today("yyyy") %>'
}
}
},
compile_jst: {
files: {
'tmp/jst/jade.js': ['test/fixtures/jade.jade'],
'tmp/jst/jade2.js': ['test/fixtures/jade2.jade'],
'tmp/jst/jadeInclude.js': ['test/fixtures/jadeInclude.jade'],
'tmp/jst/jadeTemplate.js': ['test/fixtures/jadeTemplate.jade']
},
options: {
client: true,
compileDebug: false,
processName: function(str) { return str.match(/^test\/fixtures\/(.*)\.jade$/)[1]; },
data: {
test: true,
year: '<%= grunt.template.today("yyyy") %>'
}
}
}

@@ -48,0 +85,0 @@ },

7

package.json
{
"name": "grunt-contrib-jade",
"description": "Compile Jade files to HTML.",
"version": "0.4.0",
"version": "0.5.0",
"homepage": "https://github.com/gruntjs/grunt-contrib-jade",

@@ -31,6 +31,7 @@ "author": {

"dependencies": {
"jade": "~0.27.2"
"jade": "~0.27.2",
"grunt-lib-contrib": "~0.5.1"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-jshint": "~0.2.0",
"grunt-contrib-nodeunit": "~0.1.2",

@@ -37,0 +38,0 @@ "grunt-contrib-clean": "~0.4.0",

@@ -16,3 +16,3 @@ # grunt-contrib-jade [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-jade.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-jade)

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

@@ -44,2 +44,45 @@ ```js

#### comileDebug
Type: `Boolean`
Set `compileDebug: fase` to remove `jade` debug instructions in javascript templates.
#### namespace
Type: `String` `false`
Default: 'JST'
The namespace in which the precompiled templates will be assigned. *Use dot notation (e.g. App.Templates) for nested namespaces or false for no namespace wrapping.* When false with `amd` option set `true`, templates will be returned directly from the AMD wrapper.
Example:
```js
options: {
namespace: 'MyApp.Templates'
}
```
#### amd
Type: `Boolean`
default: `false`
Wraps the output file with an AMD define function and returns the compiled template namespace unless namespace has been explicitly set to false in which case the template function will be returned directly.
```js
define(function() {
//...//
returns this['[template namespace]'];
});
```
#### processName
Type: `function`
This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.
```js
options: {
processName: function(filename) {
return filename.toUpperCase();
}
}
```
### Usage Examples

@@ -128,2 +171,3 @@

* 2013-03-06   v0.5.0   Allow compilation to JS functions Support JST and AMD formats
* 2013-02-14   v0.4.0   First official release for Grunt 0.4.0.

@@ -140,2 +184,2 @@ * 2013-01-23   v0.4.0rc7   Updating grunt/gruntplugin dependencies to rc7. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.

*This file was generated on Mon Feb 18 2013 08:40:02.*
*This file was generated on Thu Mar 07 2013 08:08:26.*

@@ -12,37 +12,112 @@ /*

module.exports = function(grunt) {
var _ = grunt.util._;
var helpers = require('grunt-lib-contrib').init(grunt);
grunt.registerMultiTask('jade', 'Compile Jade templates into HTML.', function() {
// content conversion for templates
var defaultProcessContent = function(content) { return content; };
// filename conversion for templates
var defaultProcessName = function(name) { return name.replace('.jade', ''); };
grunt.registerMultiTask('jade', 'Compile jade templates.', function() {
var options = this.options({
data: {}
namespace: 'JST',
separator: grunt.util.linefeed + grunt.util.linefeed,
amd: false
});
grunt.verbose.writeflags(options, 'Options');
var data = options.data;
delete options.data;
var nsInfo;
if(options.namespace !== false){
nsInfo = helpers.getNamespaceDeclaration(options.namespace);
}
// assign transformation functions
var processContent = options.processContent || defaultProcessContent;
var processName = options.processName || defaultProcessName;
this.files.forEach(function(f) {
var output = f.src.map(function(file) {
return compileJade(file, options, options.data);
}).join(grunt.util.normalizelf(grunt.util.linefeed));
var templates = [];
f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
})
.forEach(function(filepath) {
var src = processContent(grunt.file.read(filepath));
var compiled, filename;
filename = processName(filepath);
options = grunt.util._.extend(options, { filename: filepath });
try {
compiled = require('jade').compile(src, options);
// if in client mode, return function source
if (options.client) {
compiled = compiled.toString();
} else {
compiled = compiled(data);
}
// if configured for amd and the namespace has been explicitly set
// to false, the jade template will be directly returned
if (options.client && options.amd && options.namespace === false) {
compiled = 'return ' + compiled;
}
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('Jade failed to compile '+filepath+'.');
}
if (options.client && options.namespace !== false) {
templates.push(nsInfo.namespace+'['+JSON.stringify(filename)+'] = '+compiled+';');
} else {
templates.push(compiled);
}
});
var output = templates;
if (output.length < 1) {
grunt.log.warn('Destination not written because compiled files were empty.');
} else {
grunt.file.write(f.dest, output);
grunt.log.writeln('File ' + f.dest.cyan + ' created.');
if (options.client && options.namespace !== false) {
output.unshift(nsInfo.declaration);
if (options.node) {
output.unshift('var jade = jade || require(\'jade\').runtime;');
var nodeExport = 'if (typeof exports === \'object\' && exports) {';
nodeExport += 'module.exports = ' + nsInfo.namespace + ';}';
output.push(nodeExport);
}
}
if (options.amd) {
// Wrap the file in an AMD define fn.
output.unshift("define(['jade'], function(jade) { if(jade && jade['runtime'] !== undefined) { jade = jade.runtime; }");
if (options.namespace !== false) {
// Namespace has not been explicitly set to false; the AMD
// wrapper will return the object containing the template.
output.push("return "+nsInfo.namespace+";");
}
output.push("});");
}
grunt.file.write(f.dest, output.join(grunt.util.normalizelf(options.separator)));
grunt.log.writeln('File "' + f.dest + '" created.');
}
});
});
var compileJade = function(srcFile, options, data) {
options = grunt.util._.extend({filename: srcFile}, options);
delete options.data;
var srcCode = grunt.file.read(srcFile);
try {
return require('jade').compile(srcCode, options)(data);
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('Jade failed to compile.');
}
};
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc