Created
February 24, 2014 04:48
-
-
Save vyorkin/9182106 to your computer and use it in GitHub Desktop.
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_name = "myApp" | |
app = angular.module "#{app_name}.controllers", [] | |
class BaseController | |
@register: (app, name) -> | |
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1] | |
app.controller name, @ | |
@inject: (args...) -> | |
@$inject = args | |
constructor: (args...) -> | |
for key, index in @constructor.$inject | |
@[key] = args[index] | |
for key, fn in @constructor.prototype | |
continue unless typeof fn is 'function' | |
continue if key in ['constructor', 'initialize'] or key[0] is '_' | |
@$scope[key] = fn.bind?(@) || _.bind(fn, @) | |
@initialize?() | |
class TestController extends BaseController | |
@register app | |
@inject '$scope' | |
initialize: -> | |
@$scope.name = 'view 1' | |
@$scope.say = -> window.alert.apply window, arguments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment