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(); |
| 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")); | |
| }); |
| # 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" |
| 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) { |