codegooglecom / json-template

Automatically exported from code.google.com/p/json-template
0 stars 0 forks source link

GetFormatter is wrong on so many levels (javascript). Proposed changes. #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by dlikhten on 7 Apr 2009 at 12:38

GoogleCodeExporter commented 9 years ago
We 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.

Original comment by gtempacc...@yahoo.com on 12 Apr 2009 at 8:31