Cicero API
Modules
- cicero-engine
Clause Engine
- cicero-core
Cicero Core - defines the core data types for Cicero.
cicero-engine
Clause Engine
- cicero-engine
- .Engine
- new Engine()
- .execute(clause, request, state, currentTime) ⇒
Promise
- .init(clause, currentTime) ⇒
Promise
- .getErgoEngine() ⇒
ErgoEngine
- .Engine
cicero-engine.Engine
Engine class. Stateless execution of clauses against a request object, returning a response to the caller.
Kind: static class of cicero-engine
Access: public
- .Engine
- new Engine()
- .execute(clause, request, state, currentTime) ⇒
Promise
- .init(clause, currentTime) ⇒
Promise
- .getErgoEngine() ⇒
ErgoEngine
new Engine()
Create the Engine.
Promise
engine.execute(clause, request, state, currentTime) ⇒ Execute a clause, passing in the request object
Kind: instance method of Engine
Returns: Promise
- a promise that resolves to a result for the clause
Param | Type | Description |
---|---|---|
clause | Clause | the clause to execute |
request | object | the request, a JS object that can be deserialized using the Composer serializer. |
state | object | the contract state, a JS object that can be deserialized using the Composer serializer. |
currentTime | string | the definition of 'now' |
Promise
engine.init(clause, currentTime) ⇒ Initialize a clause
Kind: instance method of Engine
Returns: Promise
- a promise that resolves to a result for the clause initialization
Param | Type | Description |
---|---|---|
clause | Clause | the clause to execute |
currentTime | string | the definition of 'now' |
ErgoEngine
engine.getErgoEngine() ⇒ Provides access to the Ergo engine.
Kind: instance method of Engine
Returns: ErgoEngine
- the underlying Ergo Engine
cicero-core
Cicero Core - defines the core data types for Cicero.
- cicero-core
- .Clause
- .Contract
- .DateTimeFormatParser
- .parseDateTimeFormatField(field) ⇒
string
- .buildDateTimeFormatRule(formatString) ⇒
Object
- .parseDateTimeFormatField(field) ⇒
- .Metadata
- new Metadata(packageJson, readme, samples, request)
- .getTemplateType() ⇒
number
- .getRuntime() ⇒
string
- .getErgoVersion() ⇒
string
- .getCiceroVersion() ⇒
string
- .satisfiesCiceroVersion(version) ⇒
string
- .getSamples() ⇒
object
- .getRequest() ⇒
object
- .getSample(locale) ⇒
string
- .getREADME() ⇒
String
- .getPackageJson() ⇒
object
- .getName() ⇒
string
- .getKeywords() ⇒
Array
- .getDescription() ⇒
string
- .getVersion() ⇒
string
- .getIdentifier() ⇒
string
- .createTargetMetadata(runtimeName) ⇒
object
- .ParserManager
- new ParserManager(template)
- instance
- .getParser() ⇒
object
- .getTemplateAst() ⇒
object
- .setGrammar(grammar)
- .buildGrammar(templatizedGrammar)
- .buildGrammarRules(ast, templateModel, prefix, parts)
- .handleBinding(templateModel, parts, inputRule, element)
- .cleanChunk(input) ⇒
string
- .findFirstBinding(propertyName, elements) ⇒
int
- .getGrammar() ⇒
String
- .getTemplatizedGrammar() ⇒
String
- .getParser() ⇒
- static
- .Template
- new Template(packageJson, readme, samples, request)
- instance
- .validate()
- .getTemplateModel() ⇒
ClassDeclaration
- .getIdentifier() ⇒
String
- .getMetadata() ⇒
Metadata
- .getName() ⇒
String
- .getVersion() ⇒
String
- .getDescription() ⇒
String
- .getHash() ⇒
string
- .toArchive([language], [options]) ⇒
Promise.<Buffer>
- .getParserManager() ⇒
ParserManager
- .getTemplateLogic() ⇒
TemplateLogic
- .getIntrospector() ⇒
Introspector
- .getFactory() ⇒
Factory
- .getSerializer() ⇒
Serializer
- .getRequestTypes() ⇒
Array
- .getResponseTypes() ⇒
Array
- .getEmitTypes() ⇒
Array
- .getStateTypes() ⇒
Array
- .hasLogic() ⇒
boolean
- static
- .fromDirectory(path, [options]) ⇒
Promise.<Template>
- .fromArchive(buffer) ⇒
Promise.<Template>
- .fromUrl(url, options) ⇒
Promise
- .instanceOf(classDeclaration, fqt) ⇒
boolean
- .fromDirectory(path, [options]) ⇒
- .TemplateInstance
- new TemplateInstance(template)
- instance
- .setData(data)
- .getData() ⇒
object
- .getDataAsComposerObject() ⇒
object
- .parse(text, currentTime)
- .generateText() ⇒
string
- .getIdentifier() ⇒
String
- .getTemplate() ⇒
Template
- .getTemplateLogic() ⇒
TemplateLogic
- .toJSON() ⇒
object
- static
- .pad(n, width, z) ⇒
string
- .convertDateTimes(obj, utcOffset) ⇒
*
- .pad(n, width, z) ⇒
- .TemplateLoader
- .loadZipFileContents(zip, path, json, required) ⇒
Promise.<string>
- .loadZipFilesContents(zip, regex) ⇒
Promise.<Array.<object>>
- .loadFileContents(path, fileName, json, required) ⇒
Promise.<string>
- .loadFilesContents(path, regex) ⇒
Promise.<Array.<object>>
- .fromArchive(Template, buffer) ⇒
Promise.<Template>
- .fromUrl(Template, url, options) ⇒
Promise
- .fromDirectory(Template, path, [options]) ⇒
Promise.<Template>
- .loadZipFileContents(zip, path, json, required) ⇒
- .TemplateSaver
- .toArchive(template, [language], [options]) ⇒
Promise.<Buffer>
- .toArchive(template, [language], [options]) ⇒
cicero-core.Clause
A Clause is executable business logic, linked to a natural language (legally enforceable) template. A Clause must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the clause (an instance of the template model) by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.
Kind: static class of cicero-core
Access: public
cicero-core.Contract
A Contract is executable business logic, linked to a natural language (legally enforceable) template. A Clause must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the clause (an instance of the template model) by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.
Kind: static class of cicero-core
Access: public
cicero-core.DateTimeFormatParser
Parses a date/time format string
Kind: static class of cicero-core
Access: public
- .DateTimeFormatParser
- .parseDateTimeFormatField(field) ⇒
string
- .buildDateTimeFormatRule(formatString) ⇒
Object
- .parseDateTimeFormatField(field) ⇒
string
DateTimeFormatParser.parseDateTimeFormatField(field) ⇒ Given a format field (like HH or D) this method returns a logical name for the field. Note the logical names have been picked to align with the moment constructor that takes an object.
Kind: static method of DateTimeFormatParser
Returns: string
- the field designator
Param | Type | Description |
---|---|---|
field | string | the input format field |
Object
DateTimeFormatParser.buildDateTimeFormatRule(formatString) ⇒ Converts a format string to a Nearley action
Kind: static method of DateTimeFormatParser
Returns: Object
- the tokens and action and name to use for the Nearley rule
Param | Type | Description |
---|---|---|
formatString | string | the input format string |
cicero-core.Metadata
Defines the metadata for a Template, including the name, version, README markdown.
Kind: static class of cicero-core
Access: public
- .Metadata
- new Metadata(packageJson, readme, samples, request)
- .getTemplateType() ⇒
number
- .getRuntime() ⇒
string
- .getErgoVersion() ⇒
string
- .getCiceroVersion() ⇒
string
- .satisfiesCiceroVersion(version) ⇒
string
- .getSamples() ⇒
object
- .getRequest() ⇒
object
- .getSample(locale) ⇒
string
- .getREADME() ⇒
String
- .getPackageJson() ⇒
object
- .getName() ⇒
string
- .getKeywords() ⇒
Array
- .getDescription() ⇒
string
- .getVersion() ⇒
string
- .getIdentifier() ⇒
string
- .createTargetMetadata(runtimeName) ⇒
object
new Metadata(packageJson, readme, samples, request)
Create the Metadata.
Note: Only to be called by framework code. Applications should retrieve instances from [Template](Template)
Param | Type | Description |
---|---|---|
packageJson | object | the JS object for package.json (required) |
readme | String | the README.md for the template (may be null) |
samples | object | the sample text for the template in different locales, |
request | object | the JS object for the sample request represented as an object whose keys are the locales and whose values are the sample text. For example: { default: 'default sample text', en: 'sample text in english', fr: 'exemple de texte français' } Locale keys (with the exception of default) conform to the IETF Language Tag specification (BCP 47). THe default key represents sample template text in a non-specified language, stored in a file called sample.txt . |
number
metadata.getTemplateType() ⇒ Returns either a 0 (for a contract template), or 1 (for a clause template)
Kind: instance method of Metadata
Returns: number
- the template type
string
metadata.getRuntime() ⇒ Returns the name of the runtime target for this template, or null if this template has not been compiled for a specific runtime.
Kind: instance method of Metadata
Returns: string
- the name of the runtime
string
metadata.getErgoVersion() ⇒ Returns the Ergo version that the Ergo code in this template is compatible with. This is null for templates that do not contain source Ergo code.
Kind: instance method of Metadata
Returns: string
- the version of Ergo
string
metadata.getCiceroVersion() ⇒ Returns the version of Cicero that this template is compatible with. i.e. which version of the runtime was this template built for? The version string conforms to the semver definition
Kind: instance method of Metadata
Returns: string
- the semantic version
string
metadata.satisfiesCiceroVersion(version) ⇒ Only returns true if the current cicero version satisfies the target version of this template
Kind: instance method of Metadata
Returns: string
- the semantic version
Param | Type | Description |
---|---|---|
version | string | the cicero version to check against |
object
metadata.getSamples() ⇒ Returns the samples for this template.
Kind: instance method of Metadata
Returns: object
- the sample files for the template
object
metadata.getRequest() ⇒ Returns the sample request for this template.
Kind: instance method of Metadata
Returns: object
- the sample request for the template
string
metadata.getSample(locale) ⇒ Returns the sample for this template in the given locale. This may be null. If no locale is specified returns the default sample if it has been specified.
Kind: instance method of Metadata
Returns: string
- the sample file for the template in the given locale or null
Param | Type | Default | Description |
---|---|---|---|
locale | string | null | the IETF language code for the language. |
String
metadata.getREADME() ⇒ Returns the README.md for this template. This may be null if the template does not have a README.md
Kind: instance method of Metadata
Returns: String
- the README.md file for the template or null
object
metadata.getPackageJson() ⇒ Returns the package.json for this template.
Kind: instance method of Metadata
Returns: object
- the Javascript object for package.json
string
metadata.getName() ⇒ Returns the name for this template.
Kind: instance method of Metadata
Returns: string
- the name of the template
Array
metadata.getKeywords() ⇒ Returns the name for this template.
Kind: instance method of Metadata
Returns: Array
- the name of the template
string
metadata.getDescription() ⇒ Returns the description for this template.
Kind: instance method of Metadata
Returns: string
- the description of the template
string
metadata.getVersion() ⇒ Returns the version for this template.
Kind: instance method of Metadata
Returns: string
- the description of the template
string
metadata.getIdentifier() ⇒ Returns the identifier for this template, formed from name@version.
Kind: instance method of Metadata
Returns: string
- the identifier of the template
object
metadata.createTargetMetadata(runtimeName) ⇒ Return new Metadata for a target runtime
Kind: instance method of Metadata
Returns: object
- the new Metadata
Param | Type | Description |
---|---|---|
runtimeName | string | the target runtime name |
cicero-core.ParserManager
Generates and manages a Nearley parser for a template.
Kind: static class of cicero-core
Access: public
- .ParserManager
- new ParserManager(template)
- instance
- .getParser() ⇒
object
- .getTemplateAst() ⇒
object
- .setGrammar(grammar)
- .buildGrammar(templatizedGrammar)
- .buildGrammarRules(ast, templateModel, prefix, parts)
- .handleBinding(templateModel, parts, inputRule, element)
- .cleanChunk(input) ⇒
string
- .findFirstBinding(propertyName, elements) ⇒
int
- .getGrammar() ⇒
String
- .getTemplatizedGrammar() ⇒
String
- .getParser() ⇒
- static
new ParserManager(template)
Create the ParserManager.
Param | Type | Description |
---|---|---|
template | object | the template instance |
object
parserManager.getParser() ⇒ Gets a parser object for this template
Kind: instance method of ParserManager
Returns: object
- the parser for this template
object
parserManager.getTemplateAst() ⇒ Gets the AST for the template
Kind: instance method of ParserManager
Returns: object
- the AST for the template
parserManager.setGrammar(grammar)
Set the grammar for the template
Kind: instance method of ParserManager
Param | Type | Description |
---|---|---|
grammar | String | the grammar for the template |
parserManager.buildGrammar(templatizedGrammar)
Build a grammar from a template
Kind: instance method of ParserManager
Param | Type | Description |
---|---|---|
templatizedGrammar | String | the annotated template |
parserManager.buildGrammarRules(ast, templateModel, prefix, parts)
Build grammar rules from a template
Kind: instance method of ParserManager
Param | Type | Description |
---|---|---|
ast | object | the AST from which to build the grammar |
templateModel | ClassDeclaration | the type of the parent class for this AST |
prefix | String | A unique prefix for the grammar rules |
parts | Object | Result object to acculumate rules and required sub-grammars |
parserManager.handleBinding(templateModel, parts, inputRule, element)
Utility method to generate a grammar rule for a variable binding
Kind: instance method of ParserManager
Param | Type | Description |
---|---|---|
templateModel | ClassDeclaration | the current template model |
parts | * | the parts, where the rule will be added |
inputRule | * | the rule we are processing in the AST |
element | * | the current element in the AST |
string
parserManager.cleanChunk(input) ⇒ Cleans a chunk of text to make it safe to include as a grammar rule. We need to remove linefeeds and escape any '"' characters.
Kind: instance method of ParserManager
Returns: string
- cleaned text
Param | Type | Description |
---|---|---|
input | string | the input text from the template |
int
parserManager.findFirstBinding(propertyName, elements) ⇒ Finds the first binding for the given property
Kind: instance method of ParserManager
Returns: int
- the index of the element or -1
Param | Type | Description |
---|---|---|
propertyName | string | the name of the property |
elements | Array.<object> | the result of parsing the template_txt. |
String
parserManager.getGrammar() ⇒ Get the (compiled) grammar for the template
Kind: instance method of ParserManager
Returns: String
- - the grammar for the template
String
parserManager.getTemplatizedGrammar() ⇒ Returns the templatized grammar
Kind: instance method of ParserManager
Returns: String
- the contents of the templatized grammar
*
ParserManager.getProperty(templateModel, propertyName) ⇒ Throws an error if a template variable doesn't exist on the model.
Kind: static method of ParserManager
Returns: *
- the property
Param | Type | Description |
---|---|---|
templateModel | * | the model for the template |
propertyName | String | the name of the property |
object
ParserManager.compileGrammar(sourceCode) ⇒ Compiles a Nearley grammar to its AST
Kind: static method of ParserManager
Returns: object
- the AST for the grammar
Param | Type | Description |
---|---|---|
sourceCode | string | the source text for the grammar |
cicero-core.Template
A template for a legal clause or contract. A Template has a template model, request/response transaction types, a template grammar (natural language for the template) as well as Ergo code for the business logic of the template.
Kind: static abstract class of cicero-core
Access: public
- .Template
- new Template(packageJson, readme, samples, request)
- instance
- .validate()
- .getTemplateModel() ⇒
ClassDeclaration
- .getIdentifier() ⇒
String
- .getMetadata() ⇒
Metadata
- .getName() ⇒
String
- .getVersion() ⇒
String
- .getDescription() ⇒
String
- .getHash() ⇒
string
- .toArchive([language], [options]) ⇒
Promise.<Buffer>
- .getParserManager() ⇒
ParserManager
- .getTemplateLogic() ⇒
TemplateLogic
- .getIntrospector() ⇒
Introspector
- .getFactory() ⇒
Factory
- .getSerializer() ⇒
Serializer
- .getRequestTypes() ⇒
Array
- .getResponseTypes() ⇒
Array
- .getEmitTypes() ⇒
Array
- .getStateTypes() ⇒
Array
- .hasLogic() ⇒
boolean
- static
- .fromDirectory(path, [options]) ⇒
Promise.<Template>
- .fromArchive(buffer) ⇒
Promise.<Template>
- .fromUrl(url, options) ⇒
Promise
- .instanceOf(classDeclaration, fqt) ⇒
boolean
- .fromDirectory(path, [options]) ⇒
new Template(packageJson, readme, samples, request)
Create the Template. Note: Only to be called by framework code. Applications should retrieve instances from Template.fromArchive or Template.fromDirectory.
Param | Type | Description |
---|---|---|
packageJson | object | the JS object for package.json |
readme | String | the readme in markdown for the template (optional) |
samples | object | the sample text for the template in different locales |
request | object | the JS object for the sample request |
template.validate()
Verifies that the template is well formed. Throws an exception with the details of any validation errors.
Kind: instance method of Template
ClassDeclaration
template.getTemplateModel() ⇒ Returns the template model for the template
Kind: instance method of Template
Returns: ClassDeclaration
- the template model for the template
Throws:
Error
if no template model is found, or multiple template models are found
String
template.getIdentifier() ⇒ Returns the identifier for this template
Kind: instance method of Template
Returns: String
- the identifier of this template
Metadata
template.getMetadata() ⇒ Returns the metadata for this template
Kind: instance method of Template
Returns: Metadata
- the metadata for this template
String
template.getName() ⇒ Returns the name for this template
Kind: instance method of Template
Returns: String
- the name of this template
String
template.getVersion() ⇒ Returns the version for this template
Kind: instance method of Template
Returns: String
- the version of this template. Use semver module
to parse.
String
template.getDescription() ⇒ Returns the description for this template
Kind: instance method of Template
Returns: String
- the description of this template
string
template.getHash() ⇒ Gets a content based SHA-256 hash for this template. Hash is based on the metadata for the template plus the contents of all the models and all the script files.
Kind: instance method of Template
Returns: string
- the SHA-256 hash in hex format
Promise.<Buffer>
template.toArchive([language], [options]) ⇒ Persists this template to a Cicero Template Archive (cta) file.
Kind: instance method of Template
Returns: Promise.<Buffer>
- the zlib buffer
Param | Type | Description |
---|---|---|
[language] | string | target language for the archive (should be 'ergo') |
[options] | Object | JSZip options |
ParserManager
template.getParserManager() ⇒ Provides access to the parser manager for this template. The parser manager can convert template data to and from natural language text.
Kind: instance method of Template
Returns: ParserManager
- the ParserManager for this template
TemplateLogic
template.getTemplateLogic() ⇒ Provides access to the template logic for this template. The template logic encapsulate the code necessary to execute the clause or contract.
Kind: instance method of Template
Returns: TemplateLogic
- the TemplateLogic for this template
Introspector
template.getIntrospector() ⇒ Provides access to the Introspector for this template. The Introspector is used to reflect on the types defined within this template.
Kind: instance method of Template
Returns: Introspector
- the Introspector for this template
Factory
template.getFactory() ⇒ Provides access to the Factory for this template. The Factory is used to create the types defined in this template.
Kind: instance method of Template
Returns: Factory
- the Factory for this template
Serializer
template.getSerializer() ⇒ Provides access to the Serializer for this template. The Serializer is used to serialize instances of the types defined within this template.
Kind: instance method of Template
Returns: Serializer
- the Serializer for this template
Array
template.getRequestTypes() ⇒ Provides a list of the input types that are accepted by this Template. Types use the fully-qualified form.
Kind: instance method of Template
Returns: Array
- a list of the request types
Array
template.getResponseTypes() ⇒ Provides a list of the response types that are returned by this Template. Types use the fully-qualified form.
Kind: instance method of Template
Returns: Array
- a list of the response types
Array
template.getEmitTypes() ⇒ Provides a list of the emit types that are emitted by this Template. Types use the fully-qualified form.
Kind: instance method of Template
Returns: Array
- a list of the emit types
Array
template.getStateTypes() ⇒ Provides a list of the state types that are expected by this Template. Types use the fully-qualified form.
Kind: instance method of Template
Returns: Array
- a list of the state types
boolean
template.hasLogic() ⇒ Returns true if the template has logic, i.e. has more than one script file.
Kind: instance method of Template
Returns: boolean
- true if the template has logic
Promise.<Template>
Template.fromDirectory(path, [options]) ⇒ Builds a Template from the contents of a directory. The directory must include a package.json in the root (used to specify the name, version and description of the template).
Kind: static method of Template
Returns: Promise.<Template>
- a Promise to the instantiated template
Param | Type | Description |
---|---|---|
path | String | to a local directory |
[options] | Object | an optional set of options to configure the instance. |
Promise.<Template>
Template.fromArchive(buffer) ⇒ Create a template from an archive.
Kind: static method of Template
Returns: Promise.<Template>
- a Promise to the template
Param | Type | Description |
---|---|---|
buffer | Buffer | the buffer to a Cicero Template Archive (cta) file |
Promise
Template.fromUrl(url, options) ⇒ Create a template from an URL.
Kind: static method of Template
Returns: Promise
- a Promise to the template
Param | Type | Default | Description |
---|---|---|---|
url | String | the URL to a Cicero Template Archive (cta) file | |
options | object |
| additional options |
boolean
Template.instanceOf(classDeclaration, fqt) ⇒ Check to see if a ClassDeclaration is an instance of the specified fully qualified type name.
Kind: static method of Template
Returns: boolean
- True if classDeclaration an instance of the specified fully
qualified type name, false otherwise.
Internal:
Param | Type | Description |
---|---|---|
classDeclaration | ClassDeclaration | The class to test |
fqt | String | The fully qualified type name. |
cicero-core.TemplateInstance
A TemplateInstance is an instance of a Clause or Contract template. It is executable business logic, linked to a natural language (legally enforceable) template. A TemplateInstance must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the TemplateInstance by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.
Kind: static abstract class of cicero-core
Access: public
- .TemplateInstance
- new TemplateInstance(template)
- instance
- .setData(data)
- .getData() ⇒
object
- .getDataAsComposerObject() ⇒
object
- .parse(text, currentTime)
- .generateText() ⇒
string
- .getIdentifier() ⇒
String
- .getTemplate() ⇒
Template
- .getTemplateLogic() ⇒
TemplateLogic
- .toJSON() ⇒
object
- static
- .pad(n, width, z) ⇒
string
- .convertDateTimes(obj, utcOffset) ⇒
*
- .pad(n, width, z) ⇒
new TemplateInstance(template)
Create the Clause and link it to a Template.
Param | Type | Description |
---|---|---|
template | Template | the template for the clause |
templateInstance.setData(data)
Set the data for the clause
Kind: instance method of TemplateInstance
Param | Type | Description |
---|---|---|
data | object | the data for the clause, must be an instance of the template model for the clause's template. This should be a plain JS object and will be deserialized and validated into the Composer object before assignment. |
object
templateInstance.getData() ⇒ Get the data for the clause. This is a plain JS object. To retrieve the Composer object call getComposerData().
Kind: instance method of TemplateInstance
Returns: object
- - the data for the clause, or null if it has not been set
object
templateInstance.getDataAsComposerObject() ⇒ Get the data for the clause. This is a Composer object. To retrieve the
plain JS object suitable for serialization call toJSON() and retrieve the data
property.
Kind: instance method of TemplateInstance
Returns: object
- - the data for the clause, or null if it has not been set
templateInstance.parse(text, currentTime)
Set the data for the clause by parsing natural language text.
Kind: instance method of TemplateInstance
Param | Type | Description |
---|---|---|
text | string | the data for the clause |
currentTime | string | the definition of 'now' (optional) |
string
templateInstance.generateText() ⇒ Generates the natural language text for a clause; combining the text from the template and the clause data.
Kind: instance method of TemplateInstance
Returns: string
- the natural language text for the clause; created by combining the structure of
the template with the JSON data for the clause.
String
templateInstance.getIdentifier() ⇒ Returns the identifier for this clause. The identifier is the identifier of the template plus '-' plus a hash of the data for the clause (if set).
Kind: instance method of TemplateInstance
Returns: String
- the identifier of this clause
Template
templateInstance.getTemplate() ⇒ Returns the template for this clause
Kind: instance method of TemplateInstance
Returns: Template
- the template for this clause
TemplateLogic
templateInstance.getTemplateLogic() ⇒ Returns the template logic for this clause
Kind: instance method of TemplateInstance
Returns: TemplateLogic
- the template for this clause
object
templateInstance.toJSON() ⇒ Returns a JSON representation of the clause
Kind: instance method of TemplateInstance
Returns: object
- the JS object for serialization
string
TemplateInstance.pad(n, width, z) ⇒ Left pads a number
Kind: static method of TemplateInstance
Returns: string
- the left padded string
Param | Type | Default | Description |
---|---|---|---|
n | * | the number | |
width | * | the number of chars to pad to | |
z | string | "0" | the pad character |
*
TemplateInstance.convertDateTimes(obj, utcOffset) ⇒ Recursive function that converts all instances of ParsedDateTime to a Moment.
Kind: static method of TemplateInstance
Returns: *
- the converted object
Param | Type | Description |
---|---|---|
obj | * | the input object |
utcOffset | number | the default utcOffset |
cicero-core.TemplateLoader
A utility class to create templates from data sources.
Kind: static abstract class of cicero-core
Interal:
- .TemplateLoader
- .loadZipFileContents(zip, path, json, required) ⇒
Promise.<string>
- .loadZipFilesContents(zip, regex) ⇒
Promise.<Array.<object>>
- .loadFileContents(path, fileName, json, required) ⇒
Promise.<string>
- .loadFilesContents(path, regex) ⇒
Promise.<Array.<object>>
- .fromArchive(Template, buffer) ⇒
Promise.<Template>
- .fromUrl(Template, url, options) ⇒
Promise
- .fromDirectory(Template, path, [options]) ⇒
Promise.<Template>
- .loadZipFileContents(zip, path, json, required) ⇒
Promise.<string>
TemplateLoader.loadZipFileContents(zip, path, json, required) ⇒ Loads a required file from the zip, displaying an error if missing
Kind: static method of TemplateLoader
Returns: Promise.<string>
- a promise to the contents of the zip file or null if it does not exist and
required is false
Internal:
Param | Type | Default | Description |
---|---|---|---|
zip | * | the JSZip instance | |
path | string | the file path within the zip | |
json | boolean | false | if true the file is converted to a JS Object using JSON.parse |
required | boolean | false | whether the file is required |
Promise.<Array.<object>>
TemplateLoader.loadZipFilesContents(zip, regex) ⇒ Loads the contents of all files in the zip that match a regex
Kind: static method of TemplateLoader
Returns: Promise.<Array.<object>>
- a promise to an array of objects with the name and contents of the zip files
Internal:
Param | Type | Description |
---|---|---|
zip | * | the JSZip instance |
regex | RegExp | the regex to use to match files |
Promise.<string>
TemplateLoader.loadFileContents(path, fileName, json, required) ⇒ Loads a required file from a directory, displaying an error if missing
Kind: static method of TemplateLoader
Returns: Promise.<string>
- a promise to the contents of the file or null if it does not exist and
required is false
Internal:
Param | Type | Default | Description |
---|---|---|---|
path | * | the root path | |
fileName | string | the relative file name | |
json | boolean | false | if true the file is converted to a JS Object using JSON.parse |
required | boolean | false | whether the file is required |
Promise.<Array.<object>>
TemplateLoader.loadFilesContents(path, regex) ⇒ Loads the contents of all files under a path that match a regex Note that any directories called node_modules are ignored.
Kind: static method of TemplateLoader
Returns: Promise.<Array.<object>>
- a promise to an array of objects with the name and contents of the files
Internal:
Param | Type | Description |
---|---|---|
path | * | the file path |
regex | RegExp | the regex to match files |
Promise.<Template>
TemplateLoader.fromArchive(Template, buffer) ⇒ Create a template from an archive.
Kind: static method of TemplateLoader
Returns: Promise.<Template>
- a Promise to the template
Param | Type | Description |
---|---|---|
Template | * | the type to construct |
buffer | Buffer | the buffer to a Cicero Template Archive (cta) file |
Promise
TemplateLoader.fromUrl(Template, url, options) ⇒ Create a template from an URL.
Kind: static method of TemplateLoader
Returns: Promise
- a Promise to the template
Param | Type | Description |
---|---|---|
Template | * | the type to construct |
url | String | the URL to a Cicero Template Archive (cta) file |
options | object | additional options |
Promise.<Template>
TemplateLoader.fromDirectory(Template, path, [options]) ⇒ Builds a Template from the contents of a directory. The directory must include a package.json in the root (used to specify the name, version and description of the template).
Kind: static method of TemplateLoader
Returns: Promise.<Template>
- a Promise to the instantiated template
Param | Type | Description |
---|---|---|
Template | * | the type to construct |
path | String | to a local directory |
[options] | Object | an optional set of options to configure the instance. |
cicero-core.TemplateSaver
A utility to persist templates to data sources.
Kind: static class of cicero-core
Internal:
Promise.<Buffer>
TemplateSaver.toArchive(template, [language], [options]) ⇒ Persists this template to a Cicero Template Archive (cta) file.
Kind: static method of TemplateSaver
Returns: Promise.<Buffer>
- the zlib buffer
Param | Type | Description |
---|---|---|
template | Template | the template to persist |
[language] | string | target language for the archive (should be 'ergo') |
[options] | Object | JSZip options |