ranska / rang

rang give sexy KISS to your angular files
MIT License
15 stars 2 forks source link

add directive class #3

Open ranska opened 10 years ago

BernhardRode commented 10 years ago

This would be awesome! I'd love a consistent syntax... up to now, I wasn't able to create it myself.

ranska commented 10 years ago

i working on this

class @BaseDrtCtrl extends @Rang

     constructor: (args...) ->
       super args...
       @s = @$scope
       for key, fn of @constructor.prototype
         continue unless typeof fn is 'function'
         continue if key in ['constructor', 'initialize'] or key[0] is '_'
         @s[key] = fn.bind?(@) || _.bind(fn, @)

       @initialize?()
  class @ScopeDrtCtrl extends @BaseDrtCtrl
     @inject '$scope'

class @ItemDrtCtrl extends @ScopeDrtCtrl
     @inject 'ItemService'

     edit: (item) ->
       @s.$emit "EDIT_ITEM", {ol}

     destroy: (item) ->
       @ItemService.destroy(item).then =>
          @s.$emit "RELOAD_ITEMS"

     change_status:  (item, status) ->
       ItemService.change_status(item, status)
         .then =>
           @s.$emit "RELOAD_ITEMS"

     cancel: ->
       @s.$emit "RELOAD_ITEMS"

   @Candy.directive "item", ->
     restrict:    "CE"
     remplace:    true
     templateUrl: "/templates/item_tds"
     scope:       false
     controller:  @ItemDrtCtrl

Then I want to automate all conf, controller will default by directive name expecting '#{DirectiveNave}DrtCtrl'

ranska commented 10 years ago

First try done. '#{DirectiveNave}DrtCtrl' works iihaaa ! Now next chalenge is with controller and automate template url.