UNPKG

goji

Version:

An HTML templating engine inspired by Thymeleaf

939 lines (278 loc) 11.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: Compiler</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: Compiler</h1> <section> <header> <h2> Compiler </h2> </header> <article> <div class="container-overview"> <h4 class="name" id="Compiler"><span class="type-signature"></span>new Compiler<span class="signature">(options)</span><span class="type-signature"> &rarr; {<a href="Compiler.html">Compiler</a>}</span></h4> <div class="description"> Provides methods for parsing, compiling, and rendering templates. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="lib_Compiler.js.html">lib/Compiler.js</a>, <a href="lib_Compiler.js.html#line53">line 53</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Compiler.html">Compiler</a></span> </dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="compile"><span class="type-signature"></span>compile<span class="signature">(template, options)</span><span class="type-signature"> &rarr; {<a href="Compiler.html#~RenderFunction">Compiler~RenderFunction</a>}</span></h4> <div class="description"> Parses a given <code>template</code> for <code>g-include</code> and <code>g-replace</code> blocks. Said blocks are dealt with appropriately. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>template</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The template to compile</td> </tr> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><a href="Compiler.html#~Options">Compiler~Options</a></span> </td> <td class="description last">Options to be used by the compiler</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="lib_Compiler.js.html">lib/Compiler.js</a>, <a href="lib_Compiler.js.html#line612">line 612</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> A function to use for rendering the compiled template </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Compiler.html#~RenderFunction">Compiler~RenderFunction</a></span> </dd> </dl> <h4 class="name" id="emptyCache"><span class="type-signature"></span>emptyCache<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> If caching is enabled, this method can be used to clear the cache. </div> <dl class="details"> <dt class="tag-since">Since:</dt> <dd class="tag-since"><ul class="dummy"><li>0.5.0</li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="lib_Compiler.js.html">lib/Compiler.js</a>, <a href="lib_Compiler.js.html#line351">line 351</a> </li></ul></dd> </dl> <h4 class="name" id="loadTemplateNamed"><span class="type-signature"></span>loadTemplateNamed<span class="signature">(name, isPartial)</span><span class="type-signature"> &rarr; {string|null}</span></h4> <div class="description"> Looks for a file in the templates direcory with the given name. If the file exists, it will be loaded and returned as a string. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the template to load</td> </tr> <tr> <td class="name"><code>isPartial</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">If set, then the defined partials directory will be used as the base path for loading the template</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-since">Since:</dt> <dd class="tag-since"><ul class="dummy"><li>0.5.0</li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="lib_Compiler.js.html">lib/Compiler.js</a>, <a href="lib_Compiler.js.html#line474">line 474</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> The template or <code>null</code> (wasn't found) </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> | <span class="param-type">null</span> </dd> </dl> <h3 class="subsection-title">Type Definitions</h3> <h4 class="name" id="~Options">Options</h4> <div class="description"> <p>An object literal that has the following properties:</p> <ul> <li> <code>cache</code>: Set to <code>true</code> (default) to enable caching of compiled templates. Set to <code>false</code> to compile templates every load. </li> <li> <code>cacheTTL</code>: Time, in seconds, to keep templates in the cache. Default value is 300 (5 minutes). </li> <li> <code>templatesDir</code>: The location where templates are stored. This should be the full path (use `path.resolve`). If it is not present, then it will be set to an "html" directory that is in the same directory as a node_modules directory. </li> <li> <code>partialsDir</code>: The location where partial templates are stored. This should be the full path (use `path.resolve`). If this option is not present then it will be set to a sub-directory of the specified <code>templatesDir</code>. The name of the sub-directory will be <code>partials</code>. </li> <li> <code>templatesExt</code>: The file extension used on template files. This defaults to ".html". Note that it should include the leading dot. </li> </ul> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">object</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="lib_Compiler.js.html">lib/Compiler.js</a>, <a href="lib_Compiler.js.html#line72">line 72</a> </li></ul></dd> </dl> <h4 class="name" id="~RenderFunction"><span class="type-signature"></span>RenderFunction<span class="signature">(context, options)</span><span class="type-signature"></span></h4> <div class="description"> Returned from the <a href="Compiler.html#compile">Compiler#compile</a> method when a template has been compiled. This function allows you to render the compiled template with substitued values. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>context</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">An object of values that will be substituted in the rendered template</td> </tr> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Not used (yet)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="lib_Compiler.js.html">lib/Compiler.js</a>, <a href="lib_Compiler.js.html#line592">line 592</a> </li></ul></dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Compiler.html">Compiler</a></li><li><a href="Goji.html">Goji</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.1</a> on Tue Jun 09 2015 14:05:51 GMT-0400 (EDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>