Skip to content

Instantly share code, notes, and snippets.

View thehydroimpulse's full-sized avatar

Somewhere thehydroimpulse

View GitHub Profile

Routing in Ember

In Ember, the application's state manager handles routing. Let's take a look at a simple example:

App.stateManager = Ember.StateManager.create({
  start: Ember.State.extend({
    index: Ember.State.extend({
      route: "/",
// Create a new instance of the container!
container = new container;
// Load a "fake" module. (simple class):
container.module('controller.js', "var controller;controller = (function() {function controller() {}controller.prototype.get = function(route) {alert('Method get called.');};return controller;})();return controller;");
// Resolve / Load this module and assigned it to a global 'controller' variable:
window.controller = new (container.resolve('controller.js'))();
// Call one of it's methods 'get':
controller.get();
@thehydroimpulse
thehydroimpulse / console.js
Created October 27, 2012 11:18 — forked from elijahmanor/console.js
Custom JSBin Settings
jsbin.settings.editor.theme = "monokai";
jsbin.settings.editor.indentUnit = 4;
jsbin.settings.editor.smartIndent = true;
jsbin.settings.editor.tabSize = 4;
jsbin.settings.editor.indentWithTabs = true;
jsbin.settings.editor.autoClearEmptyLines = true;
jsbin.settings.editor.lineWrapping = true;
jsbin.settings.editor.lineNumbers = true;
jsbin.settings.editor.matchBrackets = true;
var container = new Container();
container.configure(function(){
this.set("App.PostsController", require("/app/controllers/postsController"));
this.set("App.ApplicationController", require("/app/controllers/applicationController"));
});
@thehydroimpulse
thehydroimpulse / package.coffee
Created November 30, 2012 02:49
Tower Package Example
# Register a new package:
Tower.Package.register ->
# Require some core modules:
fs = require("fs")
path = require("path")
# Add information to the package.
@info
name: "Auth"
@thehydroimpulse
thehydroimpulse / ember-precompile.js
Created December 1, 2012 06:12 — forked from lancejpollard/ember-precompile.js
Precompile .handlebars templates with node js
var fs = require('fs');
var path = require('path');
var vm = require('vm');
var argv = require('optimist').argv;
function compileHandlebarsTemplate(file, onComplete) {
//dummy jQuery
var jQuery = function () { return jQuery }
jQuery.ready = function () { return jQuery }
jQuery.inArray = function () { return jQuery }
// Define a file.
// This allows us to use dependency injection file-wide, instead of class/function wide.
// This brings some simplicity to each file, as each will have
// a base, common framework.
File.define('framework', function(router, jsonController){
// As stated below, we want to listen on this error, otherwise the system will automatically
// trigger an error.
this.on("error", function(error){
console.log("We have an error: " + JSON.stringify(error));
throw Error(error);
Package.include('authentication')
Package.require('authentication')
Package.require('controllers', function(config){
// Do something when the package is included.
// The package can export methods, classes, etc...
// and they can be accessed by using "this"
console.log(this.var);
console.log(this.load());
});
this._paths.forEach(function(p){
fs.readdir(p, function(error, dir){
if (error) throw Error(error);
dir.forEach(function(_dir){
if (_dir.match("tower-packages")) return;
// Check if `package.js` exists:
fs.exists(path.join(p, _dir, 'package.js'), function(exists){
if (exists) {
this._paths.forEach(function(p){
fs.readdir(p, function(error, dir){
if (error) throw Error(error);
dir.forEach(function(_dir){
if (_dir.match("tower-packages")) return;
// Check if `package.js` exists:
fs.exists(path.join(p, _dir, 'package.js'), function(exists){
if (exists) {