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.2.1 to 0.3.0

.travis.yml

11

Gruntfile.js

@@ -130,2 +130,13 @@ /*

foreach_inline_bake: {
options: {
content: "test/fixtures/content.json",
section: "en"
},
files: {
"tmp/foreach-inline_bake.html": "test/fixtures/foreach-inline_bake.html"
}
},
no_process_bake: {

@@ -132,0 +143,0 @@ options: {

5

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

@@ -31,2 +31,5 @@ "author": {

},
"dependencies": {
"mout": "~0.7.1"
},
"devDependencies": {

@@ -33,0 +36,0 @@ "grunt-contrib-jshint": "~0.1.1",

30

README.md

@@ -1,2 +0,2 @@

# grunt-bake
# grunt-bake [![Build Status](https://travis-ci.org/MathiasPaumgarten/grunt-bake.png?branch=master)](https://travis-ci.org/MathiasPaumgarten/grunt-bake)

@@ -6,2 +6,4 @@ > Bake static pages for production while using modular files while in development.

## Getting Started

@@ -302,2 +304,14 @@ This plugin requires Grunt `~0.4.0`

Additionally the the `_if` statement also works with inlining the bake content.
```html
<html>
<body>
<!--(bake-start _if="name")-->
<h1>{{name}}</h1>
<!--(bake-end)-->
</body>
</html>
```
#### Foreach Loop

@@ -357,2 +371,16 @@

Just like the `_if` statement the `_foreach` also works with inlined content:
```html
<html>
<body>
<ul>
<!--(bake-start _foreach="name:[robert, susan, carl]")-->
<li>{{name}}</li>
<!--(bake-end)-->
</ul>
</body>
</html>
```
#### Costum process

@@ -359,0 +387,0 @@ This example shows the use of a costum process funtion.

@@ -11,2 +11,4 @@ /*

var mout = require( "mout" );
module.exports = function( grunt ) {

@@ -43,2 +45,6 @@

if ( options.basePath.substr( -1 , 1 ) !== "/" && options.basePath.length > 0 ) {
options.basePath = options.basePath + "/";
}
// ===========

@@ -51,4 +57,4 @@ // -- UTILS --

var regex = /([ |\t]*)<!\-\-\(\s?bake\s+([\w\/.\-]+)\s?([^>]*)\)\-\->/g;
var regexInline = /[ |\t]*<!\-\-\(\s?bake\-start\s+([^>]*)\)\-\->\n?([^!]*)[ |\t]*<!\-\-\(\s?bake\-end\s?\)\-\->/g;
// Regex to parse attributes.

@@ -104,18 +110,3 @@

function resolveName( name, values ) {
var names = name.split( "." );
var current = values;
var next;
while ( names.length ) {
next = names.shift();
if ( ! current.hasOwnProperty( next ) ) {
grunt.log.warn( "can't find " + name );
return "";
}
current = current[ next ];
}
return current || "";
return mout.object.get( values, name ) || "";
}

@@ -127,17 +118,4 @@

function hasValue( name, values ) {
var names = name.split( "." );
var current = values;
var next;
while ( names.length ) {
next = names.shift();
if ( ! current.hasOwnProperty( next ) ) {
return false;
}
current = current[ next ];
}
return current === false ? false : true;
var current = mout.object.get( values, name );
return current === false || current === undefined ? false : true;
}

@@ -154,3 +132,2 @@

var lines = content.split( "\n" );
var prepedLines = lines.map( function( line ) {

@@ -178,80 +155,149 @@ return indent + line;

function replaceMatch( indent, includePath, attributes, filePath, values ) {
// =====================
// -- RECURSIVE PARSE --
// =====================
var inlineOptions = parseInlineOptions( attributes );
var array = [];
var name = "";
// Recursivly search for includes and create one file.
if ( "_if" in inlineOptions ) {
var value = inlineOptions[ "_if" ];
function parse( fileContent, filePath, values ) {
if ( ! hasValue( value, values ) ) {
return "";
}
if ( typeof options.process === "function" ) {
fileContent = options.process( fileContent, values );
delete inlineOptions[ "_if" ];
}
return fileContent.replace( regex, function( match, indent, includePath, attributes ) {
if ( "_foreach" in inlineOptions ) {
var pair = inlineOptions[ "_foreach" ].split( ":" );
var inlineOptions = parseInlineOptions( attributes );
var array = [];
var name = "";
name = pair[ 0 ];
array = getArrayValues( pair[ 1 ], values );
if ( "_if" in inlineOptions ) {
var value = inlineOptions[ "_if" ];
delete inlineOptions[ "_foreach" ];
}
if ( ! hasValue( value, values ) ) {
return "";
}
grunt.util._.merge( values, inlineOptions );
delete inlineOptions[ "_if" ];
if ( includePath[ 0 ] === "/" ) {
includePath = options.basePath + includePath.substr( 1 );
} else {
includePath = directory( filePath ) + "/" + includePath;
}
var includeContent = grunt.file.read( includePath );
includeContent = applyIndent( indent, includeContent );
if ( array.length > 0 ) {
var fragment = "";
var newline = "";
var oldValue = values[ name ];
array.forEach( function( value, index ) {
values[ name ] = value;
newline = index > 0 ? "\n" : "";
fragment += newline + parse( includeContent, includePath, values );
} );
if ( oldValue ) {
values[ name ] = oldValue;
} else {
delete values[ name ];
}
if ( "_foreach" in inlineOptions ) {
var pair = inlineOptions[ "_foreach" ].split( ":" );
return fragment;
name = pair[ 0 ];
array = getArrayValues( pair[ 1 ], values );
} else {
delete inlineOptions[ "_foreach" ];
return parse( includeContent, includePath, values );
}
}
function replaceInlineMatch( attributes, content, filePath, values ) {
var inlineOptions = parseInlineOptions( attributes );
var name = "";
var array = [];
if ( "_if" in inlineOptions ) {
var value = inlineOptions[ "_if" ];
if ( ! hasValue( value, values ) ) {
return "";
}
grunt.util._.merge( values, inlineOptions );
delete inlineOptions[ "_if" ];
if ( includePath[ 0 ] === "/" ) {
includePath = options.basePath + includePath.substr( 1 );
}
if ( "_foreach" in inlineOptions ) {
var pair = inlineOptions[ "_foreach" ].split( ":" );
name = pair[ 0 ];
array = getArrayValues( pair[ 1 ], values );
delete inlineOptions[ "_foreach" ];
}
grunt.util._.merge( values, inlineOptions );
var includeContent = mout.string.rtrim( content, [ " ", "\n", "\t", "\r" ] );
if ( array.length > 0 ) {
var fragment = "";
var newline = "";
var oldValue = values[ name ];
array.forEach( function( value, index ) {
values[ name ] = value;
newline = typeof options.process === "function" ? options.process( includeContent, values ) : includeContent;
fragment += ( index > 0 ? "\n" : "" ) + newline;
} );
if ( oldValue ) {
values[ name ] = oldValue;
} else {
includePath = directory( filePath ) + "/" + includePath;
delete values[ name ];
}
var includeContent = grunt.file.read( includePath );
includeContent = applyIndent( indent, includeContent );
return fragment;
if ( array.length > 0 ) {
} else {
var fragment = "";
var newline = "";
var oldValue = values[ name ];
return parse( includeContent, filePath, values );
array.forEach( function( value, index ) {
values[ name ] = value;
newline = index > 0 ? "\n" : "";
}
}
fragment += newline + parse( includeContent, includePath, values );
} );
if ( oldValue ) {
values[ name ] = oldValue;
} else {
delete values[ name ];
}
// =====================
// -- RECURSIVE PARSE --
// =====================
return fragment;
// Recursivly search for includes and create one file.
} else {
function parse( fileContent, filePath, values ) {
return parse( includeContent, includePath, values );
fileContent = fileContent.replace( regexInline, function( match, attributes, content ) {
return replaceInlineMatch( attributes, content, filePath, values );
} );
}
if ( typeof options.process === "function" ) {
fileContent = options.process( fileContent, values );
}
fileContent = fileContent.replace( regex, function( match, indent, includePath, attributes ) {
return replaceMatch( indent, includePath, attributes, filePath, values );
} );
return fileContent;
}

@@ -264,12 +310,3 @@

// normalize options
var basePath = options.basePath;
if ( basePath.substr( -1 , 1 ) !== "/" && basePath.length > 0 ) {
options.basePath = basePath + "/";
}
// Loop over files and create baked files.

@@ -276,0 +313,0 @@

@@ -107,2 +107,12 @@ "use strict";

foreachInlineBack: function( test ) {
test.expect( 1 );
var actual = grunt.file.read( "tmp/foreach-inline_bake.html" );
var expected = grunt.file.read( "test/expected/foreach-inline_bake.html" );
test.equal( actual, expected, "foreach-inline bake" );
test.done();
},
noProcessBake: function( test ) {

@@ -109,0 +119,0 @@ test.expect( 1 );

@@ -0,0 +0,0 @@ {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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