@blinkmobile/forms-template-helper v1.0.0
Forms CLI Template Helper
A collection of functions to help making a Framework plugin for the Blink Mobile Technologies Forms CLI easier.
See The AngularJS package for a detailed implementation.
Installation
Install this module as part of your plugin code:
npm i --save @blinkmobile/forms-template-helper
Then require the module where needed and use the exposed API functions
API
The template helper exposes the following functions via an object. The majority of function are wrapped by the functions provided by "service", but are exposed for convenience
makeTemplateStore
makeTemplateStore(templatePath: string) => Promise
Reads the folder/file structure from templatePath
and creates the Templates. Templates in the root templatePath
are the default templates. Folders represent forms, with the templates contained in the folders overriding the default templates of the same name.
service
Deprecated. Will be removed before next release Object containing two functions that wrap most the below functions.
- load (templatePath) => Promise(<Array<MustacheRenderers>)
- Loads all templates in a given path. Sub folders are treated as 'types', eg a folder structure of
|-templates
| |-html
| | |-text.mustache
| |-js
| | |-controller.js.mustache
results in two types of templates, "html" and "js"
- getByType (type) => Array<object>
- returns an object where the key is the name of the file (minus the .mustache part) and the value is a Mustache Renderer, "primed" with the template
fileListHelper
Object containing helper functions for getting lists of files.
- getFileList(path <string>) => Promise(Array<string>)
- Gets a list of files from the specified path
- getFolderList(path <string>) => Promise(Array<string>)
- Gets a list of folders from the specified path
readFileContents
readFileContents(path-to-file <string>) => Promise(contents <string>)
Asynchronously reads the contents of a file and resolves with the contents of the file.
mustacheRenderer
Object containing helper functions to prime a mustache template with the contents of a mustache file
- renderer (template<string>) => (data<object>) => <string>
- Returns a function that accepts an object of data, lazily runs mustache on the initial template with the data
- createRenderer (filePath<string>) => (data<object>) => <string>
- Takes a path to a mustache file and reads the file, passing the template to the above
renderer
function, returning the result
- Takes a path to a mustache file and reads the file, passing the template to the above
writeFile
writeFile(filePath<string>, contents<string>) => Promise(filePath<string>)
Writes contents
to path
. Will recursively create the path if it doesn't exist
lazyWriteFile
lazyWriteFile (filePath<string>, contents<string>) => (basePath = '') => writeFile
Same as writeFile but returns a function that will write the file to basePath
when run
writeTemplates
writeTemplates (srcFolder<string>, destFolder<string>)
Used by the forms transformer during initialisation to copy the templates into the forms project folder.
srcFolder
is where in your plugin project the template files are, destFolder
is where they will be copied to. Note that all contents of destFolder
are removed.
See the docs/ folder for specific implementation details
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago