html-tag-helpers

0.1.4 • Public • Published

html-tag-helpers NPM version

Easily generate helpers for creating HTML tags. Works great as handlebars helpers or vanilla javascript utils.

Install

Install with npm:

npm i html-tag-helpers --save-dev

Usage

Create a new instance of Tags:

var Tags = require('html-tag-helpers');
var html = new Tags();

Tags

Generate a function to create any HTML tag:

var apple = html.addTag('apple');
 
// pass text as the first parameter, and an object of
// attributes as the second param.
console.log(apple('a', {href: 'b'})
//=> '<apple href="b">a</apple>'
 
// or pass text as a property
console.log(apple({href: 'b', text: 'a'})
//=> '<apple href="b">a</apple>'

Default attributes

Pass default attributes as a second paramter:

var css = html.addTag('link', {rel: 'stylesheet'});
console.log(css({href: 'styles.css'}));
//=> <link href="styles.css" rel="stylesheet">

As Handlebars helpers

To create a handlebars helper:

Handlebars.registerHelper('orange', tag.addTag('orange'));
 
var tmpl = Handlebars.compile('{{{orange "This is text" href=link}}}');
console.log(tmpl({link: 'about/us.html'}));
//=> '<orange href="about/us.html">This is text</orange>'

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on August 21, 2014.

Package Sidebar

Install

npm i html-tag-helpers

Weekly Downloads

1

Version

0.1.4

License

none

Last publish

Collaborators

  • doowb
  • jonschlinkert