grunt-bake
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -101,2 +101,13 @@ /* | ||
} | ||
}, | ||
if_bake: { | ||
options: { | ||
content: "test/fixtures/content.json", | ||
section: "en" | ||
}, | ||
files: { | ||
"tmp/if_bake.html": "test/fixtures/if_bake.html" | ||
} | ||
} | ||
@@ -103,0 +114,0 @@ }, |
{ | ||
"name": "grunt-bake", | ||
"description": "Bake external includes into files to create static pages with no compilation time", | ||
"version": "0.0.9", | ||
"description": "Bake external includes into files to create static pages with no server-side compilation time", | ||
"version": "0.0.10", | ||
"homepage": "https://github.com/MathiasPaumgarten/grunt-bake", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -270,2 +270,34 @@ # grunt-bake | ||
#### IF Statement | ||
The __bake__ task also allows a simple `if` conditional. Inline attributes named `_if` are treated as such. If the value that `_if` holds can't be found in the content.json or if found equals to the value `false` the include will be ignored. | ||
_app/base.html_: | ||
```html | ||
<html> | ||
<body> | ||
<!--(bake includes/container.html _if="name")--> | ||
</body> | ||
</html> | ||
``` | ||
_app/content.json_: | ||
```json | ||
{ | ||
"foo": "bar" | ||
} | ||
``` | ||
This bake task will create _app/index.html_: | ||
```html | ||
<html> | ||
<body> | ||
</body> | ||
</html> | ||
``` | ||
#### Costum process | ||
@@ -272,0 +304,0 @@ This example shows the use of a costum process funtion. |
@@ -53,3 +53,3 @@ /* | ||
var attributesRegex = /([\S]+)="([^"]+)"/g; | ||
var attributesRegex = /([\S_]+)="([^"]+)"/g; | ||
@@ -116,2 +116,23 @@ | ||
// Helper that simply checks weather a value exists and is not `false` | ||
var hasValue = function( 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; | ||
} | ||
// ===================== | ||
@@ -133,2 +154,10 @@ // -- RECURSIVE PARSE -- | ||
if ( "_if" in inlineOptions ) { | ||
var value = inlineOptions[ "_if" ]; | ||
if ( ! hasValue( value, values ) ) return ""; | ||
delete inlineOptions[ "_if" ]; | ||
} | ||
grunt.util._.merge( values, inlineOptions ); | ||
@@ -135,0 +164,0 @@ |
@@ -75,3 +75,13 @@ "use strict"; | ||
test.done(); | ||
}, | ||
ifBake: function( test ) { | ||
test.expect( 1 ); | ||
var actual = grunt.file.read( "tmp/if_bake.html" ); | ||
var expected = grunt.file.read( "test/expected/if_bake.html" ); | ||
test.equal( actual, expected, "if bake" ); | ||
test.done(); | ||
} | ||
}; |
@@ -6,3 +6,4 @@ { | ||
"author": "Mathias" | ||
} | ||
}, | ||
"bar": false | ||
}, | ||
@@ -9,0 +10,0 @@ |
21305
28
320
346