Skip to content

Instantly share code, notes, and snippets.

@cloke
cloke / gist:4519996
Last active December 11, 2015 00:58
{ food: {_id: 'bc4', brand: 'test', food_nutrients: [{ _id: 'af1', name: 'sodium'}] }
FoodNutrient = DS.Model.extend({
name: DS.attr( 'string' )
});
Food = DS.Model.extend(
brand: DS.attr( 'string' ),
food_nutrients: DS.hasMany( Diets.FoodNutrient )
});
@cloke
cloke / gist:4495264
Last active December 10, 2015 21:28
MyApp.MyCollectionView = Ember.CollectionView.create({
tagName: 'ul'
contentBinding: 'some array controller',
itemViewClass: Ember.View.extend({
tagName: 'li'
template: Ember.Handlebars.compile("the letter: {{view.content}}")
})
});
/** MUTLIPLE STATE MANAGERS **/
activeStateManagers: null,
getStateManager: function(stateManager) {
return (typeof stateManager === 'string') ?
this.get(stateManager+'StateManager') :
stateManager;
},
News.Router = Core.Router.extend
enableLogging: true
root: Core.Route.extend
index: Core.Route.extend
route: '/'
redirectsTo: 'nav'
nav: Core.Route.extend
initialState: 'index'
route: '/:nav_id'
index: Core.Route.extend
<ul>
{{#each email in view.content}}
{{#email_timecheck email.nice_created_at}}
{{/email_timecheck}}
Handlebars.registerHelper 'email_timecheck', (conditional, block) ->
time = this.get(conditional)
if(time != News.masterView.get('email_time'))
Assume you are using a bound array named links that is defined like [{link: 'some link', title: 'my nifty link', active: true}, ...]
//in JS file. I will assume you have an app called MyApp that was create with Em.Application.create()
MyApp.linksController = Em.ArrayProxy.create({
content: [ { link: 'I am a link', title: 'I am a title', active: true } ]
});
<!-- Navbar
================================================== -->
@cloke
cloke / gist:2854056
Created June 1, 2012 18:01
simple view
M.HeadingView = Em.View.extend Ember.TextSupport,
viewName: 'heading_view'
content: null
attributeBindings: ['text']
editable: false
template: Ember.Handlebars.compile(
'{{#if this.editable}}
{{view Em.TextField valueBinding="content"}}
{{else}}
@cloke
cloke / gist:2490991
Created April 25, 2012 16:12
Select Element
{{view M.Select
contentBinding="Desires.elementTypeController"
valueBinding="this.type"
optionLabelPath="content.label"
optionValuePath="content.type"
classNames="input-xlarge"
}}
M.Select = Em.Select.extend({
@cloke
cloke / gist:2360459
Created April 11, 2012 16:47
Binding issue
PostView: Em.View.extend
templateName: 'post_container'
postBinding: 'App.appController.selection.post'
Displays, but does not update until I click on the text field.
{{view Em.TextField valueBinding="post.managing"}}
Displays and updates
{{view Em.TextField valueBinding="parentView.content.post.managing"}}
@cloke
cloke / gist:2279116
Created April 1, 2012 22:16
Custom view
M.Paragraph = Em.View.extend(Ember.TextSupport, {
viewName: 'paragraph_view',
content: null,
attributeBindings: ['text'],
text: '',
editable: false,
_editable: (function() {
console.log(arguments);
return this.set('editable', Em.getPath(arguments[1]));
}).observes('M.editable.status'),