<commit_before>
GwtBackbone v0.4.1 [![Travis-CI Build Status](https://travis-ci.org/liraz/gwt-backbone.svg?branch=master)](https://travis-ci.org/liraz/gwt-backbone)
===========

GwtBackbone a.k.a. GBackbone is a Backbone-like API written in GWT, which allows GWT to be used convert already written enterprise backbone projects into entirely used in GWT.
That aim here is to provide the tools to those who don't have the time to change all of their project to some type safe language, and rewrite the whole thing.
With GBackbone you can use the same programming methodology currently written & used in your company, and just convert it into type safe, compile time syntax checking & way more organized java project.

GBackbone is using the same API currently available in backbone, and will continue to do so until imitating the full capabilities of backbone.
The library is completely dependant on the *GQuery a.k.a GwtQuery project*, and will take it as one of it's dependencies.
Currently what mostly is used from GwtQuery is JsMap, Function & the whole selector, events engines available within the framework (like Backbone is using jQuery/Zepto etc...).

*Gwt version used is 2.7.0*
All functionality is available and tested, in addition to some utility annotations and helpers that can be used.


Demo
=======
Check out the demo source here (Todos application):
https://github.com/liraz/gwt-backbone/tree/master/gwt-backbone-examples/gwt-backbone-examples-todos

Use the following link to see the Todos application live running:
https://gbackbone-1198.appspot.com/

Demo was tested on IE 8,9,10+, FireFox, Chrome, Android & iPhone

Highlights
=======

Router @Route annotations
------
@Route can be declared with multiple routes as array of string values.
Arguments can be with the same name as what is passed into the route regex.
If specifying String[] router will give you all the arguments that were provided for the route.

```java
public class AnnotatedRouter extends Router {
    @Override
    protected void initialize(Options options) {
    }

    @Route(value = {"counter", "counter2"})
    public void counter() {
        count++;
    }

    @Route("search/:query")
    public void search(String query) {
        this.query = query;
    }

    @Route("search/:query/p:page")
    public void searchArgs(String[] args) {
        this.query = args[0];
        this.page = args[1];
    }
}
```

View @EventHandler annotations for attaching events
------
@EventHandler can be declared with an event selector like you would do the same with events object in Backbone.js.
If specifying Event or Element, those objects will be injected automatically.

```java
public class AnnotatedView extends View {
    int[] counter;
    public AnnotatedView(Options options, int[] counter) {
        super(options);
        this.counter = counter;
    }

    @EventHandler("click h1")
    public void foo(Event event, Element element) {
        counter[0]++;

        assert event != null;
        assert element != null;
    }

    @EventHandler("click")
    public void bar(Element element, Event event) {
        counter[0]++;

        assert event != null;
        assert element != null;
    }

    @EventHandler("click")
    public void noArgs() {
        counter[0]++;
    }
}
```

View @ViewTemplate annotations for attaching a template for the view
------
If "filePath" is provided, the template will be loaded on demand, a "template:load" event will be dispatched,
then when completed loading an event of "template:complete" will be dispatched once the template was loaded.
If a default "value" is provided, it'll be considered as a template string.
```java
@ViewTemplate(filePath = "CustomerRegisterView.ejs")
public class AnnotatedModelInjectedView extends View {
    @InjectView
    public InputElement emailInput;

    public AnnotatedModelInjectedView(Options options) {
        super(options);
    }

    @Override
    public View render() {
        emailInput.setValue("My Email!");

        return this;
    }
}
```

```java
@ViewTemplate("<%= value %>")
public class AnnotatedTemplateView extends View {

    public AnnotatedTemplateView(Options options) {
        super(options);
    }
}
```

Also a selector of the <script id="item-template"></script> element holding the html template currently in the document can be provided:
```java
@ViewTemplate(selector = "#item-template")
public class ListItemView extends View {

    public ListItemView(Options options) {
        super(options);
    }
}
```

View @InjectView annotation for injecting views that exists inside the $el
------
A GWT element can be injected, as well GQuery is supported.
The annotation can be provided with a selector to get the element injected.
Or you can also leave it empty, then the property name will be taken in the following selector pattern "#%s".
```java
@ViewTemplate(filePath = "CustomerRegisterView.ejs")
public class InjectedView extends View {

    @InjectView
    public InputElement emailInput;

    @InjectView("#emailRetypeSpecialId")
    public InputElement emailRetypeInput;

    @InjectView(".phoneInputClass")
    public InputElement phoneNumberInput;

    @InjectView(".addressInputAsGQuery")
    public GQuery addressInput;

    @InjectView
    public GQuery cityInput;

    public AnnotatedModelInjectedView(Options options) {
        super(options);
    }

    @Override
    public View render() {
        emailInput.setValue("<EMAIL>");

        return this;
    }
}
```

View @InjectModel annotation for injecting properties from model
------
```java
@ViewTemplate(filePath = "CustomerRegisterView.ejs")
public class AnnotatedModelInjectedView extends View {

    @InjectModel
    public String email; // injected from model, field name is taken as property name

    @InjectView
    public InputElement emailInput;

    public AnnotatedModelInjectedView(Options options) {
        super(options);
    }

    @Override
    public View render() {
        emailInput.setValue(email);

        return this;
    }
}
```

View @ViewTagName annotation for specifying tag name for a view
------
```java
@ViewTagName("li")
public class TodoView extends View<Todo> {

}
```

View @ViewElement annotation for specifying the view's element that is in the DOM
------
```java
@ViewElement("#todoapp")
public class AppView extends View {

}
```


Adding to your project
=======

For now this package is available only via https://jitpack.io/

### Gradle dependencies
```
repositories {
  maven {
    url "https://jitpack.io"
  }
}

dependencies {
    compile 'com.github.liraz:gwt-backbone:0.4.1'
}
```

### Maven dependencies
```
<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.liraz</groupId>
    <artifactId>gwt-backbone</artifactId>
    <version>0.4.1</version>
</dependency>
```


Usage
=======

Collection
------
```java
import static org.lirazs.gbackbone.client.core.data.Options.O;<commit_msg>Updated README with correct dependency location on jitpack.io<commit_after>
GwtBackbone v0.4.1 [![Travis-CI Build Status](https://travis-ci.org/liraz/gwt-backbone.svg?branch=master)](https://travis-ci.org/liraz/gwt-backbone)
===========

GwtBackbone a.k.a. GBackbone is a Backbone-like API written in GWT, which allows GWT to be used convert already written enterprise backbone projects into entirely used in GWT.
That aim here is to provide the tools to those who don't have the time to change all of their project to some type safe language, and rewrite the whole thing.
With GBackbone you can use the same programming methodology currently written & used in your company, and just convert it into type safe, compile time syntax checking & way more organized java project.

GBackbone is using the same API currently available in backbone, and will continue to do so until imitating the full capabilities of backbone.
The library is completely dependant on the *GQuery a.k.a GwtQuery project*, and will take it as one of it's dependencies.
Currently what mostly is used from GwtQuery is JsMap, Function & the whole selector, events engines available within the framework (like Backbone is using jQuery/Zepto etc...).

*Gwt version used is 2.7.0*
All functionality is available and tested, in addition to some utility annotations and helpers that can be used.


Demo
=======
Check out the demo source here (Todos application):
https://github.com/liraz/gwt-backbone/tree/master/gwt-backbone-examples/gwt-backbone-examples-todos

Use the following link to see the Todos application live running:
https://gbackbone-1198.appspot.com/

Demo was tested on IE 8,9,10+, FireFox, Chrome, Android & iPhone

Highlights
=======

Router @Route annotations
------
@Route can be declared with multiple routes as array of string values.
Arguments can be with the same name as what is passed into the route regex.
If specifying String[] router will give you all the arguments that were provided for the route.

```java
public class AnnotatedRouter extends Router {
    @Override
    protected void initialize(Options options) {
    }

    @Route(value = {"counter", "counter2"})
    public void counter() {
        count++;
    }

    @Route("search/:query")
    public void search(String query) {
        this.query = query;
    }

    @Route("search/:query/p:page")
    public void searchArgs(String[] args) {
        this.query = args[0];
        this.page = args[1];
    }
}
```

View @EventHandler annotations for attaching events
------
@EventHandler can be declared with an event selector like you would do the same with events object in Backbone.js.
If specifying Event or Element, those objects will be injected automatically.

```java
public class AnnotatedView extends View {
    int[] counter;
    public AnnotatedView(Options options, int[] counter) {
        super(options);
        this.counter = counter;
    }

    @EventHandler("click h1")
    public void foo(Event event, Element element) {
        counter[0]++;

        assert event != null;
        assert element != null;
    }

    @EventHandler("click")
    public void bar(Element element, Event event) {
        counter[0]++;

        assert event != null;
        assert element != null;
    }

    @EventHandler("click")
    public void noArgs() {
        counter[0]++;
    }
}
```

View @ViewTemplate annotations for attaching a template for the view
------
If "filePath" is provided, the template will be loaded on demand, a "template:load" event will be dispatched,
then when completed loading an event of "template:complete" will be dispatched once the template was loaded.
If a default "value" is provided, it'll be considered as a template string.
```java
@ViewTemplate(filePath = "CustomerRegisterView.ejs")
public class AnnotatedModelInjectedView extends View {
    @InjectView
    public InputElement emailInput;

    public AnnotatedModelInjectedView(Options options) {
        super(options);
    }

    @Override
    public View render() {
        emailInput.setValue("My Email!");

        return this;
    }
}
```

```java
@ViewTemplate("<%= value %>")
public class AnnotatedTemplateView extends View {

    public AnnotatedTemplateView(Options options) {
        super(options);
    }
}
```

Also a selector of the <script id="item-template"></script> element holding the html template currently in the document can be provided:
```java
@ViewTemplate(selector = "#item-template")
public class ListItemView extends View {

    public ListItemView(Options options) {
        super(options);
    }
}
```

View @InjectView annotation for injecting views that exists inside the $el
------
A GWT element can be injected, as well GQuery is supported.
The annotation can be provided with a selector to get the element injected.
Or you can also leave it empty, then the property name will be taken in the following selector pattern "#%s".
```java
@ViewTemplate(filePath = "CustomerRegisterView.ejs")
public class InjectedView extends View {

    @InjectView
    public InputElement emailInput;

    @InjectView("#emailRetypeSpecialId")
    public InputElement emailRetypeInput;

    @InjectView(".phoneInputClass")
    public InputElement phoneNumberInput;

    @InjectView(".addressInputAsGQuery")
    public GQuery addressInput;

    @InjectView
    public GQuery cityInput;

    public AnnotatedModelInjectedView(Options options) {
        super(options);
    }

    @Override
    public View render() {
        emailInput.setValue("<EMAIL>");

        return this;
    }
}
```

View @InjectModel annotation for injecting properties from model
------
```java
@ViewTemplate(filePath = "CustomerRegisterView.ejs")
public class AnnotatedModelInjectedView extends View {

    @InjectModel
    public String email; // injected from model, field name is taken as property name

    @InjectView
    public InputElement emailInput;

    public AnnotatedModelInjectedView(Options options) {
        super(options);
    }

    @Override
    public View render() {
        emailInput.setValue(email);

        return this;
    }
}
```

View @ViewTagName annotation for specifying tag name for a view
------
```java
@ViewTagName("li")
public class TodoView extends View<Todo> {

}
```

View @ViewElement annotation for specifying the view's element that is in the DOM
------
```java
@ViewElement("#todoapp")
public class AppView extends View {

}
```


Adding to your project
=======

For now this package is available only via https://jitpack.io/

### Gradle dependencies
```
repositories {
  maven {
    url "https://jitpack.io"
  }
}

dependencies {
    compile 'com.github.liraz.gwt-backbone:gwt-backbone:0.4.1'
}
```

### Maven dependencies
```
<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.liraz.gwt-backbone</groupId>
    <artifactId>gwt-backbone</artifactId>
    <version>0.4.1</version>
</dependency>
```


Usage
=======

Collection
------
```java
import static org.lirazs.gbackbone.client.core.data.Options.O;
{'fraction_non_alphanumeric': 0.1021528371827773, 'fraction_numerical': 0.003849443969204448, 'mean_word_length': 3.6254533465215957, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 14, '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': '6010635', 'n_tokens_mistral': 4041, 'n_tokens_neox': 3843, 'n_words': 1452}