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

grunt-bake

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-bake - npm Package Compare versions

Comparing version 0.3.17 to 0.3.18

test/expected/transform_deep.html

78

Gruntfile.js

@@ -67,2 +67,3 @@ /*

bake: {
default_bake: {

@@ -257,3 +258,78 @@ files: {

}
}
},
transform_pass_through: {
options: {
content: {
content: "Hallo Welt!"
},
transforms: {
noop: function(str) {
return str
}
}
},
files: {
"tmp/transform_pass_through.html": "test/fixtures/transform_pass_through.html"
}
},
transform_single: {
options: {
content: {
content: "Hallo Welt!"
},
transforms: {
upper: function(str) {
return String(str).toUpperCase();
}
}
},
files: {
"tmp/transform_single.html": "test/fixtures/transform_single.html"
}
},
transform_multiple: {
options: {
content: {
content: "Hallo\nWelt!"
},
transforms: {
nl2br: function(str) {
return String(str).replace(/([\r\n]+)/g, '<br />');
},
upper: function(str) {
return String(str).toUpperCase();
}
}
},
files: {
"tmp/transform_multiple.html": "test/fixtures/transform_multiple.html"
}
},
transform_deep: {
options: {
content: {
sub: {
sub: {
content: "Hallo Welt!"
}
}
},
transforms: {
upper: function(str) {
return String(str).toUpperCase();
}
}
},
files: {
"tmp/transform_deep.html": "test/fixtures/transform_deep.html"
}
},
}

@@ -260,0 +336,0 @@

{
"name": "grunt-bake",
"description": "Bake external includes into files to create static pages with no server-side compilation time",
"version": "0.3.17",
"version": "0.3.18",
"homepage": "https://github.com/MathiasPaumgarten/grunt-bake",

@@ -11,2 +11,12 @@ "author": {

},
"contributors": [
{
"name": "David Zacharias",
"url": "https://github.com/david-zacharias"
},
{
"name": "Paul Huizer",
"url": "https://github.com/PaulHuizer"
}
],
"repository": {

@@ -13,0 +23,0 @@ "type": "git",

@@ -152,2 +152,26 @@ # grunt-bake

#### options.transforms
Type: `Object`
Default value: {}
Registers callbacks that can be used as transforms in the template with `{{myvar | upper}}`. It is possible to chain transforms like `{{myvar | upper | nl2br}}`.
```js
transforms: {
upper: function(str) {
return String(str).toUpperCase();
},
nl2br: function(str) {
// ...
}
}
```
#### options.transformGutter
Type: `String`
Default value: '|'
Sequence used to split transforms.
#### options.semanticIf

@@ -154,0 +178,0 @@ Type: `Bool` | `Array` | `Function`

@@ -28,3 +28,5 @@ /*

basePath: "",
parsePattern: /\{\{\s*([\.\-\w]*)\s*\}\}/g
transforms: {},
parsePattern: /\{\{\s*([^\}]+)\s*\}\}/g,
transformGutter: "|"
} );

@@ -42,6 +44,15 @@

// This process method is used when no process function is supplied.
function defaultProcess( template, content ) {
return template.replace( options.parsePattern, function( match, inner ) {
function defaultProcess( template, content ) {
return template.replace( options.parsePattern, function( match, key ) {
return resolveName( key, content );
// remove whitespace
var transforms = inner.split( options.transformGutter ).map( function( str ) {
return mout.string.trim( str );
});
// the first value is our variable key and not a transfrom
var key = transforms.shift();
var resolved = resolveName( key, content );
return transforms.reduce( applyTransform, resolved );
} );

@@ -54,2 +65,21 @@ }

function applyTransform( content, transform ) {
// check if transform is registred
if( ! mout.object.has( options.transforms, transform ) ) {
grunt.log.error( "Unknown transform: " + transform );
return content;
}
// check if transform is valid callback
if( ! mout.lang.isFunction( options.transforms[transform] ) ) {
grunt.log.error( "Transform is not a function: " + transform );
return content;
}
// apply transform
return options.transforms[transform].call( null, content );
}
// ===========

@@ -56,0 +86,0 @@ // -- UTILS --

@@ -27,3 +27,7 @@ "use strict";

"tmp/html_include_bake.html": "test/expected/html_include_bake.html",
"tmp/function_content_bake.html": "test/expected/function_content_bake.html"
"tmp/function_content_bake.html": "test/expected/function_content_bake.html",
"tmp/transform_pass_through.html": "test/expected/transform_pass_through.html",
"tmp/transform_single.html": "test/expected/transform_single.html",
"tmp/transform_multiple.html": "test/expected/transform_multiple.html",
"tmp/transform_deep.html": "test/expected/transform_deep.html"
};

@@ -30,0 +34,0 @@

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