Created
February 24, 2014 16:28
-
-
Save vyorkin/9191604 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
class @Base | |
constructor: (args...) -> | |
for key, index in @constructor.$inject | |
@[key] = args[index] | |
@inject: (args...) -> @$inject = _.union @$inject args | |
class @BaseCtrl extends @Base | |
constructor: (args...) -> | |
super args... | |
@_bindScopeMethods | |
@initialize?() | |
@register: (app, kind = 'controller', name) -> | |
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1] | |
app.controller name, @ | |
@_bindScopeMethods: -> | |
for key, fn in @constructor.$inject | |
continue unless @_bindable?(key, fn) | |
@$scope[key] = fn.bind?(@) || _.bind(fn, @) | |
@_function?: (fn) -> fn is 'function' | |
@_bindable?: (key, fn) -> @_isFunction(fn) && !@_isPrivate?(key) | |
@_private?: (name) -> name in ['constructor', 'initialize'] || name[0] is '_' | |
class TestController extends @BaseCtrl | |
@register app | |
@inject '$scope' | |
initialize: -> | |
@$scope.name = 'view 1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment