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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gulp-htmlrender

v0.3.0

Published

Render html files from relative partials

Readme

gulp-htmlrender

Install

$ npm install --save-dev gulp-htmlrender

Basic usage

src/index.html

<div class="main">
	<%include src="layout/header.html"%>
</div>

src/layout/header.html

<h3 class="header">Hello!</h3>

gulpfile.js

var gulp = require('gulp');
var htmlrender = require('gulp-htmlrender');

gulp.task('render', function() {
	return gulp.src('src/index.html', {read: false})
		.pipe(htmlrender.render())
		.pipe(gulp.dest('dist'));
});

gulp.task('default', function() {
	gulp.watch(['src/**/*.html'], ['render']);
});

dist/index.html

<div class="main">
	<h3 class="header">Hello!</h3>
</div>

Glob patterns for src attribute of include tag

Glob patterns can be used to include more than one partial at once. All included files will be separated with \n delimiter.

<div class="main">
	<%include src="layout/**/*.html"%>
</div>

Custom templates - AngularJS inlined template example

Custom tags can be defined to render more complicated content.

src/index.html

<body>
	<%template id="tpl/some-template" src="modules/some-template.html"%>
</body>

src/modules/some-template.html

<div>Some template</div>

gulpfile.js

var gulp = require('gulp');
var htmlrender = require('gulp-htmlrender');

htmlrender.addTemplate('template', 
	'<script id="{{id}}" type="text/ng-template">'+
		'<%include src="{{src}}"%>'+
	'</script>');

gulp.task('render', function() {
	return gulp.src('src/index.html', {read: false})
		.pipe(htmlrender.render())
		.pipe(gulp.dest('dist'));
});

dist/index.html

<body>
	<script id="tpl/some-template" type="text/ng-template">
		<div>Some template</div>
	</script>
</body>

Modifying partials before rendering

Before each rendering phase, some individual partials can be decorated and pushed in the renderer cache. You can pipe custom gulp plugins directly before htmlrenderer.cache() invocation.

gulpfile.js

var gulp = require('gulp');
var htmlrender = require('gulp-htmlrender');
var removeHtmlComments = require('gulp-remove-html-comments');

gulp.task('decorate', function() {
	return gulp.src('src/index.html')
		.pipe(removeHtmlComments())
		.pipe(htmlrender.cache());
});

gulp.task('render', ['decorate'], function() {
	return gulp.src('src/index.html', {read: false})
		.pipe(htmlrender.render())
		.pipe(gulp.dest('dist'));
});

Decorating with static and dynamic variables

More advanced decoration allows to render inlined variables inside of partials.

src/index.html

<div class="version"><%=version%></div>
<div class="timestamp"><%=timestamp%></div>

gulpfile.js

var gulp = require('gulp');
var htmlrender = require('gulp-htmlrender');

gulp.task('decorate', function() {
	return gulp.src('src/index.html')
		.pipe(htmlrender.decorator().
			.vars({
				version: '2.0.1',
				timestamp: function() {
					return new Date().getTime()
				}
			}).apply())
		.pipe(htmlrender.cache());
});

gulp.task('render', ['decorate'], function() {
	return gulp.src('src/index.html', {read: false})
		.pipe(htmlrender.render())
		.pipe(gulp.dest('dist'));
});

dist/index.html

<div class="version">2.0.1</div>
<div class="timestamp">1443219469588</div>

Chaining multiple decorators

gulpfile.js

gulp.task('decorate', function() {
	return gulp.src('src/index.html')
		.pipe(htmlrender.decorator()
			.vars({
				staticVar: 'value',
				dynamicVar: function() {
					return 'value'
				}
			})
			.fn(function(content) {
				return '<div>' + content + '</div>';
			})
			.apply())
		.pipe(htmlrender.cache());
});

Transforming included content at render phase

Transform functions can be defined to modify included partial before rendering.

src/templates.yaml

tpl/main-view: ../layout/main.html
tpl/modal-view: ../layout/modal.html

src/index.html

<%include src="templates.yaml" transform="yaml2html"%>

gulpfile.js

htmlrender.addTransform('yaml2html', function(yamlString) {
	var yamlObject = yamljs.parse(yamlString);
	return _.map(yamlObject, function(tpl, id) { 
		return '<script id="' + id + '"><%include src="' + tpl + '"%></script>';
	})
});

gulp.task('render', function() {
	return gulp.src('src/index.html', {read: false})
		.pipe(htmlrender.render())
		.pipe(gulp.dest('dist'));
});

src/index.html transformed

The following content will be saved in partials cache. During rendering all includes will be resolved to referenced files.

<script id="tpl/main-view"><%include src="../layout/main.html"%></script>
<script id="tpl/modal-view"><%include src="../layout/modal.html"%></script>

API

render()

cache()

decorator()

addTemplate()

addTransform()

Release history

0.3.0

  1. Glob patterns in src attribute for include tag
  2. Transforming functions with declarative usage

0.2.0

  1. Custom templates
  2. Decorating partials before putting to the cache

License

MIT © Sebastian Kuligowski