GithubHelp home page GithubHelp logo

manubb / barbiche Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 1.94 MB

Logic-full template engine for DOM & JavaScript

Home Page: https://manubb.github.io/barbiche

License: MIT License

JavaScript 86.65% HTML 9.11% Yacc 4.24%
template-engine dom javascript templates subtemplates partials templating html

barbiche's Introduction

Barbiche - Template engine for DOM & JavaScript

Barbiche is a logic-full template engine for browser environment. It has been designed to give you complete control over the data you want to merge into an HTML fragment. Once minified and gzipped, Barbiche size is 11KB.

Documentation and interactive examples can be found here.

Features

Barbiche supports:

  • text and HTML insertion
  • conditions (if and optional else)
  • aliases
  • loops
  • flexible subtemplate imports
  • attribute setting
  • class setting

Barbiche has a complete test suite that can be run in your browser.

Sample

We ask Barbiche to merge some data into an HTML template:

<template id="test">
	<div bb-alias="items[1].name: 'name'" bb-class="customClass">
		<div>{{name}}</div>
		<ul bb-attr="my_replace(attrValue): 'attr-name'">
			<template bb-repeat="items: 'item'">
				<li bb-if="item.show" bb-class="[item.species || 'unknown', (_item_ == 0): 'first']">
					{{item.name}} (index: {{_item_}})
				</li>
			</template>
		</ul>
		<span>{{item.join(', ').toUpperCase()}}</span>
		{{{some_html}}}
	</div>
</template>
var barbiche = Barbiche();
var frag = barbiche('test').merge({
	customClass: "my-class",
	"items": [
		{species: "hen", name: "Elsa", show: true},
		{species: "cat", name: "Jacynthe", show: false},
		{species: null, name: "Zaza", show: true}
	],
	item: ["hen", "cat", "dog", "spider"],
	some_html: "<div><p>This is...</p><p>...some HTML.</p></div>",
	my_replace: function(str) {return str.replace(/o/g, "O");},
	attrValue: "lunchroom"
});

The returned document fragment can then be inserted anywhere you want. It contains:

<div class="my-class">
	<div>Jacynthe</div>
	<ul attr-name="lunchrOOm">
		<li class="hen first">Elsa (index: 0)</li>
		<li class="unknown">Zaza (index: 2)</li>
	</ul>
	<span>HEN, CAT, DOG, SPIDER</span>
	<div><p>This is...</p><p>...some HTML.</p></div>
</div>

Browser support

Barbiche requires support of <template> element and basic support of element.classList API. Here is the support table:

Native (v2 & v3) Polyfilled (v2) Polyfilled (v3)
Chrome ≥26 ≥15 ≥26
Firefox ≥22 ≥22 ≥22
IE/Edge No support ≥9 ≥11
Opera ≥15 ≥11.6 ≥15
Safari ≥9 ≥6.2 ≥6.2

Polyfills, once minified and gzipped, weight an additionnal 2KB.

barbiche's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.