Last active
August 29, 2015 14:00
-
-
Save istro/11384151 to your computer and use it in GitHub Desktop.
Code for Ember post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /app/adapters/application.js | |
export default DS.ActiveModelAdapter.extend({ | |
host: 'trooper-json-api-host.com/', | |
namespace: 'api', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/controllers/foobar/avatar.js | |
export default Ember.ObjectController.extend({ | |
avatarClass: function () { | |
return "sprite-" + this.get('avatar.name').dasherize(); | |
}.property('avatar.name'), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/controllers/users/edit.js | |
export default Ember.ObjectController.extend({ | |
isEditingUserName: false; | |
actions: { | |
showEditUsernameForm: function () { | |
this.toggleProperty('isEditingUserName'); | |
}, | |
save: function () { | |
this.toggleProperty('isEditingPostalCode'); | |
// bubble action to route | |
return true; | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /Gruntfile.js | |
// task that is intended to be run by us | |
grunt.registerTask('server', "Run your server in development mode, auto-rebuilding when files change.", function(proxyMethod) { | |
... | |
grunt.task.run(['clean:debug', | |
'build:debug', | |
expressServerTask, | |
'watch' | |
]); | |
}); | |
// task that is run as part of another task | |
grunt.registerTask('build:debug', filterAvailable([ | |
'jshint:tooling', | |
'createResultDirectory', // Create directoy beforehand, fixes race condition | |
'fancySprites:create', | |
'concurrent:buildDebug', // Executed in parallel, see config below | |
])); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/models/jedi.js | |
export default DS.Model.extend({ | |
weapon: DS.attr() | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/models/base.js | |
export default DS.Model.extend({ | |
name: DS.attr(), | |
kind: DS.attr(), | |
us: belongsTo('us'), // not specifying `async` as below forces Ember to fetch `us` right away. ALL YOUR BASE ARE BELONG TO US | |
battleships: hasMany('battleships', {async: true}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /package.json | |
... | |
"devDependencies": { | |
"express": "~3.4.2", | |
"lockfile": "~>0.3.0", | |
"bower": "~1.3.2", | |
"grunt": "~0.4.2", | |
"grunt-fancy-sprites": "~2.0.0", | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /app/routes/user/index.js | |
export default Ember.Route.extend({ | |
// this is default model behaviour - that's what Ember assumes when model definition is omitted | |
model: function (params) { | |
return this.store.find('user', params.user_id) | |
} | |
// /app/routes/user/index.js | |
... | |
// default renderTemplate behaviour - that's what Ember assumes if it's omitted | |
// the path given is relative to app/templates/ | |
renderTemplate: function () { | |
this.render('user/index') | |
} | |
... | |
// /app/routes/user/index.js | |
... | |
// default setupController behaviour - if omitted, this is what Ember assumes | |
setupController: function(controller, model) { | |
controller.set('model', model); | |
} | |
... | |
// /app/routes/users/new.js | |
actions { | |
save: function () { | |
// `this` refers to the route. | |
return this.currentModel.save(); | |
} | |
} | |
... | |
// /app/routes/user.js | |
renderTemplate: function () { | |
// preserving default behaviour | |
this.render('user'); | |
// render sidebar | |
this.render('super-special-partial', { | |
outlet: 'named-special-outlet' | |
}); | |
} | |
... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Router = Ember.Router.extend(); // ensure we don't share routes between all Router instances | |
Router.map(function() { | |
this.route('landing', { path: '/landing' }); | |
this.resource('locations', function(){ // { path: 'locations' } omitted | |
this.route('new'); // { path: 'locations/new' } omitted | |
}); | |
this.resource('location', { path: '/location/:location_id' }); | |
}); | |
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /app/adapters/storm-trooper.js | |
export default DS.FixtureAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/models/strorm-trooper.js | |
var StormTrooper = DS.Model.extend({ | |
weapon: DS.attr() | |
}); | |
StormTrooper.reopenClass({ | |
FIXTURES: [{ | |
id: 1, | |
weapon: "Blaster rifle", | |
}, { | |
id: 2, | |
name: "Samurai sword", | |
}, { | |
id: 3, | |
name: "Baton", | |
}] | |
}); | |
export default StormTrooper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment