On Sun, Apr 29, 2001 at 10:21:26PM -0400, Chuck Esterbrook wrote:
> def replaceNamedValues(string, valueContainers, unknownValue=NoDefault,
> noneValue=None, regEx=None):
> '''
> Returns a new version of the string replaced with named values that
> come from the valueContainers.
>
> The point here is to provide a more powerful version of Python's
> dictionary strings:
> format % dict # such as:
> '%(foo)s %(bar)s' % dict
>
> The first improvement is syntax:
> '$foo $bar'
Somewhere the posts switched from talking about this syntax to $(foo), ${foo},
$(foo align=left). Or are we talking about two different packages.
$foo is certainly easy to type and has the advantage of consistency with
other languages. However, what about $fooNOTFOO (the placeholder being
immediately followed by a letter). Are the parentheses/braces optional?
> Another advantage to this syntax is that more advanced templating
> packages like Tavis Rudd's TemplateServer, Velocity and webmacro use
> this same syntax. That means you can later upgrade your templating
> solution without having to modify any of your existing templates.
Not having to upgrade your templates every time you change the engine would
be a very nice feature.
Plow and (last time I looked) TemplateServer both used a single regular
expression with a group to find the placeholders, so the syntax can be
switched easily. If each kit can ship with optional expressions to match
the syntaxes of the other kits, that would be a plus.
I may be willing to switch the default syntax of Plow from {braces} to
$(whatever_we_decide), depending.
> The next improvement is dotted notation. This function uses
> NamedValueAccess.valueForName(), so you can traverse an object graph
> (including dictionaries) using dotted notation: $department.manager.lastName
What about a sentance ending with $name. And then another sentance.
Would it be smart enough to know a period is not part of the name if
it's followed by whitespace?
> Parameters:
>string - The formatted string such as "Hello, %(name)s!"
>valueContainers - a list of objects that will be searched in
> order for particular named value.
>args - Optional dictionary of args takes precedence over the
> object
??? What does "taking precedence over the object" mean? Taking precedence
over what? Over 'valueContainers[0]'?
> unknownValue - The string value to use if a named value
> cannot be found.
> If not specified, an exception will be raised. Note that unknownValue is %
> with a dictionary contain the key 'name'. So for example, you could pass
> unknownValue='<span class=unknownValue> %(name)s </span>'.
OK, but the explanation could be a bit clearer. How about:
unknownValue - a format string used if a named value cannot be found.
The string may contain the substring "%(name)s", which will be replaced by
the missing name, using the normal %-operator semantics.
> @@ 2001-04-29 ce: Provide a filterValueFunc argument which defaults to
> None and is invoked for all values:
> if filterValueFunc: value = filterValueFunc(name, value)
> Is that a useful hook?
I don't see a need.
--
-Mike (Iron) Orr, iron@... (if mail problems: mso@...)
http://mso.oz.net/ English * Esperanto * Russkiy * Deutsch * Espan~ol
|