Skip to content
A gulp plugin that converts a html file into a ts file containing an object with html as string template.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
samples
.gitignore
README.md
gulpfile.js
index.js
package.json

README.md

HTML template to TS

This gulp plugin converts a html file with into a ts file containing an object with string template.

Writing template inside a structured HTML file is much more practical than in a one line javascript string. Therefore this plugin turns a HTML file with templates into a js object. You can use whatever template language you like it simply turns the html nodes into a js string. It will take the html name file to named module and property html as string value.

Usage

An example usage with gulp:

var gulp        = require('gulp');
var html2ts = require('gulp-html-to-ts');

gulp.task('template', function() {
	return gulp.src('my/template.html')
	.pipe(html2ts())
  //.pipe(html2ts('app'))
  //.pipe(html2ts({ moduleName: '{$folderName}', propertyName: '{$fileName}Html'}))
	.pipe(gulp.dest('./')); 
});

Example

This example shows how this plugin turn html into a ts file.

HTML Source : mytemplate.html

  <p>A {{ handlebar }} example.</p>

The generated output : mytemplate.html.ts

module mytemplate { export var html = '<p>A {{ handlebar }} example.</p>';}
You can’t perform that action at this time.