<commit_before>ICanHaz.Controller
==================

[![License](http://img.shields.io/:license-mit-blue.svg)](http://tonekk.mit-license.org)

Create client-side controllers with [mustache](http://mustache.github.io/)-views.
Bind events with the easiest syntax available.

Based on [ICanHaz.js](http://icanhazjs.com/) / [ICanHaz.load](https://github.com/tonekk/ICanHaz.load).

## Usage

**NOTE:** This project uses [ICanHaz.load](https://github.com/tonekk/ICanHaz.load), so first be sure to set:

```javascript

// Global config
ich.templatePath('/assets/templates');
// optionally, set a special extension (.mustache is standard)
ich.templateExtension = 'tpl';

```

After having that set up, create a `ViewController` like this:

```javascript

var MyViewController = ich.Controller.extend({
  init: function() {

    // Data for mustache template
    var templateData = { foo: 'bar' },
        self = this;

    // Constructor, render element here
    self.element.render('templateName', templateData, function() {
      // Executed when template has loaded
      self.afterInit();
    });
  },

  // Bind events with this readable, kick-ass syntax
  '.btn click': function(el, e) {
    // 'this' refers to MyViewController, although this is an event
    // 'el' refers to jQuery Element, 'e' to jQuery Event
    this.helper();
  },

  '.select change': function() {
    // SomeCode()
  },

  helper: function() {
    // SomeCode()
  },

  afterInit: function() {
    // SomeCode()
  }
});

```

## Installation

Just load `ICanHaz.Controller.js` somewhere after its [bower dependencies](https://github.com/tonekk/ICanHaz.Controller/blob/master/bower.json).
Create your `controllers` in separate files and require them accordingly.

## Testing

Tests are written using `jasmine` and can be executed in the browser, by browsing `test/index.html`.
This project is too tiny for continuous integration imo.<commit_msg>updates readme<commit_after>ICanHaz.Controller
==================

[![License](http://img.shields.io/:license-mit-blue.svg)](http://tonekk.mit-license.org)

Create client-side controllers with [mustache](http://mustache.github.io/)-views.
Bind events with the easiest syntax available.
Can also be used without a mustache template, see below.

Based on [ICanHaz.js](http://icanhazjs.com/) / [ICanHaz.load](https://github.com/tonekk/ICanHaz.load).

## Usage

**NOTE:** This project uses [ICanHaz.load](https://github.com/tonekk/ICanHaz.load), so first be sure to set:

```javascript

// Global config
ich.templatePath('/assets/templates');
// optionally, set a special extension (.mustache is standard)
ich.templateExtension = 'tpl';

```

After having that set up, create a `ViewController` like this:

```javascript

var MyViewController = ich.Controller.extend({
  init: function() {

    // Data for mustache template
    var templateData = { foo: 'bar' },
        self = this;

    // Constructor, render element here
    self.element.render('templateName', templateData, function() {
      // Executed when template has loaded
      self.afterInit();
    });
  },

  // Bind events with this readable, kick-ass syntax
  '.btn click': function(el, e) {
    // 'this' refers to MyViewController, although this is an event
    // 'el' refers to DOMElement, 'e' to jQuery Event
    this.helper();
  },

  helper: function() {
    // SomeCode()
  }
});

```

### Without mustache template

You can also use `ICanHaz.Controller` to bind events on pre-rendered html.
The only difference is that you won't have to call `this.element.render()` and you **must** implement `afterInit` instead of `init`, so that events are bound correctly:

```javascript

var MyViewController = ich.Controller.extend({
  afterInit: function() {
    // Events are already bound when this function is executed
  },

  '.select change': function(el, e) {
    $(el).css('display', 'none');
  }
});

```


## Installation

Just load `ICanHaz.Controller.js` somewhere after its [bower dependencies](https://github.com/tonekk/ICanHaz.Controller/blob/master/bower.json).
Create your `controllers` in separate files and require them accordingly.

## Testing

Tests are written using `jasmine` and can be executed in the browser, by browsing `test/index.html`.
This project is too tiny for continuous integration imo.
{'fraction_non_alphanumeric': 0.14478270973739252, 'fraction_numerical': 0.0, 'mean_word_length': 3.798216276477146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3326975', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1260, 'n_words': 396}