Compiler

class
 new Compiler() 

The class that compiles the Jade template.

class Compiler {
  constructor(parser) {

jade

property
 this.jade 

Jade used to compile the documentation

this.jade = jade;
// Set the options       
this.options = parser ? parser.options : {};
// Sets the files from the parser       
this.files = parser ? parser.files : [];
// Set up the compiler's code filter       
this.setCodeFilter();
    }

compile

method
 compile() 

Option name Type Description
locals Object

The local variable object

template String

The template to compile

return String

The compiled content

Compiles the docs

compile(locals, template) {
    // Return the compiled template       
    return this.jade.compile(template || this.template, {
      pretty: true,
      // Get the path (alias for filename) 
      filename: this.options.template ?
        this.options.template.path || 'index.jade' : 'index.jade'
    })(locals);
  }
JSFiddle

compileWithPath

method
 compileWithPath() 

Option name Type Description
path Object

The path to compile

locals Object

The local variable object

template String

The template to compile

return String

The compiled content

Compiles the docs with a specified path

compileWithPath(path, locals, template) {
    // Return the compiled template       
    return this.jade.compile(template || this.template, {
      pretty: true,
      // Alias for filename         
      filename: path
    })(locals);
  }

setTemplate

method
 setTemplate() 

Option name Type Description
template String

The template

Sets the template

setTemplate(template) {
    // Template used to produce the documentation     
    this.template = template;
    return this;
  }

setTemplateWithPath

method
 setTemplateWithPath() 

Option name Type Description
path String

The path to the template

Sets the template

setTemplateWithPath(path) {
    // Template used to produce the documentation     
    this.template = File.readFileSync(Path.resolve(__dirname, path ||
      this.options.template.path)).toString();
    return this;
  }

setFilters

method
 setFilters() 

Option name Type Description
filters Array, Object

The custom filter(s) to set

Sets custom filter(s)

setFilters(filters) {
    // Check if the fitlers is an object     
    if (_.isPlainObject(filters)) {
      this.jade.filters[filters.name] = filters.filter;
    }
    // Check if the filters is an array     
    if (_.isArray(filters)) {
      _.forEach(filters, (filter) => {
        this.jade.filters[filter.name] = filter.filter;
      });
    }
    return this;
  }
JSFiddle

setCodeFilter

method
 setCodeFilter() 

Option name Type Description
filter Function

The code filter to set

Sets the code filter for :code

setCodeFilter(filter) {

code

property
 this.jade.filters.code 

Option name Type Description
block String
return String

Jade support for filter :code

this.jade.filters.code = filter || function(block) {
  return block
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/#/g, '&#35;')
    .replace(/\\/g, '\\\\')
    .replace(/\n/g, '\\n');
};
return this;
  }
}
export default Compiler;