Template Store

libflitter/utility/TemplateStore

exports:  class TemplateStore

class TemplateStore

Stores templates by name and returns their parts on demand. Templates should be instances of Object that specify the template generator, file extension, and destination directory. In Flitter, a template is a type of file that may be created by the developer multiple times with different names. The generator function should accept a class/variable name and should return the text of the new file. Here's an example template Object:

const middleware_template = {
	// The generator function. Should accept (String name) and should return the text of the new file.
	template: require('libflitter/templates/middleware'),
  
  	// The base directory of the template, fully-qualified.
	directory: this.directory,
  
  	// Extension of the new file.
	extension: '.middleware.js'
}
store

type:  Object

Stores the templates in key-value pairs such that the key is the specified name of the template, and the value is the template Object.

constructor()

returns:  this

Initializes the class. Sets this.store to a new Object.

add(String name, Object template)

returns:  undefined

Stores the provided template in this.store by name.

directory(String name)

returns:  String

Returns the directory from the template Object with the given name from this.store.

extension(String name)

returns:  String

Returns the file extension from the template Object with the given name from this.store.

generator(String name)

returns:  function

Returns the template generator function from the template Object with the given name from this.store.

No Comments
Back to top