GithubHelp home page GithubHelp logo

teepee's Introduction

Teepee

Teepee is a templating system for JavaScript, ideal for creating websites, webapps, or anything else - quickly. Teepee is stable, fast, easy, and even lets you control the syntax (and all of this in 1KB).

Using Teepee

To use Teepee, include this script anywhere in your page. You can even hotlink to the latest Teepee (well, you can't in IE9). Woot ('cept for IE9)!

<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>

Example: Hello World

Teepee syntax is both easy to use, and completely customizable. By default, Teepee's syntax is like that of Mustache, an absolutely fantastic markup language (which is itself based on CTemplate). Awesome!

<body>
	<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>
	<script>
	var tp = new Teepee();
	tp.write(
		'Hello, {{=who}}!',
		{ who: 'World' }
	); // prints "Hello, World!"
	</script>
</body>

Example: If and If Not

Use simplified IF and IF NOT statements in your templates for even more dynamic control. Oh yea!

<body>
	<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>
	<script>
	var tp = new Teepee();
	tp.write(
		'Hello{{?isEarth}}, Earth{{/isEarth}}{{?isMars}}, Mars{{/isMars}}!',
		{ isMars: false, isEarth: true }
	); // prints "Hello, Earth!"
	</script>
</body>

Example: Looping

Use a simplified loop statement in your templates to loop through an array. Uhuh uhuh uhuh!

<body>
	<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>
	<script>
	var tp = new Teepee();
	tp.write(
		'Ask these questions:{{#q}} {{=q}}{{/q}}.',
		{ q: ['Who', 'What', 'Where', 'When', 'Why'] }
	); // prints "Ask these questions: Who What Where When Why."
	</script>
</body>

Example: Syntax Mod

You can change Teepee's syntax to your heart's content. Yay!

<body>
	<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>
	<script>
	var t = new Teepee();
	t.opener('@').closer('@').printer('$');
	t.write(
		'The quick @$jumper@ jumps over the @$jumpee@.',
		{ jumper: 'brown fox', jumpee: 'lazy dog' }
	); // prints "The quick brown fox jumps over the lazy dog."
	</script>
</body>

That's right, you may have noticed that most functions in Teepee are chainable (like jQuery). Nice!

Examples: Script Tag

You can even use templates in <script> tags to make your entire page. Sweet!

<body>
	<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>
	<script id="demo-template" type="text/html">
	<h1>
		{{=pageTitle}}
	</h1>
	<p>
		{{=pageDescription}}
	</p>
	</script>
	<script>
	demoObject = {
		pageTitle: 'My 1997 Website',
		pageDescription: 'Hello and welcome to my awesome website.'
	};
	tp = new Teepee();
	tp.tplById('demo-template').use(demoObject).write();
	</script>
</body>

You can even use external templates in <script> tags to make your page as well as style it Sass-style. Nifty!

<body>
	<script src="//raw.github.com/rezitech/teepee/master/teepee.js"></script>
	<script src="demo-advanced.tpl.html" id="demo-html" type="text/html">
		<-- Contents of "demo-advanced.tpl.html" -->
		<h1>
			{{=pageTitle}}
		</h1>
		<nav>
			<ul>
				{{#pageNavigation}}
				<li>
					<a href="{{=pageNavigation.href}}">{{=pageNavigation.title}}</a>
				</li>
				{{/pageNavigation}}
			</ul>
		</nav>
	</script>
	<script src="demo-advanced.tpl.css" id="demo-css" type="text/css">
		/* Contents of "demo-advanced.tpl.css" */
		body {
			background: {{=pageBackgroundColor}};
			color: {{=pageTextColor}};
		}
		a {
			color: {{=pageTextColor}};
			text-decoration: none;
		}
	</script>
	<script>
	demoObject = {
		pageTitle: 'My HTML5 1997 Website',
		pageNavigation: [
			{ href: '#uno', title: 'One' },
			{ href: '#dos', title: 'Two' },
			{ href: '#tres', title: 'Three' },
			{ href: '#cuatro', title: 'Four' },
			{ href: '#cinco', title: 'Five' },
		],
		pageBackgroundColor: '#444',
		pageTextColor: '#FFF'
	};
	</script>
	<script>
	var tp = new Teepee();
	tp.use(demoObject);
	tp.tplById('demo-css', false).writeCSS().tplById('demo-html', false).write();
	</script>
</body>

Features

Teepee's filled with functionality that will allow you to start developing immediately.


Creating a new instance

Syntax

_tp_ = new Teepee()

opener

Syntax

_tp_.opener
_tp_.opener ( _chars_ )

Summary

Sets the opening character(s) of Teepee code and returns the instance of Teepee. If nothing is passed, the current opening character(s) are returned.

Parameters

chars
The character(s) to be used.

closer

Syntax

_tp_.closer
_tp_.closer ( _chars_ )

Summary

Sets the closing character(s) of Teepee code and returns the instance of Teepee. If nothing is passed, the current closing character(s) are returned.

Parameters

chars
The character(s) to be used.

iffer

Syntax

_tp_.iffer
_tp_.iffer ( _chars_ )

Summary

Sets the character(s) used to begin an IF statement and returns the instance of Teepee. If nothing is passed, the current IF character(s) are returned.

Parameters

chars
The character(s) to be used.

closer

Syntax

_tp_.notter
_tp_.notter ( _chars_ )

Summary

Sets the character(s) used to begin an IF NOT statement and returns the instance of Teepee. If nothing is passed, the current IF NOT character(s) are returned.

Parameters

chars
The character(s) to be used.

looper

Syntax

_tp_.looper
_tp_.looper ( _chars_ )

Summary

Sets the character(s) used to begin a FOR statement and returns the instance of Teepee. If nothing is passed, the current FOR character(s) are returned.

Parameters

chars
The character(s) to be used.

printer

Syntax

_tp_.printer
_tp_.printer ( _chars_ )

Summary

Sets the character(s) used to print a variable and returns the instance of Teepee. If nothing is passed, the current printing character(s) are returned.

Parameters

chars
The character(s) to be used.

tpl

Syntax

_tp_.tpl ( _tpl_ )

Summary

Assigns the template string and returns the instance of Teepee. If nothing is passed, the current template string is returned.

Parameters

tpl
The string to be used.

tplById

Syntax

_tp_.tplById ( _id_, _async_ )

Summary

Sets the template string, based on an element's content and returns the instance of Teepee. If the element is a script tag with a src attribute, the local source will be used.

Parameters

id
The id of the element.
async
The optional boolean of whether to load the template asynchronously. Defaults true.

use

Syntax

_tp_.use ( _use_ )

Summary

Sets the object to be used by the template and returns the instance of Teepee. If nothing is passed, the current object is returned.

Parameters

use
The object to be used.

render

Syntax

_tp_.render
_tp_.render ( _tpl_ , _use_ )

Summary

Returns the rendered template.

Parameters

tpl
The optional string of the template. Defaults to the stored string.
use
The optional object to be used by the template. Defaults to the stored object.

write

Syntax

_tp_.write ( _tpl_ , _use_ )

Summary

Writes the rendered template to the document and returns the instance of Teepee.

Parameters

tpl
The optional string of the template. Defaults to the stored string.
use
The optional object to be used by the template. Defaults to the stored object.

writeCSS

Syntax

_tp_.writeCSS ( _tpl_ , _use_ )

Summary

Writes the rendered template to a style element in the document and returns the instance of Teepee.

Parameters

tpl
The optional string of the template. Defaults to the stored string.
use
The optional object to be used by the template. Defaults to the stored object.

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my_teepee)
  3. Commit your changes (git commit -am "Added Awesomeness")
  4. Push to the branch (git push origin my_teepee)
  5. Create an Issue with a link to your branch
  6. Enjoy a refreshing Coca Cola Classic (you earned it!) and wait

teepee's People

Contributors

jonathantneal avatar

Stargazers

Bradley Wood avatar

Watchers

James Cloos avatar Bradley Wood 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.