New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 1.4.1 to 1.5.0

test/expected/extra_bake_multiple.html

20

Gruntfile.js

@@ -439,2 +439,22 @@ /*

}
},
extra_bake: {
files: {
"tmp/extra_bake.html": "test/fixtures/extra_bake.html"
}
},
extra_bake_multiple: {
options: {
content: "test/fixtures/content.json",
transforms: {
lowercase: function( string ) {
return String( string ).toLowerCase();
}
}
},
files: {
"tmp/extra_bake_multiple.html": "test/fixtures/extra_bake_multiple.html"
}
}

@@ -441,0 +461,0 @@ }

2

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

@@ -6,0 +6,0 @@ "author": {

@@ -558,4 +558,68 @@ # grunt-bake

#### Bake extra pages (e.g. detail pages)
Another special inline attribute is the `_bake` attribute. This keyword expects a specific syntax which allows to dynamically create additional files. It accepts the syntax: `_bake="template.html > target.html"`.
The following example will create two additional files named `info-John.html` and `info-Jane.html` which will be baked using `app/detail.html` with corresponding values from `app/content.json`. For linking to genereated files a `@link` variable is available.
_app/detail.html_:
```html
<html>
<body>
<h1>My name is {{member.name}}</h1>
<p>I am a {{member.profession}}</p>
</body>
</html>
```
_app/base.html_:
```html
<html>
<body>
<ul>
<!--(bake li.html _foreach="member:members" _bake="detail.html > member-{{member.name}}.html")-->
</ul>
</body>
</html>
```
_app/li.html_:
```html
<li><a href="{{@link}}">More about {{member.name}}</a></li>
```
_app/content.json_:
```json
{
"members": [
{
"name": "John",
"profession": "Dentist"
},
{
"name": "Jane",
"profession": "Pilot"
}
]
}
```
**Alternative `app/base.html` with inline-section instead of additional `app/li.html` file:**
_app/base.html_:
```html
<html>
<body>
<ul>
<!--(bake-start _foreach="member:members" _bake="detail.html > member-{{member.name}}.html")-->
<li><a href="{{@link}}">More about {{member.name}}</a></li>
<!--(bake-end)-->
</ul>
</body>
</html>
```
_app/detail.html_ and _app/content.json_ same as above.
#### Custom process

@@ -603,2 +667,3 @@ This example shows the use of a custom process function.

`1.5.0` __2-2-2016__ adds support for _bake attribute.
`1.4.1` __2-2-2016__ fixes minor bug fix #72.

@@ -605,0 +670,0 @@ `1.4.0` __1-30-2016__ adds full JS support for evaluating _if.

@@ -330,2 +330,21 @@ /*

// Handle _bake attributes in inline arguments
function validateBake( inlineValues ) {
if ( "_bake" in inlineValues ) {
var signature = inlineValues[ "_bake" ];
delete inlineValues[ "_bake" ];
var set = signature.split( ">", 2 );
return {
src: mout.string.trim( set[0] ),
dest: mout.string.trim( set[1] )
};
}
return null;
}
function preparePath( includePath, filePath, values ) {

@@ -341,3 +360,14 @@

function replaceFile( linebreak, indent, includePath, attributes, filePath, values ) {
function processExtraBake( bake, filePath, destFile, values ) {
if( bake === null ) return;
var src = preparePath( bake.src, filePath, values );
var dest = preparePath( bake.dest, destFile, values );
values[ "@link" ] = processContent( bake.dest, values );
bakeFile( src, dest, values );
}
function replaceFile( linebreak, indent, includePath, attributes, filePath, destFile, values ) {
includePath = preparePath( includePath, filePath, values );

@@ -347,8 +377,9 @@

return replaceString( includeContent, linebreak, indent, includePath, attributes, values );
return replaceString( includeContent, linebreak, indent, includePath, attributes, filePath, destFile, values );
}
function replaceString( includeContent, linebreak, indent, includePath, attributes, values ) {
function replaceString( includeContent, linebreak, indent, includePath, attributes, filePath, destFile, values ) {
var inlineValues = parseInlineValues( attributes );
var section = validateSection( inlineValues, values );
var extraBake = validateBake( inlineValues );

@@ -390,3 +421,5 @@ if ( section !== null ) {

fragment += linebreak + parse( includeContent, includePath, values );
processExtraBake( extraBake, filePath, destFile, values );
fragment += linebreak + parse( includeContent, includePath, destFile, values );
} );

@@ -401,4 +434,6 @@

return linebreak + parse( includeContent, includePath, values );
processExtraBake( extraBake, filePath, destFile, values );
return linebreak + parse( includeContent, includePath, destFile, values );
} else {

@@ -410,3 +445,2 @@

// =====================

@@ -469,3 +503,3 @@ // -- RECURSIVE PARSE --

function parse( fileContent, filePath, values ) {
function parse( fileContent, filePath, destFile, values ) {

@@ -478,8 +512,8 @@ var section = extractSection( fileContent );

if(section.inner) {
fileContent += replaceString( section.inner, "", "", filePath, section.attributes, values );
fileContent += replaceString( section.inner, "", "", filePath, section.attributes, filePath, destFile, values );
} else {
fileContent += replaceFile( section.linebreak, section.indent, section.includePath, section.attributes, filePath, values );
fileContent += replaceFile( section.linebreak, section.indent, section.includePath, section.attributes, filePath, destFile, values );
}
fileContent += parse( section.after, filePath, values );
fileContent += parse( section.after, filePath, destFile, values );
}

@@ -500,2 +534,11 @@

function bakeFile( src, dest, content ) {
var srcContent = grunt.file.read( src );
var destContent = parse( srcContent, src, dest, content );
grunt.file.write( dest, destContent );
grunt.log.ok( "File \"" + dest + "\" created." );
}
// Loop over files and create baked files.

@@ -519,10 +562,5 @@

var srcContent = grunt.file.read( src );
var destContent = parse( srcContent, src, options.content );
grunt.file.write( dest, destContent );
grunt.log.ok( "File \"" + dest + "\" created." );
bakeFile( src, dest, options.content );
} );
} );
};

@@ -39,3 +39,8 @@ "use strict";

"tmp/path_with_placeholder.html": "test/expected/path_with_placeholder.html",
"tmp/recursive_path_with_placeholder.html": "test/expected/recursive_path_with_placeholder.html"
"tmp/recursive_path_with_placeholder.html": "test/expected/recursive_path_with_placeholder.html",
"tmp/extra_bake.html": "test/expected/extra_bake.html",
"tmp/extra_bake_multiple.html": "test/expected/extra_bake_multiple.html",
"tmp/extra-page.html": "test/expected/extra/extra-page.html",
"tmp/extra-0-a-team.html": "test/expected/extra/extra-0-a-team.html",
"tmp/extra-1-b-team.html": "test/expected/extra/extra-1-b-team.html"
};

@@ -42,0 +47,0 @@

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