-
Notifications
You must be signed in to change notification settings - Fork 6
ow.template
- ow.template.addConditionalHelpers
- ow.template.addFormatHelpers
- ow.template.addHelper
- ow.template.addHelpers
- ow.template.addInLineCSS2HTML
- ow.template.addPartial
- ow.template.compile
- ow.template.delHelper
- ow.template.delPartial
- ow.template.execCompiled
- ow.template.getTemplate
- ow.template.loadCompiledHBS
- ow.template.loadHBSs
- ow.template.loadPartialHBS
- ow.template.parse
- ow.template.parseHBS
- ow.template.parseMD2HTML
- ow.template.saveCompiledHBS
- ow.template.saveHBS
- ow.template.unloadPartialHBSs
ow.template.addConditionalHelpers()
Adds helper functions equivalent to assemble.io comparison helpers. See more in http://assemble.io/helpers/helpers-comparison.html
ow.template.addFormatHelpers()
Adds all functions of ow.format as helpers with the prefix owFormat_.
ow.template.addHelper(aHelperName, aFunction)
Adds aFunction as aHelperName.
ow.template.addHelpers(aPrefix, aObject)
Registers all aObject functions as helpers. These helpers identifier will be composed by aPrefix + Name of the each function.
(available after ow.loadTemplate())
ow.template.addInLineCSS2HTML(aHTML, aCustomCSSMap) : String
Given aHTML (usually the result of parseMD2HTML) applies a custom inline css (aCustomCSSMap) usually useful to send HTML to email clients. This custom map should be composed of a html tag entity tag (e.g. "p") and, as value, the css style to apply (e.g. "color: red;"). The map will be applied to all html entities on aHTML. If aCustomCSSMap is not provided a default one (suited for markdown html) will be applied.
ow.template.addPartial(aPartialName, aSource)
Registers aSource template as a reusable aPartialName in other templates.
ow.template.compile(aSource, anOptionsMap) : String
Tries to precompile aSource and returns a String that can be used with ow.template.execCompiled. Optionally you can provide anOptionsMap for the Handlebars precompiler (see more on ow.template.saveCompiledHBS).
ow.template.delHelper(aHelperName)
Unregister aHelperName that had been previously added with ow.template.addHelper.
ow.template.delPartial(aPartialName)
Unregisters aPartialName that had been previously added with ow.template.addPartial
ow.template.execCompiled(aCompiledObject) : Function
Tries to execute a previously precompiled Handlebars template (for example, using ow.template.compile) and return it as a Handlebars template functions.
ow.template.getTemplate(aSource) : Function
Returns a template function, given aSource, that accepts an object as argument and returns the correspoding template filled with the values provided.
ow.template.loadCompiledHBS(aFilename) : Function
Tries to load a previously precompiled Handlebars template (for example, using ow.template.saveCompiledHBS) and return it as a Handlebars template functions.
ow.template.loadHBSs(aMapOfHBSs) : Function
Given a map where the key is a hbs template key and the value is the filepath of a HBS file, will pre-compile the HBS files and return a function(key, data). This function can be used to execute a the pre-compiled templates using the hbs template key and passing the corresponding data map to be used on that template returning the template parsed. Note: the filepath can indicate a file inside a zip file like 'some/path/a.zip::file'.
ow.template.loadPartialHBS(aMapOfParialHBSs)
Given a map where the key is a partial hbs template key and the value is the filepath of a HBS file, will load it and add it as a template partial. Note: the filepath can indicate a file inside a zip file like 'some/path/a.zip::file'.
ow.template.parse(aSource, someData) : String
Returns the results of using someData to the template defined on the aSource provided. Note: for parallel processing you should use ow.template.compile since Handlebars might not be thread-safe.
ow.template.parseHBS(aFilename, someData) : String
Returns the results of using someData with the template defined on aFilename (tip: use the extension hbs).
ow.template.parseMD2HTML(aMarkdownString, isFull) : String
Given aMarkdownString will parse it with showdown (using the github flavor) and return the HTML in a string. If isFull = true it will produce a complete HTML with references for the highlight library+css and github markdown css included internally in OpenAF. Example:
ow.server.httpd.route(hs, ow.server.httpd.mapRoutesWithLibs(hs, {
"/md": (req) => { return hs.replyOKHTML(ow.template.parseMD2HTML(io.readFileString("README.md"), true)) }
}), (req) => { return hs.replyOKText("nothing here...");})
ow.template.saveCompiledHBS(aFilename, aSource, anOptionsMap)
Tries to precompile aSource and save the result into aFilename (tip: use the extension hbsc). This can later be loaded again using ow.template.loadCompiledHBS, for example. Optionally you can provide anOptionsMap for the Handlebars precompiler (see more on the options for Handlebars.precompile). Example:
var source = "My name is {{myname}}. I'm a\n{{#each role}}\t- {{this}}\n{{/each}}";
ow.template.saveCompiledHBS("myroles.hbsc", source, {
{ "knowHelpers": ["each"], "knowHelpersOnly": true }
};
ow.template.saveHBS(aFilename, aSource)
Saves aSource Handlebars template into aFilename (tip: use the extension hbs).
ow.template.unloadPartialHBSs(aMapOFPartialHBSs)
Given the same map provided to ow.template.loadPartialHBS will actually unload them as template partials.