Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2012 Benjamin Kalman | 1 # Copyright 2012 Benjamin Kalman |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 this file to Python. | 61 this file to Python. |
| 62 """ | 62 """ |
| 63 def __init__(self): | 63 def __init__(self): |
| 64 self._buf = [] | 64 self._buf = [] |
| 65 self._length = 0 | 65 self._length = 0 |
| 66 | 66 |
| 67 def __len__(self): | 67 def __len__(self): |
| 68 return self._length | 68 return self._length |
| 69 | 69 |
| 70 def append(self, obj): | 70 def append(self, obj): |
| 71 string = str(obj) | 71 string = unicode(obj) |
|
cduvall
2012/07/20 19:40:51
I'll take these out before I commit, just showing
not at google - send to devlin
2012/07/23 13:25:37
Several hours later, and I know more than I really
cduvall
2012/07/23 18:10:37
Nice, I had some fun exploring Python unicode too.
| |
| 72 self._buf.append(string) | 72 self._buf.append(string) |
| 73 self._length += len(string) | 73 self._length += len(string) |
| 74 | 74 |
| 75 def toString(self): | 75 def toString(self): |
| 76 return ''.join(self._buf) | 76 return ''.join(self._buf) |
| 77 | 77 |
| 78 class RenderState(object): | 78 class RenderState(object): |
| 79 """ The state of a render call. | 79 """ The state of a render call. |
| 80 """ | 80 """ |
| 81 def __init__(self, globalContexts, localContexts): | 81 def __init__(self, globalContexts, localContexts): |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 class EscapedVariableNode(LeafNode): | 342 class EscapedVariableNode(LeafNode): |
| 343 """ {{foo}} | 343 """ {{foo}} |
| 344 """ | 344 """ |
| 345 def __init__(self, id, line): | 345 def __init__(self, id, line): |
| 346 LeafNode.__init__(self, line) | 346 LeafNode.__init__(self, line) |
| 347 self._id = id | 347 self._id = id |
| 348 | 348 |
| 349 def render(self, renderState): | 349 def render(self, renderState): |
| 350 value = self._id.resolve(renderState) | 350 value = self._id.resolve(renderState) |
| 351 if value != None: | 351 if value != None: |
| 352 self._appendEscapedHtml(renderState.text, str(value)) | 352 self._appendEscapedHtml(renderState.text, unicode(value)) |
| 353 | 353 |
| 354 def _appendEscapedHtml(self, escaped, unescaped): | 354 def _appendEscapedHtml(self, escaped, unescaped): |
| 355 for c in unescaped: | 355 for c in unescaped: |
| 356 if c == '<': | 356 if c == '<': |
| 357 escaped.append("<") | 357 escaped.append("<") |
| 358 elif c == '>': | 358 elif c == '>': |
| 359 escaped.append(">") | 359 escaped.append(">") |
| 360 elif c == '&': | 360 elif c == '&': |
| 361 escaped.append("&") | 361 escaped.append("&") |
| 362 else: | 362 else: |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 def render(self, *contexts): | 733 def render(self, *contexts): |
| 734 """ Renders this template given a variable number of "contexts" to read | 734 """ Renders this template given a variable number of "contexts" to read |
| 735 out values from (such as those appearing in {{foo}}). | 735 out values from (such as those appearing in {{foo}}). |
| 736 """ | 736 """ |
| 737 globalContexts = [] | 737 globalContexts = [] |
| 738 for context in contexts: | 738 for context in contexts: |
| 739 globalContexts.append(context) | 739 globalContexts.append(context) |
| 740 renderState = RenderState(globalContexts, []) | 740 renderState = RenderState(globalContexts, []) |
| 741 self._topNode.render(renderState) | 741 self._topNode.render(renderState) |
| 742 return renderState.getResult() | 742 return renderState.getResult() |
| OLD | NEW |