Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created March 6, 2012 04:49
Show Gist options
  • Select an option

  • Save cognitom/1983645 to your computer and use it in GitHub Desktop.

Select an option

Save cognitom/1983645 to your computer and use it in GitHub Desktop.
YinYangのTemplateVarクラス for codeReview.cafe
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