James Sumners committed 2f314cf

Added support for page strings

Comments (0)

Files changed (4)

 			"index": {
 				"content": "index_content",
 				"file": "index.html",
-				"template": "template.html"
+				"template": "template.html",
+				"strings": {
+					"title": "Page Title",
+					"foo": "bar"
+				}
 	1. 	The "content" property's value must match a key on the *snippets* object.
 	2. 	The "file" property defines what file will be written in the config.buildDir directory.
 	3. 	The "template" property specifies what template from the config.templateDir directory
-		to use for this HTML file.
+		to use for this HTML file.
+	4.	Additionally, the *pages* object can include a "strings" property. This property is an object that
+		maps page specific token names to replacement strings. In our example, every occurance of "{{title}}"
+		in the "index_content" snippet will be replaced with "Page Title". Likewise, every
+		instance of "{{foo}}" will be replaced with "bar".


 		"index": {
 			"content": "index_content",
 			"file": "index.html",
-			"template": "template.html"
+			"template": "template.html",
+			"strings": {
+				"title": "njsBaker Example",
+				"sig": "~ James Sumners"
+			}
 		"about": {
 			"content": "about_content",


-	<h1>njsBaker Example</h1>
+	<h1>{{title}}</h1>
 	<p>This is an example to show how njsBaker builds static HTML sites.</p>
 	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
 	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
 	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>
+	<p>{{sig}}</p>
 		buffer = buffer.replace(re, snippets[tokens[i]], 'g');
+	// Replace the page's simple strings
+	if (page.strings) {
+		for (var str in page.strings) {
+			if (!page.strings.hasOwnProperty(str)) {
+				continue;
+			}
+			re = new RegExp(tokenDelimA + str + tokenDelimB);
+			buffer = buffer.replace(re, page.strings[str]);
+		}
+	}
 	fs.writeFileSync(baker.config.buildDir + '/' + page.file, buffer);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.