fly-ng-templatecache

2.1.0 • Public • Published

fly-ng-templatecache

Concatenate and register Angular JS templates in the $templateCache, with [Fly][fly].

Install

npm install --save-dev fly-ng-templatecache

Usage

exports.views = function * (fly) {
  yield fly.source('templates/**/*.html')
    .ngTemplates({
      file: 'views.js',
      standalone: true,
      moduleName: 'app.templates'
    })
    .target('dist/js');
}

API

.ngTemplates(options)

options.file

Type: string
Default: templates.js

The name of the file that will be place in your target() destination. Do not include a directory structure here.

options.moduleName

Type: string
Default: 'templates'

The name of your Angular JS module or submodule.

options.moduleType

Type: string
Default: null
Options: 'iffe', 'requirejs', 'browserify', 'es6'

The module system for which your module should be prepared.

options.standalone

Type: boolean
Default: false

If true, creates a new Angular JS module. If false, it is assumed that you are using an existing module.

options.templateHeader

Type: string
Default: angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {

This precedes your template content and will correctly initialize your Angular module. It is not recommended you change this, but if you do, you must retain the <%= module %> variable.

If the standalone option is true, an empty dependency array ([]) will replace <%= standalone %>.

options.templateContent

Type: string
Default: $templateCache.put("<%= url %>","<%= contents %>");

The template wrapper for each view's content. It is not recommended to change this.

options.templateFooter

Type: string
Default: }]);

This is appended to your module file. There probably is no reason to change this.

options.trim

Type: function or string
Default: ''

A function that handles or alters your views' reference URLs. If using string, the value will simply be removed.

.ngTemplates({
  trim: str => str.replace('app/views', 'views');
})
//=> ng-include="views/demo.html"
//=> INSTEAD OF
//=> ng-include="app/views/demo.html"

License

MIT © Luke Edwards

Package Sidebar

Install

npm i fly-ng-templatecache

Weekly Downloads

5

Version

2.1.0

License

MIT

Last publish

Collaborators

  • lukeed