gulp-template-generator

1.0.1 • Public • Published

Build Status

Information

Packagegulp-template-generator
Description Template tags in HTML are destructive - they ruin your HTML. If you wanted to work with your HTML after adding template tags then you have to remove all the template tags, or you're forced to use your web application so that the template tags are parsed. There's a better way! Wouldn't it be better if you could use static HTML whilst your developing your frontend, but then also add the templating tags required to make your HTML dynamic when it's used by your web application. This gulp plugin lets you do this and toggle between the two (static HTML or template tags).
Node Version >= 0.10

Usage

var generateTemplate = require('gulp-template-generator');
 
gulp.task('generate-template', function() {
 
  return gulp.src('./static/html/*.html')
    .pipe(generateTemplate('static')) //either 'static' or 'template'
    .pipe(gulp.dest('./dist/'));
});

HTML COMMENTS

In your HTML you can tell the gulp plugin what to add and remove when it runs. Anything in a

<!--DEL--><!--/DEL-->

comment will be removed.

Anything in a

<!--ADD--><!--/ADD-->

comment will be added.

EXAMPLE

The following example contains both static HTML (great for developing) and template tags:

<h2><!--DEL-->This is the title<!-- /DEL --><!-- ADD--><% title %><!--/ADD--></h2>
 
<!--ADD-->
  <strong>some emphasised text</strong>
<!--/ADD-->
<ul>
  <!--ADD--><% for each item in list %>   <!--/ADD--> <li><!--DEL-->This is the first item in the list<!--/DEL--><!--ADD--><% item %><!--/ADD--></li><!--ADD--><% end for %><!--   /ADD -->
  <!--DEL--><li>This is the second item in the list</li><!--/DEL -->
  <!--DEL--><li>This is the <strong>third</strong> item in the list</li><!-- /DEL    -->
</ul>

When using generateTemplate('static'), this will render as:

<h2>This is the title</h2>
 
<ul>
  <li>This is the first item in the list</li>
  <li>This is the second item in the list</li>
  <li>This is the <strong>third</strong> item in the list</li>
</ul>

When using generateTemplate('template'), this will render as:

<h2><% title %></h2>
 
  <strong>some emphasised text</strong>
<ul>
  <% for each item in list %><li><% item %></li><% end for %>
</ul>

LICENSE

(MIT License)

Copyright (c) 2015 Richard Willars (richard@richardwillars.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i gulp-template-generator

Weekly Downloads

3

Version

1.0.1

License

none

Last publish

Collaborators

  • richwillars