0.1.11 • Published 10 years ago

maker v0.1.11

Weekly downloads
2
License
-
Repository
-
Last release
10 years ago

maker

maker is a general purpose text file templating engine. Use it to create text files programmatically.

Installation

npm install maker

maker scans a directory for a collection of templates, and allows you to select and fill out those templates as needed.

Here's an example template, lets say we save it as 'myTemplate.tpl'

//////////////////////////////////////////////////////////////////////////
// ~~comment~~
function ~~functionName~~( ~~arguments~~ ) {
	~~contents~~
} // end ~~functionName~~()

The template is a copy of the code you're trying to output with the variables and custom names replaced with template strings. The default separation string is ~~, but it can be changed to anything by using the optional argument to the maker constructor.

Here's a basic usage example

var maker = require("maker").createMaker();

// Load all template files (.tpl) within some directory
maker.loadTemplateDir( "./templates", function( templates ) {

	// Grab a copy of the templates we want to use
	var myTemplate = maker.getTemplate( "myTemplate" ),
		myOtherTemplate = maker.getTemplate( "myOtherTemplate" );

	// Fill out our templates with contents
	myTemplate.comment = "comment stuff";
	myTemplate.functionName = "SomeFunction";
	myTemplate.arguments = "";
	myTemplate.contents = "console.log('test');";

	myOtherTemplate.someThing = "someOtherThing";

	// Create an array of templates in the order that 
	// we want them to appear in the file
	fileTemplates = [];
	fileTemplates.push( myTemplate );
	fileTemplates.push( templates["myOtherTemplate"] );

	// Write the file
	maker.makeFile( "./testOutput.js", fileTemplates );
}

Ignoring the unspecified template 'myOtherTemplate', This script would render myTemplate.tpl as the following

//////////////////////////////////////////////////////////////////////////
// comment stuff
function SomeFunction() {
	console.log('test');
} // end SomeFunction()
0.1.11

10 years ago

0.1.9

10 years ago

0.1.8

11 years ago

0.1.7

11 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.14

11 years ago

0.0.13

11 years ago

0.0.12

11 years ago

0.0.11

11 years ago

0.0.10

11 years ago

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago