Caphe
Various design utils for htpp://coffeescript.org. Implementation of Reg Braithwaite's article.
Features
> mixin consumer, modules...
Mix modules' methods to the model.
person = Talkable = : -> consolelog "Yeah!" Moveable = : consolelog "Walk by " : consolelog "Run by " CaphemixinpersonTalkableMoveable personspeak # "Yeah!" personwalk8 # "Walk by 8" personrun5 # "Run by 5"
> include module
Like mixin but do it Ruby style.
Talkable = : -> consolelog "Yeah!" @include Talkable person = personspeak # "Yeah!"
> attrAccessor names...
Create getter & setter methods in Ruby style and hide the properties from public access.
@attrAccessor "name""age" : person = "Bar"personsetName"Foo"persongetName # Foo personname # undefined persongetAge # undefined personsetAge5persongetAge # 5 personage # undefined personjob # Bar
> CONST name: value, ...
Create constant getters in prototype level.
@CONST EYE: 2SPECIES: 'homo sapiens' Person::EYE # 2 Person::SPECIES # homo sapiens
> forward consumer, providers...
Mixin with late bound. The forwarded methods have each own module as their context.
= -> consolelog "a"= -> consolelog @nameCapheforwardpersonmodule personfoo # a personbar # undefined = -> consolelog "b"personbar # b
> delegate consumer, providers...
Like #forward
, but the forwarded methods have the consumer as their context.
person.name = "John"= -> consolelog "a"= -> consolelog @nameCaphedelegatepersonmodule personfoo # a personbar # John = -> consolelog "b"personfoo # b