Tagster
Tagster is simple library which is helping you create html strings with ease.
It works in both node and client-side applications.
Elements
Add slash to the end of element name to create element without closing tag.
var div = element;// <div></div> var header = 'header.header' role: 'header' element;// <header role="header" class="header"</header> var header = '#unique'element;// <div id="unique"></div> var image = 'img/' src: 'img/partizan.png' alt: 'Volim Partizan!' element;// <img src="img/partizan.png" alt="Volim Partizan!"> var custom = 'polymer-ajax' url: 'http://example.com/json' handleAs: 'json' element;// <polymer-ajax url="http://example.com/json" handleAs="json"></polymer-ajax>
Populate
You can populate element on two ways. First is passing by a string as third param when creating new element.
var header = 'header' role: 'header' 'I am a header!'element;// <header role="header">I am a header!</header>
Second way is to chain populateWith method which accepts function or string.
var header = 'header' role: 'header' element;// <header role="header">I am a header!</header> var header = 'header' role: 'header' element; // <header role="header"><a class="logo">NameOfCompany</a></header>
Helpers
var jquery = element;// <script src="js/vendor/jquery.js"></script>
var style = style'css/style.css'element;// <link rel="stylesheet" href="css/style.css">
Extensible
Tagster is extensible, so you can create your helpers and methods.
Tagsterprototype { thisattrs = attrs; thisel = 'form'; this; this; return this;}; var form = form name: 'form' method: 'POST' element;// <form name="form" method="POST"></form> Tagsterprototype { thisattrs = attrs; thisel = 'meta'; this; this; return this;}; var viewport = element;// <meta name="viewport" content="width=device-width">
Example
var menu = 'home' 'about' 'portfolio' 'contact'; var nav = 'nav.nav' role: 'navigation' element; /* <nav role="navigation" class="nav"> <ul> <li class="menu-item"><a href="/#home">home</a></li> <li class="menu-item"><a href="/#about">about</a></li> <li class="menu-item"><a href="/#portfolio">portfolio</a></li> <li class="menu-item"><a href="/#contact">contact</a></li> </ul></nav> */