Skip to content

Instantly share code, notes, and snippets.

@stephendeyoung
Created July 6, 2013 16:53
Show Gist options
  • Save stephendeyoung/5940490 to your computer and use it in GitHub Desktop.
Save stephendeyoung/5940490 to your computer and use it in GitHub Desktop.
App = Ember.Application.create({});
var attr = Ember.attr;
App.Post = Ember.Model.extend({
id: attr('number'),
title: attr('string'),
author: attr('string'),
intro: attr('string'),
extended: attr('string'),
publishedAt: attr('date')
});
App.Post.url = '/posts';
App.Post.adapter = Ember.RESTAdapter.create();
App.Router.map(function() {
this.resource('about');
this.resource('posts', function() {
this.resource('post', { path: ':id' });
});
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return App.Post.find();
}
});
App.PostRoute = Ember.Route.extend({
setupController: function(controller, id) {
console.log(id)
controller.set('model', App.Post.find(id));
}
})
App.PostController = Ember.ObjectController.extend({
isEditing: false,
edit: function() {
this.set('isEditing', true);
},
doneEditing: function() {
this.set('isEditing', false);
this.get('store').commit();
}
});
var showdown = new Showdown.converter();
Ember.Handlebars.registerBoundHelper('markdown', function(input) {
return new Handlebars.SafeString(showdown.makeHtml(input));
});
Ember.Handlebars.registerBoundHelper('date', function(date) {
return moment(date).fromNow();
});
<script type="text/x-handlebars" id="posts">
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<table class='table'>
<thead>
<tr><th>Recent Posts</th></tr>
</thead>
{{#each model}}
<tr><td>
{{#linkTo 'post' id}}{{title}} <small class='muted'>by {{author}}</small>{{/linkTo}}
</td></tr>
{{/each}}
</table>
</div>
<div class="span9">
{{outlet}}
</div>
</div>
</div>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment