Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Mustr

Hierarchy

  • EventEmitter
    • Mustr

Implements

Index

Constructors

constructor

Properties

Engine

Engine: Object

components

components: IMap<IComponent>

configPath

configPath: string

cwd

cwd: string = process.cwd().toLowerCase()

Private loaded

loaded: boolean = false

log

log: ILogger

options

options: IMustrOptions

outputPath

outputPath: string

registerPath

registerPath: string

renderer

renderer: RenderMethod

rollbackIdExp

rollbackIdExp: RegExp = /^[0-9]+-[a-z0-9]+$/

rollbacks

rollbacksPath

rollbacksPath: string

templates

templates: IMap<ITemplate>

templatesGlob

templatesGlob: string[]

templatesPath

templatesPath: string

Private tplexp

tplexp: RegExp

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: Function): this
  • Parameters

    • event: string | symbol
    • listener: Function

    Returns this

Private addPartials

  • addPartials(template: ITemplate, ...args: any[]): void
  • Add Partials

    Parameters

    • template: ITemplate

      the template to add partials to.

    • Rest ...args: any[]

      the list of partials to add.

    Returns void

Private addRollback

configure

  • Configure Configures template for output.

    Parameters

    • name: string

      the name of the template to load.

    • Optional output: string | IRegisterConfig

      the output name/path to use when rendering.

    • Optional options: IRegisterConfig

      the optional config for the template.

    Returns ITemplate

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Returns ( string | symbol ) []

Private getDirs

  • getDirs(dir: string): string[]
  • Get Dirs Takes a base directory then retrives all sub directories for that directory.

    Parameters

    • dir: string

      base directory to get all sub directories from.

    Returns string[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

Private getPartial

getRollbacks

Private hasMatter

  • hasMatter(str: any): boolean
  • Has Matter Tests if string contains front matter.

    Parameters

    • str: any

      the string to inspect.

    Returns boolean

Private hasTemplate

  • hasTemplate(str: any): boolean
  • Has Template Loosly check if string contains template chars.

    Parameters

    • str: any

      the string to inspect.

    Returns boolean

init

  • init(force?: boolean): void
  • Init Initializes Mustr for current project

    Parameters

    • Optional force: boolean

      when true forces init.

    Returns void

inject

  • inject(filename: string | IInject, find?: string | RegExp | NodeCallback, strategy?: "before" | "after" | "first" | "last" | "replace", insert?: string | string[], done?: NodeCallback): void
  • Inject Creates a file stream reading chunks until match. Upon match the provided value is injected. NOTE: lines are auto updated with the correct line ending for returns.

    Parameters

    • filename: string | IInject

      the file name to inject into.

    • Optional find: string | RegExp | NodeCallback

      the string or expression to match.

    • Optional strategy: "before" | "after" | "first" | "last" | "replace"

      insert on before, after, replace, first or last when matched.

    • Optional insert: string | string[]

      the value or callback for injecting upon match.

    • Optional done: NodeCallback

      the callback on file written.

    Returns void

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

load

loadRollbacks

  • loadRollbacks(reindex?: boolean): IMustr

Private normalize

  • Normalize Parses/normalizes a template name, path or static template string. When passing a name it searches loaded template paths and matches the filename to the template name passed.

    Parameters

    • template: string

      the template name, path or static template string.

    Returns ITemplate

Private normalizeName

  • normalizeName(name: any): any
  • Normalize Name Removes extention from template name.

    Parameters

    • name: any

      the template name to normalize.

    Returns any

Private normalizedExt

  • normalizedExt(ext: any): string
  • Normalize Extension Ensures extension begins with "."

    Parameters

    • ext: any

      the extension to be normalized.

    Returns string

on

  • on(event: string | symbol, listener: Function): this
  • Parameters

    • event: string | symbol
    • listener: Function

    Returns this

once

  • once(event: string | symbol, listener: Function): this
  • Parameters

    • event: string | symbol
    • listener: Function

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: Function): this
  • Parameters

    • event: string | symbol
    • listener: Function

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: Function): this
  • Parameters

    • event: string | symbol
    • listener: Function

    Returns this

register

registerComponent

  • Register Component Registers a group of templates which will output to the specified directory. Often a component may have several files such as styles helpers, interfaces or maybe actions for react. This makes it easy to output all the files needed at once, hence a "component" or group.

    Parameters

    • name: string | IComponent

      the name of the component regsiter.

    • Rest ...args: any[]

      array of template names or csv params.

    Returns IMustr

registerGroup

  • registerGroup(...args: any[]): IMustr
  • Register Group Just a patch for backward compatibility.

    Parameters

    • Rest ...args: any[]

      arguments for registerComponent.

    Returns IMustr

reindexRollbacks

  • reindexRollbacks(prune?: boolean): IMustr
  • Reindex Rollbacks Iterates rollbacks.json re-sorts order optionally prunes records where rollback files are missing.

    Parameters

    • Optional prune: boolean

      when true prunes entries where missing required rollback folder/files.

    Returns IMustr

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: Function): this
  • Parameters

    • event: string | symbol
    • listener: Function

    Returns this

removeRollbacks

  • removeRollbacks(by: string | number | Date, save?: boolean): IMustr
  • Remove Rollbacks Removes previous rollbacks before Date by Date string a count of rollbacks to be removed or by rollbackId. When a number is provided the first of number provided will be removed. The last rollback is always preserved.

    Parameters

    • by: string | number | Date

      the date string or number of rollbacks to remove.

    • Optional save: boolean

      when false changes are not saved to file.

    Returns IMustr

render

  • Render Renders the requested template.

    todo

    this method is a monster now need to break out.

    Parameters

    • name: string | ITemplate

      the name of the template to render.

    • Optional output: string | IRegisterConfig | NodeCallback | boolean

      the output path/name to render the template as.

    • Optional options: IRegisterConfig | NodeCallback | boolean

      the configuration and metadata object.

    • Optional force: boolean | NodeCallback

      forces overwriting existing file.

    • Optional done: NodeCallback

      Node style callback with err and rendered template.

    • Optional group: any

      private variable used only internally.

    Returns ILogger

rollback

  • rollback(name?: string, output?: string): IMustr
  • Rollback Rolls back and removes generated templates.

    NOTE: currently does not rollback injects.

    Parameters

    • Optional name: string

      the template or group name.

    • Optional output: string

    Returns IMustr

saveRollbacks

  • saveRollbacks(prune?: boolean): IMustr
  • Save Rollbacks Writes current rollbacks to file.

    Parameters

    • Optional prune: boolean

      when false prevents pruning rollbacks before save.

    Returns IMustr

setEngine

  • setEngine(Engine: Object, renderer: RenderMethod): ILogger
  • Set Engine Allows for setting the templating Engine that should be used for rendering.

    Parameters

    • Engine: Object

      the template Engine used for rendering.

    • renderer: RenderMethod

      the rendering method.

    Returns ILogger

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

transformCase

  • transformCase(str: string, to: string): string
  • Transform To Transforms a string to the desired casing.

    Parameters

    • str: string

      the string to be transformed.

    • to: string

      the casing to be transformed to using lodash.

    Returns string

Private truncate

  • truncate(str: any, max: any): string
  • Truncate Nothing special, cheesy truncation...move along.

    Parameters

    • str: any

      the string to be truncated.

    • max: any

      the max len before truncating.

    Returns string

Private tryRequire

  • tryRequire(path: string): any
  • Try Require Tries to require a module logging error if failed.

    Parameters

    • path: string

      the module path to be required.

    Returns any

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc