Skip to content

Instantly share code, notes, and snippets.

@krishnay
Created October 9, 2013 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnay/6904438 to your computer and use it in GitHub Desktop.
Save krishnay/6904438 to your computer and use it in GitHub Desktop.
App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter.extend({
url: 'http://krishnayallapanthula.com/posts'
})
});
App.Router.map(function(){
this.resource('posts', function(){
this.resource('post', {path: '/post/:post_id'});
});
this.resource('about');
});
App.IndexRoute = Ember.Route.extend({
redirect: function(){
this.transitionTo('posts');
}
});
App.PostsRoute = Ember.Route.extend({
model: function(){
return App.Post.find();
}
});
App.PostController = Ember.ObjectController.extend({
isEditing:false,
doneEditing:function(){
this.set('isEditing', false);
this.get('store').commit();
},
edit:function(){
this.set('isEditing', true);
}
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
intro: DS.attr('string'),
extended: DS.attr('string'),
publishedAt: DS.attr('date')
});
// App.Post.FIXTURES = [{
// id: '1',
// title: "Rails is Omakase",
// author: { name: "d2h" },
// publishedAt: new Date('12-27-2012'),
// intro: "There are lots of à la carte software environments in this world. Places where in order to eat, you must first carefully look over the menu of options to order exactly what you want.",
// extended: "I want this for my ORM, I want that for my template language, and let's finish it off with this routing library. Of course, you're going to have to know what you want, and you'll rarely have your horizon expanded if you always order the same thing, but there it is. It's a very popular way of consuming software.\n\nRails is not that. Rails is omakase."
// }, {
// id: '2',
// title: "The Parley Letter",
// author: { name: "d2h" },
// publishedAt: new Date('12-24-2012'),
// intro: "My [appearance on the Ruby Rogues podcast](http://rubyrogues.com/056-rr-david-heinemeier-hansson/) recently came up for discussion again on the private Parley mailing list.",
// extended: "A long list of topics were raised and I took a time to ramble at large about all of them at once. Apologies for not taking the time to be more succinct, but at least each topic has a header so you can skip stuff you don't care about.\n\n### Maintainability\n\nIt's simply not true to say that I don't care about maintainability. I still work on the oldest Rails app in the world."
// }];
Ember.Handlebars.registerBoundHelper('date', function(date){
return moment(date).fromNow();
});
var showdown = new Showdown.converter();
Ember.Handlebars.registerBoundHelper('markdown', function(input){
return new Ember.Handlebars.SafeString(showdown.makeHtml(input));
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
</head>
<body>
<script type="text/x-handlebars">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Bloggr</a>
<ul class="nav">
<li>{{#linkTo 'posts'}}Posts{{/linkTo}}</li>
<li>{{#linkTo 'about'}}About{{/linkTo}}</li>
</ul>
</div>
</div>
{{outlet}}
</script>
<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' this}} {{title}} <small class='muted'>by {{author}}</small>{{/linkTo}}
</td></tr>
{{/each}}
</table>
</div>
<div class="span9">
{{outlet}}
</div>
</div>
</div>
</script>
<script type="text/x-handlebars" id="posts/index">
<p class="text-warning">Please select a post</p>
</script>
<script type="text/x-handlebars" id="post">
{{#if isEditing}}
{{partial 'post/edit'}}
<button {{action 'doneEditing'}}>Done</button>
{{else}}
<button {{action 'edit'}}>Edit</button>
{{/if}}
<h1>{{title}}</h1>
<h2>by {{author}} <small class="muted">({{date publishedAt}})</small></h2>
<hr>
<div class="intro">
{{markdown intro}}
</div>
<div class="below-the-fold">
{{markdown extended}}
</div>
</script>
<script type="text/x-handlebars" id="post/_edit">
<p>{{view Ember.TextField valueBinding='title'}}</p>
<p>{{view Ember.TextArea valueBinding='intro'}}</p>
<p>{{view Ember.TextArea valueBinding='extended'}}</p>
</script>
<script type="text/x-handlebars" id="about">
<div class='about'>
<p>This is my first emberjs application .</p>
<p>This application is bloggr application where we have access to posts and edit posts .</p>
<p>I can be found on Twitter as <a href="https://twitter.com/krishyalla">@krishyalla</a>.</p>
</div>
<div class='about'>
<p>My name is Krishna Yallapanthula. I am a Mobile Web developer with a passion for creating interactive websites for mobile, tablets and desktops using HTML5, CSS3, Javascript and PHP. I have a keen understanding of web standards and best practices like progressive web enhancement, W3C compliance, and mobile development. I aim to create experiences that look and function beautifully across any device that can access the web.</p>
</div>
</script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="js/libs/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.1.0-beta.1/ember.js"></script>
<script src="http://builds.emberjs.com/tags/v0.14/ember-data.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.1.0/moment.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment