<commit_before># T.js - a simple & powerful template engine

## DESCRIPTION

T.js is a template engine that uses simple Javascript data structure to 
represent html/xml data.

### BASIC RULES

* A tag is represented by an array;
* First item is the tag name, optionally it could contain id and css classes,
  e.g. 'div#id.class1.class2';
* Rest of the array contains the tag's attributes, text or child tags;
* Attributes are stored in hash, e.g. {"name": "username", "type": "text"};
* Text values are strings, e.g. "This is sample content";
* Child tags are in child arrays;
* Attributes can appear anywhere after tag name;
* Texts and child tags are rendered sequentially.

### ADVANCED FEATURES

* Functions can be used everywhere, they'll be invoked and their results will
  be used to generate final output, e.g. 
  ```javascript
  ['div.now', function(){return new Date();}]
  ```

* render() takes an optional data argument, that argument will then be passed 
  to functions inside the template, e.g.
  ```javascript
  var template = ['div.total', function(data){return data.total;}];
  T(template).render({total: 100});
  ```

* Layout, e.g.
  ```javascript
  var layout = ['div', ['div', 'Title'], T.include('body')]
  var body   = ['div', 'Content goes here']
  T(layout).prepare({'body': body}).render()
  ```

## USAGE

* Include T.js on top of HTML
```html
<script src="https://raw.github.com/gcao/T.js/master/public/javascripts/t.js"></script>
```

* Define template
```javascript
var template = ["a.edit", {"href": "/edit"}, "Edit"]
```

* Render
```javascript
var result = T(template).render()
```

* Result is like
```html
<a class="edit" href="/edit">Edit</a>
```

## EXAMPLES

[A simple TODO list that uses reactor.js for data binding](http://jsfiddle.net/gcao/E4syH/)

## DEVELOPMENT SETUP (MAC)

  $ git clone git://github.com/gcao/T.js.git  
  $ cd T.js

  $ brew install node  
  $ npm install coffee-script  

  $ gem install bundler  
  $ bundle  
  $ guard  

## NOTES

* Run with LiveReload support:  
thin -p 8000 start

* Run with no external dependency:  
cd public && python -m SimpleHTTPServer

* Open Demo Page:  
open http://localhost:8000

* Run Jasmine tests in browser:  
open http://localhost:8000/spec_runner.html

* Convert between html and T:  
bin/html2t spec/fixtures/test.html  
bin/html2t spec/fixtures/test.html | bin/t2html  

* Convert T to CoffeeScript (js2coffee has to be installed):  
bin/html2t spec/fixtures/test.html | js2coffee

* Convert haml to html to T template to html:  
bundle exec bin/haml2erb spec/fixtures/test.haml | HTML_FRAGMENT=true bin/html2t | bin/t2html

* Integrate with Jasmine Headless WebKit:  
Config file is located at public/javascripts/spec/jasmine.yml  
jasmine-headless-webkit -c -j public/javascripts/spec/jasmine.yml

T.include("name") => T("name")
T() = T('default')
T('default', "Default content"): default include with default content
T(...).prepare({default: ''}) prepare(...)
T.v("a.b")        => T.get("a.b")
<commit_msg>Documentation<commit_after># T.js - a simple & powerful template engine

## DESCRIPTION

T.js is a template engine that uses simple Javascript data structure to 
represent html/xml data.

### BASIC RULES

* A tag is represented by an array;
* First item is the tag name, optionally it could contain id and css classes,
  e.g. 'div#id.class1.class2';
* Rest of the array contains the tag's attributes, text or child tags;
* Attributes are stored in hash, e.g. {"name": "username", "type": "text"};
* Text values are strings, e.g. "This is sample content";
* Child tags are in child arrays;
* Attributes can appear anywhere after tag name;
* Texts and child tags are rendered sequentially.

### ADVANCED FEATURES

* Functions can be used everywhere, they'll be invoked and their results will
  be used to generate final output, e.g. 
  ```javascript
  ['div.now', function(){return new Date();}]
  ```

* render() takes an optional data argument, that argument will then be passed 
  to functions inside the template, e.g.
  ```javascript
  var template = ['div.total', function(data){return data.total;}];
  T(template).render({total: 100});
  ```

* Layout, e.g.
  ```javascript
  var layout = ['div', ['div', 'Title'], T.include('body')]
  var body   = ['div', 'Content goes here']
  T(layout).prepare({'body': body}).render()
  ```

## USAGE

* Include T.js on top of HTML
```html
<script src="https://raw.github.com/gcao/T.js/master/public/javascripts/t.js"></script>
```

* Define template
```javascript
var template = ["a.edit", {"href": "/edit"}, "Edit"]
```

* Render
```javascript
var result = T(template).render()
```

* Result is like
```html
<a class="edit" href="/edit">Edit</a>
```

## EXAMPLES

[A simple TODO list that uses reactor.js for data binding](http://jsfiddle.net/gcao/E4syH/)

## DEVELOPMENT SETUP (MAC)

$ git clone git://github.com/gcao/T.js.git  
$ cd T.js

$ brew install node  
$ npm install coffee-script  

$ gem install bundler  
$ bundle  
$ guard  

## NOTES

* Run with LiveReload support:  
thin -p 8000 start

* Run with no external dependency:  
cd public && python -m SimpleHTTPServer

* Open Demo Page:  
open http://localhost:8000

* Run Jasmine tests in browser:  
open http://localhost:8000/spec_runner.html

* Convert between html and T:  
bin/html2t spec/fixtures/test.html  
bin/html2t spec/fixtures/test.html | bin/t2html  

* Convert T to CoffeeScript (js2coffee has to be installed):  
bin/html2t spec/fixtures/test.html | js2coffee

* Convert haml to html to T template to html:  
bundle exec bin/haml2erb spec/fixtures/test.haml | HTML_FRAGMENT=true bin/html2t | bin/t2html

* Integrate with Jasmine Headless WebKit:  
Config file is located at public/javascripts/spec/jasmine.yml  
jasmine-headless-webkit -c -j public/javascripts/spec/jasmine.yml

{'fraction_non_alphanumeric': 0.13725490196078433, 'fraction_numerical': 0.009287925696594427, 'mean_word_length': 3.8906644238856183, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '997439', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1874, 'n_words': 642}