grunt-bake
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -256,2 +256,8 @@ /* | ||
} | ||
}, | ||
shared: { | ||
title: "Title", | ||
info: { | ||
author: "Test Author" | ||
} | ||
} | ||
@@ -258,0 +264,0 @@ } |
{ | ||
"name": "grunt-bake", | ||
"description": "Bake external includes into files to create static pages with no server-side compilation time", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"homepage": "https://github.com/MathiasPaumgarten/grunt-bake", | ||
@@ -36,3 +36,3 @@ "author": { | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
"node": ">= 0.11.0" | ||
}, | ||
@@ -43,3 +43,3 @@ "scripts": { | ||
"dependencies": { | ||
"mout": "~0.11.1" | ||
"mout": "~1.0.0" | ||
}, | ||
@@ -46,0 +46,0 @@ "devDependencies": { |
@@ -216,2 +216,13 @@ # grunt-bake | ||
#### options.variableParsePattern | ||
Type: `Regex` | ||
Default value: `/\{\{!\s*([^\}]+)\s*\}\}/` | ||
This regex is used to parse the variable specified inline with the bake task. Any inline attribute that | ||
is not preficed with an unerscore such as `_if` and `_section` is considered a variable and is passed to | ||
the bake include. For more detail check out the section on [Inline Attributes](#inline-attributes). | ||
However, if you want to pass not a value but a reference to an different object you can do so by writing | ||
the inline value as `variable="{{!foo.bar}}"`. Mind the exclamation mark. Assuming `bar` is an object | ||
as well, this will give you a reference to bar instead of the string. | ||
### Usage Examples | ||
@@ -760,2 +771,3 @@ | ||
* `1.9.0` __1-2-2018__ Adds variableParsePattern for inline variables. | ||
* `1.8.0` __4-20-2016__ Adds permanent variables under `__bake`. | ||
@@ -762,0 +774,0 @@ * `1.7.2` __4-20-2016__ Resolves recursion issues in _process and _assign. |
@@ -30,2 +30,3 @@ /* | ||
parsePattern: /\{\{\s*([^\}]+)\s*\}\}/g, | ||
variableParsePattern: /\{\{!\s*([^\}]+)\s*\}\}/, | ||
removeUndefined: true | ||
@@ -169,2 +170,6 @@ } ); | ||
// Regex to evaluate foreach object loops | ||
var forEachRegex = /([\w]+)\s+as\s+([\w]+)\s*=>\s*([\w]+)/g; | ||
// Method to check wether file exists and warn if not. | ||
@@ -225,3 +230,2 @@ | ||
}; | ||
} else { | ||
@@ -368,2 +372,16 @@ result = { | ||
// test for object syntax `object as key => value` | ||
var match; | ||
if ( match = forEachRegex.exec( inlineValues[ "_foreach" ] ) ) { | ||
var object = { | ||
keyName: match[ 2 ], | ||
valueName: match[ 3 ], | ||
values: values[ match[ 1 ] ] | ||
}; | ||
return object; | ||
} | ||
var set = inlineValues[ "_foreach" ].split( ":" ); | ||
@@ -373,3 +391,3 @@ delete inlineValues[ "_foreach" ]; | ||
// as transforms may contain colons, join rest of list to recreate original string | ||
getArrayValues( set.slice(1).join( ":" ), values ).forEach( function( value ) { | ||
getArrayValues( set.slice( 1 ).join( ":" ), values ).forEach( function( value ) { | ||
array.push( value ); | ||
@@ -442,3 +460,3 @@ } ); | ||
function processExtraBake( bake, filePath, destFile, values ) { | ||
if( bake === null ) return; | ||
if ( bake === null ) return; | ||
@@ -479,2 +497,3 @@ var src = preparePath( bake.src, filePath, values ); | ||
if ( section !== null ) { | ||
@@ -486,3 +505,7 @@ values = mout.object.get( parentValues, section ); | ||
inlineValues = mout.object.map( inlineValues, function( value ) { | ||
return processContent( value, values ); | ||
if ( options.variableParsePattern.test( value ) ) { | ||
return mout.object.get( parentValues, options.variableParsePattern.exec( value )[ 1 ] ); | ||
} else { | ||
return processContent( value, parentValues ); | ||
} | ||
} ); | ||
@@ -492,2 +515,3 @@ | ||
if ( validateRender( inlineValues ) ) return ""; | ||
var forEachValues = []; | ||
@@ -498,14 +522,34 @@ var forEachName = validateForEach( inlineValues, values, forEachValues ); | ||
includeContent = applyIndent( indent, includeContent); | ||
includeContent = applyIndent( indent, includeContent ); | ||
var content = ""; // result of current bake-section | ||
var fragment = ""; // repeated bake section for loops | ||
var total; | ||
var oldValue; | ||
if( !doProcess ) { | ||
if ( ! doProcess ) { | ||
content = linebreak + includeContent; | ||
} else if ( mout.lang.isObject( forEachName ) ) { | ||
total = Object.keys( forEachName.values ).length; | ||
for ( var key in forEachName.values ) { | ||
values[ forEachName.keyName ] = key; | ||
values[ forEachName.valueName ] = forEachName.values[ key ]; | ||
processExtraBake( extraBake, filePath, destFile, values ); | ||
fragment += linebreak + processContent( parse( includeContent, includePath, destFile, values ), values ); | ||
delete values[ forEachName.keyName ]; | ||
delete values[ forEachName.valueName ]; | ||
} | ||
content = fragment; | ||
} else if ( forEachName && forEachValues.length > 0 ) { | ||
var fragment = ""; | ||
var oldValue = values[ forEachName ]; | ||
var total = forEachValues.length; | ||
oldValue = values[ forEachName ]; | ||
total = forEachValues.length; | ||
@@ -533,3 +577,3 @@ | ||
} else if( !forEachName ) { | ||
} else if ( ! forEachName ) { | ||
@@ -545,3 +589,3 @@ processExtraBake( extraBake, filePath, destFile, values ); | ||
if( assign !== null ) { | ||
if ( assign !== null ) { | ||
parentValues[ assign ] = mout.string.ltrim( content ); | ||
@@ -548,0 +592,0 @@ |
@@ -14,2 +14,6 @@ { | ||
], | ||
"object": { | ||
"name": "John Dough", | ||
"place": "Some place" | ||
}, | ||
"empty": [] | ||
@@ -16,0 +20,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
71227
1091
786
102
+ Addedmout@1.0.0(transitive)
- Removedmout@0.11.1(transitive)
Updatedmout@~1.0.0