1. James Sumners
  2. njsBaker

Commits

James Sumners  committed 6c32eef

Switched the order in which things are parsed so that "content" templates can contain tokens.

  • Participants
  • Parent commits 0d60bf0
  • Branches default

Comments (0)

Files changed (4)

File example/Baker.json

View file
 	},
 
 	"snippets": {
+		"index_aside": "index_aside.html",
 		"index_content": "index_content.html",
 		"about_content": "about_content.html",
 		"site_nav": "site_nav.html"
 	},
 
 	"tokens": [
+		"index_aside",
 		"site_nav"
 	],
 

File example/templates/index_aside.html

View file
+<aside>
+	<ol>
+		<li>Item 1</li>
+		<li>Item 2</li>
+		<li>Item 3</li>
+	</ol>
+</aside>

File example/templates/index_content.html

View file
 	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
 	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
 	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
-</article>
+</article>
+{{index_aside}}

File lib/njsBaker.js

View file
 	buffer = fs.readFileSync(baker.config.templateDir + '/' + page.template);
 	buffer = buffer.toString();
 
+	// Replace the content token
+	re = new RegExp(tokenDelimA + "content" + tokenDelimB);
+	buffer = buffer.replace(re, snippets[page.content]);
+
 	// Look through the template for tokens and replace them
 	for (var i = 0, j = tokens.length; i < j; i += 1) {
 		re = new RegExp(tokenDelimA + tokens[i] + tokenDelimB);
 		buffer = buffer.replace(re, snippets[tokens[i]], 'g');
 	}
 
-	// Replace the content token
-	re = new RegExp(tokenDelimA + "content" + tokenDelimB);
-	buffer = buffer.replace(re, snippets[page.content]);
-
 	fs.writeFileSync(baker.config.buildDir + '/' + page.file, buffer);
 }