
json-template - issue #9
GetFormatter is wrong on so many levels (javascript). Proposed changes.
I will be working on fixing this, but to document my findings...
GetFormatter in the javascript implementation is wrong on so many levels:
1) It does not extend DEFAULT_FORMATTERS. Instead it just replaces the defaults with more_formatters if they are specified.
2) It does not define any API of more formatters, it just assumes that the full formatter name is going to be the exact name of the property. The formatter cannot specify some special logic to deal with parameters or anything of that nature. Esencially the conversation in ticket #4 regarding making parameters for formatters is impossible in javascript impl (without replacing any methods).
3) Essentially the default formatter and more_formatters are incompatible APIs, default formatter is a hash, more_formatters should really be a function.
I propose doing the following: 1) Format rules: a function is invoked (overridable) which gets the full formatter_str and returns an object containing: A formatter name, and an array containing arguments to the invocation of that formatter.
2) That formatter is invoked, the first parameter is the raw format string, the second parameter and onwards is the parameters parsed by the format rules function.
3) The formatter returns the full text.
4) A formatter object can be passed which will extend (similar to how jQuery does $.extend) the defaults.
5) The default format rules are the following: ^(.)((.))$, group 1 = formatter name, group 2 = formatter arguments, split by the comma(,) character.
Comment #1
Posted on Apr 12, 2009 by Quick HippoWe worked out how this should be done in the Python and Java versions, and discussed it on the mailing list, so this issue isn't necessary.
Status: Done
Labels:
Type-Defect
Priority-Medium