JSFiddle - React, Tailwind, and code Playground

by mehulkar

HTML

<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script src="http://mochaleaf.com/ember.js"></script>
<script src="http://mochaleaf.com/ember-data.js"></script>
<script type='text/x-handlebars'>
{{#each post in App.postsController}}
<div>Post title: {{post.name}}</div>
<div>Author: {{post.author.name}}</div>
{{/each}}
</script>

JavaScript

App = Ember.Application.create();
App.Serializer = DS.Serializer.extend({
    keyForBelongsTo: function(type, name) {
        return this.keyForAttributeName(type, name) + "_id";
    },
    keyForAttributeName: function(type, name) {
        return Ember.String.decamelize(name);
    },
    addBelongsTo: function(hash, record, key, relationship) {
        return hash["" + key + "_id"] = record.get("" + key + ".id");
    },
    addHasMany: function(hash, record, key, relationship) {
        return console.log('serializing has_many');
    }
});

App.Adapter = DS.RESTAdapter.extend({
    serializer: App.Serializer.create()
});

App.store = DS.Store.create({
    revision: 5,
    adapter: App.Adapter.create({
        bulkCommit: false
    })
});

App.Post = DS.Model.extend({
    name: DS.attr("string"),
    author: DS.belongsTo("App.Author"),
    tags: DS.hasMany("App.Tag")
});

App.Author = DS.Model.extend({
    name: DS.attr("string")
});

App.Author.FIXTURES = [
    {id:1, name:'Charlie Dickinson'},
]

App.Tag = DS.Model.extend({
    name: DS.attr("string")
});

App.store.load(App.Author, {
    id: 1,
    name: "Foooby"
});
App.store.loadMany(App.Tag, {
    id: 1,
    name: 'test'
}, {
    id: 2,
    name: 'ember'
});
App.store.load(App.Post, {
    id: 1,
    name: "Cool Post bro",
    author_id: 1
});

App.postsController = Ember.ArrayController.create();
App.postsController.set('content', []);
App.postsController.pushObject(App.Post.find(1));