diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 16:47:25 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 16:47:25 +0000 |
commit | beb9fca9f45a99f1e3ccdb328fc40157f884fb5b (patch) | |
tree | c89e94bb713bb7de0177289a3ee80d7df72b8075 | |
parent | 8fec4b6eef7f1f4ef5840504f6abcdf0d2f9f80d (diff) | |
download | chromium_src-beb9fca9f45a99f1e3ccdb328fc40157f884fb5b.zip chromium_src-beb9fca9f45a99f1e3ccdb328fc40157f884fb5b.tar.gz chromium_src-beb9fca9f45a99f1e3ccdb328fc40157f884fb5b.tar.bz2 |
Docserver: roll third_party/handlebar/handlebar.py and tiny server2 change to
accommodate.
TBR=yoz@chromium.org
NOTRY=true
Review URL: https://codereview.chromium.org/73963003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235744 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/extensions/docs/server2/app.yaml | 2 | ||||
-rw-r--r-- | chrome/common/extensions/docs/server2/cron.yaml | 2 | ||||
-rw-r--r-- | chrome/common/extensions/docs/server2/template_renderer.py | 2 | ||||
-rw-r--r-- | third_party/handlebar/README.chromium | 4 | ||||
-rw-r--r-- | third_party/handlebar/handlebar.py | 74 |
5 files changed, 62 insertions, 22 deletions
diff --git a/chrome/common/extensions/docs/server2/app.yaml b/chrome/common/extensions/docs/server2/app.yaml index 97b55c9..3703e89 100644 --- a/chrome/common/extensions/docs/server2/app.yaml +++ b/chrome/common/extensions/docs/server2/app.yaml @@ -1,5 +1,5 @@ application: chrome-apps-doc -version: 2-42-0 +version: 2-42-1 runtime: python27 api_version: 1 threadsafe: false diff --git a/chrome/common/extensions/docs/server2/cron.yaml b/chrome/common/extensions/docs/server2/cron.yaml index be2199c..d4f2cb2 100644 --- a/chrome/common/extensions/docs/server2/cron.yaml +++ b/chrome/common/extensions/docs/server2/cron.yaml @@ -2,4 +2,4 @@ cron: - description: Repopulates all cached data. url: /_cron schedule: every 5 minutes - target: 2-42-0 + target: 2-42-1 diff --git a/chrome/common/extensions/docs/server2/template_renderer.py b/chrome/common/extensions/docs/server2/template_renderer.py index ab578db..e63f77186 100644 --- a/chrome/common/extensions/docs/server2/template_renderer.py +++ b/chrome/common/extensions/docs/server2/template_renderer.py @@ -25,10 +25,8 @@ class TemplateRenderer(object): 'apps_samples_url': GITHUB_BASE, 'base_path': server_instance.base_path, 'extensions_samples_url': EXTENSIONS_SAMPLES, - 'false': False, 'samples': server_instance.samples_data_source_factory.Create(request), 'static': server_instance.base_path + 'static', - 'true': True, } render_context.update(CreateDataSources(server_instance, request=request)) render_data = template.render(render_context) diff --git a/third_party/handlebar/README.chromium b/third_party/handlebar/README.chromium index 107866f..06d305b 100644 --- a/third_party/handlebar/README.chromium +++ b/third_party/handlebar/README.chromium @@ -2,8 +2,8 @@ Name: Handlebar, cross-platform data binding templates. Short Name: handlebar URL: https://github.com/kalman/templates Version: 0 -Date: November 14, 2013 -Revision: commit 4e707d26d5564c9046867602b8c67de4f792e2ef +Date: November 16, 2013 +Revision: commit 3e74633948a386d0a77a1c2b1df4c40546f4ec95 License: Apache 2.0 License File: NOT_SHIPPED Security Critical: no diff --git a/third_party/handlebar/handlebar.py b/third_party/handlebar/handlebar.py index f35764f..7e06868 100644 --- a/third_party/handlebar/handlebar.py +++ b/third_party/handlebar/handlebar.py @@ -155,6 +155,11 @@ class _Contexts(object): # [0] is the stack of nodes that |found_key| has been found in. self._value_info[found_key][0].pop() + def FirstLocal(self): + if len(self._nodes) == self._first_local: + return None + return self._nodes[-1]._value + def Resolve(self, path): # This method is only efficient at finding |key|; if |tail| has a value (and # |key| evaluates to an indexable value) we'll need to descend into that. @@ -643,6 +648,45 @@ class _JsonNode(_LeafNode): def __repr__(self): return '{{*%s}}' % self._id +# TODO: Better common model of _PartialNodeWithArguments, _PartialNodeInContext, +# and _PartialNode. +class _PartialNodeWithArguments(_DecoratorNode): + def __init__(self, partial, args): + if isinstance(partial, Handlebar): + # Preserve any get() method that the caller has added. + if hasattr(partial, 'get'): + self.get = partial.get + partial = partial._top_node + _DecoratorNode.__init__(self, partial) + self._partial = partial + self._args = args + + def Render(self, render_state): + render_state.contexts.Scope(self._args, self._partial.Render, render_state) + +class _PartialNodeInContext(_DecoratorNode): + def __init__(self, partial, context): + if isinstance(partial, Handlebar): + # Preserve any get() method that the caller has added. + if hasattr(partial, 'get'): + self.get = partial.get + partial = partial._top_node + _DecoratorNode.__init__(self, partial) + self._partial = partial + self._context = context + + def Render(self, render_state): + original_contexts = render_state.contexts + try: + render_state.contexts = self._context + render_state.contexts.Scope( + # The first local context of |original_contexts| will be the + # arguments that were passed to the partial, if any. + original_contexts.FirstLocal() or {}, + self._partial.Render, render_state) + finally: + render_state.contexts = original_contexts + class _PartialNode(_LeafNode): '''{{+var:foo}} ... {{/foo}} ''' @@ -651,7 +695,6 @@ class _PartialNode(_LeafNode): self._bind_to = bind_to self._id = id_ self._content = content - self._resolved_args = None self._args = None self._pass_through_id = None @@ -680,20 +723,17 @@ class _PartialNode(_LeafNode): context = render_state.contexts.Resolve(self._pass_through_id.name) if context is not None: arg_context[self._pass_through_id.name] = context - if self._resolved_args is not None: - arg_context.update(self._resolved_args) if self._args is not None: def resolve_args(args): resolved = {} for key, value in args.iteritems(): if isinstance(value, dict): assert len(value.keys()) == 1 - inner_id, inner_args = value.items()[0] - inner_partial = render_state.contexts.Resolve(inner_id.name) - if inner_partial is not None: - context = _PartialNode(None, inner_id, inner_partial) - context.SetResolvedArguments(resolve_args(inner_args)) - resolved[key] = context + id_of_partial, partial_args = value.items()[0] + partial = render_state.contexts.Resolve(id_of_partial.name) + if partial is not None: + resolved[key] = _PartialNodeWithArguments( + partial, resolve_args(partial_args)) else: context = render_state.contexts.Resolve(value.name) if context is not None: @@ -701,7 +741,8 @@ class _PartialNode(_LeafNode): return resolved arg_context.update(resolve_args(self._args)) if self._bind_to and self._content: - arg_context[self._bind_to.name] = self._content + arg_context[self._bind_to.name] = _PartialNodeInContext( + self._content, render_state.contexts) if arg_context: partial_render_state.contexts.Push(arg_context) @@ -711,9 +752,6 @@ class _PartialNode(_LeafNode): partial_render_state, text_transform=lambda text: text[:-1] if text.endswith('\n') else text) - def SetResolvedArguments(self, args): - self._resolved_args = args - def SetArguments(self, args): self._args = args @@ -1092,10 +1130,14 @@ class Handlebar(object): '''Renders this template given a variable number of contexts to read out values from (such as those appearing in {{foo}}). ''' - name = self._name or '<root>' internal_context = _InternalContext() - render_state = _RenderState( - name, _Contexts([{'_': internal_context}] + list(user_contexts))) + contexts = list(user_contexts) + contexts.append({ + '_': internal_context, + 'false': False, + 'true': True, + }) + render_state = _RenderState(self._name or '<root>', _Contexts(contexts)) internal_context.SetRenderState(render_state) self._top_node.Render(render_state) return render_state.GetResult() |