Created
March 6, 2012 04:51
-
-
Save cognitom/1983663 to your computer and use it in GitHub Desktop.
YinYangのFilterクラス 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
| # [Filters] | |
| # thru filter | |
| class YinYang.filter | |
| constructor: (@args) -> | |
| process: (val) -> val | |
| # default filter | |
| # http://osscafe.github.com/yinyang/english/api.html#filter|default | |
| class YinYang.filters.default extends YinYang.filter | |
| process: (val) -> val || @args[0] || '' | |
| # nl2br filter | |
| # http://osscafe.github.com/yinyang/english/api.html#filter|default | |
| class YinYang.filters.nl2br extends YinYang.filter | |
| process: (val) -> val.replace /\n\r|\n|\r/gim, '<br />' | |
| # truncate filter | |
| # http://osscafe.github.com/yinyang/english/api.html#filter|default | |
| class YinYang.filters.truncate extends YinYang.filter | |
| process: (val) -> | |
| max = @args[0] || 80 | |
| txt = @args[1] || '...' | |
| if val.length > max then val.substring(0, max - txt.length) + txt else val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment