Created
March 6, 2012 04:49
-
-
Save cognitom/1983645 to your computer and use it in GitHub Desktop.
YinYangのTemplateVarクラス for codeReview.cafe
This file contains hidden or 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 TemplateVar extends Template | |
| constructor: (@parent = null, @value = '', @ignore = false) -> | |
| fs = @value.split '|' | |
| @value = fs.shift() | |
| @filters = (YinYang.createFilter f for f in fs) | |
| @children = [] | |
| display: (localValues) -> | |
| @localValues = localValues | |
| v = if @value[0] == '@' then @displayDom() else @displayVar() | |
| v = filter.process v for filter in @filters | |
| v | |
| displayDom: -> $(@value.substring 1).html() | |
| displayVar: -> (@getLocalValue @value) or Template.getValue @value | |
| getLocalValue: (combinedKey) -> | |
| attrs = combinedKey.split '.' | |
| tv = @localValues | |
| tv = tv[attr] ? '' while attr = attrs.shift() | |
| tv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment