Skip to content

Commit

Permalink
better support for filters pipeline (localize first)
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Sep 11, 2015
1 parent 963f2cb commit a736aa9
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions template_engine/src/template_engine/visitor.py
Expand Up @@ -150,11 +150,11 @@
are going to be used "inside" the visitor execution logic """

FILTERS = dict(
e = lambda v: v if v == None else xml.sax.saxutils.escape(colony.legacy.UNICODE(v)),
default = lambda v, default = "", boolean = False:\
e = lambda v, t: v if v == None else xml.sax.saxutils.escape(t._serialize_value(v)),
default = lambda v, t, default = "", boolean = False:\
default if boolean and not v or v == None else v,
double = lambda v: v if v == None else v * 2,
format = lambda v, format: v if v == None else format % v
double = lambda v, t: v if v == None else v * 2,
format = lambda v, t, format: v if v == None else format % v
)
""" The dictionary containing the complete set
of base filters to be exposed to the visitor,
Expand Down Expand Up @@ -992,17 +992,17 @@ def get_value(self, attribute, localize = False, default = None):
elif attribute["type"] == "literal":
pass

# iterates over the complete set of filter definition to
# resolve the final value according to the filter
for filter in filters: value = self.resolve_many(
filter, value, global_map = self.filters
)

# resolves the current "variable" value, trying to
# localize it using the current locale bundles only
# do this in case the localize flag is set
value = self._resolve_locale(value) if localize else value

# iterates over the complete set of filter definition to
# resolve the final value according to the filter
for filter in filters: value = self.resolve_many(
filter, value, self, global_map = self.filters
)

# returns the processed value to the caller method, this is the
# considered to be the value for the requested attribute
return value
Expand Down Expand Up @@ -1443,8 +1443,9 @@ def _serialize_value(self, value):

# in case the value value is a sequence it must be
# "serializable" using the serialization of sequences
# "mechanism"
if value_type in SEQUENCE_TYPES: return self._serialize_sequence(value)
# "mechanism" (the proper way of presenting the value)
if value_type in SEQUENCE_TYPES:
return self._serialize_sequence(value)

def _serialize_sequence(self, value):
# retrieves the data type for the given value
Expand Down Expand Up @@ -1614,13 +1615,16 @@ def get_value(self, attribute, localize = False, default = None):
is_callable = hasattr(value, "__call__")
if is_callable: value = value()

# resolves the current "variable" value, trying to
# localize it using the current locale bundles only
# do this in case the localize flag is set
value = self._resolve_locale(value) if localize else value

# iterates over the complete set of filter definition to
# resolve the final value according to the filter and then
# runs the final step of locale value resolution (auto locale)
# resolve the final value according to the filters
for filter in filters: value = self.resolve_many(
filter, value, global_map = self.filters
filter, value, self, global_map = self.filters
)
value = self._resolve_locale(value) if localize else value

# returns the final value according to the eval based value
# retrieval that uses the python interpreter for evaluation
Expand Down

0 comments on commit a736aa9

Please sign in to comment.