grunt-bake
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -12,4 +12,4 @@ /* | ||
var parseFunction = function( source, object ) { | ||
return source.replace( /{{(\w*)}}/g, function( match, key ) { | ||
return ( key in object ) ? object[ key ].toUpperCase() : ""; | ||
return source.replace( /{{([.-\w]*)}}/g, function( match, key ) { | ||
return ""; | ||
} ); | ||
@@ -16,0 +16,0 @@ } |
{ | ||
"name": "grunt-bake", | ||
"description": "Bake external includes into the file to create static pages with no compilation time", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/MathiasPaumgarten/grunt-bake", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -87,7 +87,17 @@ # grunt-bake | ||
"en": { | ||
"title": "Book" | ||
"title": "Book", | ||
"info": { | ||
"author": "Joe Do", | ||
"job": "Writer" | ||
} | ||
}, | ||
"de": { | ||
"title": "Buch" | ||
"title": "Buch", | ||
"info": { | ||
"author": "Joe Do", | ||
"job": "Schreiber" | ||
} | ||
} | ||
@@ -103,2 +113,6 @@ } | ||
<div>{{title}}</div> | ||
<div> | ||
<span>{{info.author}}</span> | ||
<span>{{info.job}}</span> | ||
</div> | ||
``` | ||
@@ -105,0 +119,0 @@ |
@@ -23,4 +23,4 @@ /* | ||
var defaultProcess = function( template, content ) { | ||
return template.replace( /{{(\w*)}}/g, function( match, key ) { | ||
return ( key in content ) ? content[ key ] : ""; | ||
return template.replace( /{{([.-\w]*)}}/g, function( match, key ) { | ||
return resolveName( key, content ); | ||
} ); | ||
@@ -30,2 +30,24 @@ } | ||
// Helper method to resolve nested placeholder names like: "home.footer.text" | ||
var resolveName = function( 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 || ""; | ||
} | ||
// ============= | ||
@@ -87,3 +109,3 @@ // -- OPTIONS -- | ||
while( match = attributesRegex.exec( string ) ) { | ||
values[ match[ 0 ] ] = match[ 2 ]; | ||
values[ match[ 1 ] ] = match[ 2 ]; | ||
} | ||
@@ -102,2 +124,6 @@ | ||
if ( typeof options.process === "function" ) { | ||
fileContent = options.process( fileContent, values ); | ||
} | ||
return fileContent.replace( regex, function( match, includePath, attributes ) { | ||
@@ -112,6 +138,2 @@ | ||
if ( typeof options.process === "function" ) { | ||
includeContent = options.process( includeContent, values ); | ||
} | ||
return parse( includeContent, includePath, values ); | ||
@@ -155,3 +177,2 @@ } ); | ||
} ); | ||
}; |
@@ -45,3 +45,13 @@ "use strict"; | ||
test.done(); | ||
}, | ||
inlineBake: function( test ) { | ||
test.expect( 1 ); | ||
var actual = grunt.file.read( "tmp/inline.html" ); | ||
var expected = grunt.file.read( "test/expected/inline.html" ); | ||
test.equal( actual, expected, "inline attributes" ); | ||
test.done(); | ||
} | ||
}; |
{ | ||
"en": { | ||
"title": "Apple Pie" | ||
"title": "Apple Pie", | ||
"info": { | ||
"author": "Mathias" | ||
} | ||
}, | ||
"de": { | ||
"title": "Apfelstrudel" | ||
"title": "Apfelstrudel", | ||
"info": { | ||
"author": "Mathias" | ||
} | ||
} | ||
} |
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
16727
248
297