npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-template-cache

v1.3.3

Published

cli tool to put your html files into angular's $templateCache service

Downloads

15,758

Readme

angular-template-cache

Build Status dependencies Status devDependencies Status

Grabs all your html files into angular $templateCache and stores them in single file.

Features

  • can be run from command line (for example as npm script)
  • can be required from another script
  • can print output to stdout or to a file
  • supports html minification
  • allows to define you own prefix and suffix
  • should generate valid js file (no more .jshintignore)
  • has support for typescript

Usage

Command line

Usage: nghtml2js [options] -- [fileList...]

Examples:

node_modules/.bin/nghtml2js -m 'reporter.template' -s es2015 -f 'src/**/*.html' -p src/ -o src/template.js
node_modules/.bin/nghtml2js -m 'reporter.template' -s es2015 -f -p src/ -o src/template.js -- src/file1.html src/file2.htm
node_modules/.bin/nghtml2js   # will load all **html files from current folder 

More examples can be found in tests

Options:

fileList files to put in templateCache. File list must be provided after --

-f, --files <glob pattern> Glob (https://github.com/isaacs/node-glob) pattern to find html files. To make it work in console you must put pattern in quote. Otherwise bash will break pattern

When input file list is provided and glob pattern is present then files found for glob pattern and input files will be merged.

-o, --output [output file] File in which output should be saved (will overwrite existing file content). Will print to console if not file provided.

-p, --base-path [path] Base path to be used in you html files put into $templateCache service. For example you files are in physically stored app/src/html but you serve them from app folder. You can set base path to app/ and paths to the files will be fixed

-i, --ignore-missing Do not fail when file from fileList doesn't exist or can not be loaded. When option is active missing files will not be present in generated template file

-m, --module-name Name of the module to import in your application. 'templates' is default module name.

--service-type [service type] The Typescript type of the AngularJS $templateCache service, to generate a file compliant with strict Typescript settings.

--no-html-min Will disable html minification (https://github.com/kangax/html-minifier). All Options prefixed with --htmlmin- will be passed directly to html-minifier. For example: --htmlmin-minifyCSS will be passed as minifyCSS option to html-minifier. When you want to disable features of html-minifier then add -no- infix. For example to disable html5 processsing pass --htmlmin-no-html5 or --htmlmin-no-includeAutoGeneratedTags. See test/htmlminOptionsParser.spec.js for examples

--no-new-module should skip new module creation. Will generate: .module('templates') By default new module is created: .module('templates', [])

--no-strict Skip 'use strict'; in generated file

--header [header content] Custom header in the generated file. Just below use strict.

--prefix Custom prefix to be used in code. When provided --module and --no-new-module options are ignored Default prefix depends on --style for browser:

angular
  .module(/*...*/)
  .run(/*...*/);

for browserify:

var templatesModule = require('angular')
  .module(/*...*/)
  .run(/*...*/);
  
module.exports = templatesModule;

for es2015:

import angular from 'angular';

const templatesModule = angular
     .module(/*...*/)
     .run(/*...*/);
     
export default templatesModule;

--suffix [suffix] Custom suffix to be used in code. Default prefix depends on --style option

--quotmark [quotmark type] qutotation mark to use in generated code. Possible options: single|double single by default

--whitespace [whitespace type] Whitespace to use. Possible options: tabs|spaces tabs bt default

-h, --help prints help

-s, --style [style] Code style to generate. Possible options are:

browser:

'use strict';

// file automatically generated by angular-template-cache

angular
.module('templates', [])
.run(['$templateCache', function($templateCache) {
    $templateCache.put('test-it/first.html', '<style>\n' +
        '	p {\n' +
        '		background: red;\n' +
        '	}\n' +
        '</style>\n' +
        '\n' +
        '<p class="custom class">\n' +
        '	Custom file\n' +
        '</p>');

    $templateCache.put('test-it/second.html', '<script>\n' +
        '	alert(\'hello world\')\n' +
        '</script>\n' +
        '\n' +
        '<div>\n' +
        '	<b>hello</b>\n' +
        '</div>');
}
]);

browserify:

'use strict';

// file automatically generated by angular-template-cache

var templatesModule = require('angular')
.module('templates', [])
.run(['$templateCache', function($templateCache) {
    $templateCache.put('test-it/first.html', '<style>\n' +
        '	p {\n' +
        '		background: red;\n' +
        '	}\n' +
        '</style>\n' +
        '\n' +
        '<p class="custom class">\n' +
        '	Custom file\n' +
        '</p>');

    $templateCache.put('test-it/second.html', '<script>\n' +
        '	alert(\'hello world\')\n' +
        '</script>\n' +
        '\n' +
        '<div>\n' +
        '	<b>hello</b>\n' +
        '</div>');
}
]);

module.exports = templatesModule;

es2015:

'use strict';

// file automatically generated by angular-template-cache

import angular from 'angular';

const templatesModule = angular
.module('templates', [])
.run(['$templateCache', function($templateCache) {
    $templateCache.put('test-it/first.html', '<style>\n' +
        '	p {\n' +
        '		background: red;\n' +
        '	}\n' +
        '</style>\n' +
        '\n' +
        '<p class="custom class">\n' +
        '	Custom file\n' +
        '</p>');

    $templateCache.put('test-it/second.html', '<script>\n' +
        '	alert(\'hello world\')\n' +
        '</script>\n' +
        '\n' +
        '<div>\n' +
        '	<b>hello</b>\n' +
        '</div>');
}
]);

export default templatesModule;

Changes

1.3.3

  • Lodash bump

1.3.2

  • Removed security warnings from npm audit (thx @Ersel Aker)
  • Dropped support for nodejs 0.12 and 4.x

1.3.1

1.3.0

  • added option service-type - typescript type of the AngularJS $templateCache service (thx @lmartorella)
  • dependencies update

1.2.0

  • specify list of files (#3) - file list to be transofmred can be provided instead fo glob pattern
  • --ignore-missing option added. In case of file can not be read, or doesn't exists it's possible to proceed with template.js generation

1.1.0

Html minification supoort

1.0.1

Readme fixtures

1.0.0

Initial release