Skip to content

Gulp plugin for building HTML files into each other. Made for a workflow involving responsive unit testing.

License

Notifications You must be signed in to change notification settings

melono6/gulp-html-ssi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-html-ssi

NPM version Dependency Status

gulp-html-ssi plugin for gulp

Introduction

gulp-html-ssi allows you to compile your html files with includes.

gulp-html-ssi looks through your files for special html comments that it will use to parse them and do the include correctly.

Usage

Install

npm install --save-dev gulp-html-ssi

Sample gulpfile.js

Then, add it to your gulpfile.js:

var gulp = require('gulp'),
	includer = require('gulp-html-ssi');

gulp.task('htmlSSI', function() {
	gulp.src('./source/**/*.html')
		.pipe(includer())
		.pipe(gulp.dest('./build/'));
});

gulp.task('default', ['htmlSSI']);

gulp.task('watch', function() {
	gulp.watch(['./source/**/*.html'], function(event) {
		gulp.start('default');
	});
});

API

Include

This is the simplest use case. Simply put the following html comment

<!-- #include file="_filename" -->

or

<!-- #include virtual="_filename" -->

Templating

String replace

<!-- #include file="_filename" name="jason" job="developer"-->

<h1>{{name}}</h1>
<p>{{job}}</p>

Conditional rendering

<!-- #include file="_filename" truevalue="true" -->

{{?truevalue}}
	<p>Render this if true</p>
{{:else}}
	<p>else render this</p>
{{/truevalue}}

arrays

Can either take a comma seperated string or an object <!-- #include file="_filename" colours="red,green,blue" -->

{{#colours}}
	<p>{{value}}</p>
{{/colours}}

<!-- #include file="_filename" colours="[{'colour': 'red','hex':'#d0021b'},{'colour':'green','hex':'#40a22a'},{'colour':'blue','hex':'#193351'}]" -->

{{#colours}}
	<p>{{colour}}: {{hex}}</p>
{{/colours}}

Example

file1.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
<!-- #include file="__file2.html" -->
</body>
</html>

__file2.html

  hello world

Results

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  hello world
</body>
</html>

License

MIT License

About

Gulp plugin for building HTML files into each other. Made for a workflow involving responsive unit testing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%